Showing 493 to 496

org-before-export-hook is gone

#emacs

Struggled so long looking for a hook that would work like the old org-before-export-hook. Let this be a lesson: the Emacs hook system exists to let you subtly modify a function IN THE MIDDLE of its body. We never actually need simple before-hooks nor after-hooks (that's why it was removed), since in those cases it is always possible to use add-function or write a wrapper.

So where do you put that add-function? It depends… I use org-publish actually, so I wrap org-publish-org-to.

Created (2 years ago)

Losing items in recentf, org-id-locations? Run kill-emacs-hook periodically.

This has been annoying me for years. Every time I start #Emacs, there will be some org notes I cannot find by org-id, and recentf suffers partial amnesia so that I cannot jump to a file I was just working on minutes ago (before Emacs crashed), and so on.

The issue stems from a programming anti-pattern: assuming that takedown logic will execute. In other words, relying on kill-emacs-hook.

At the end of this page, you can find an initfile snippet to fix this.


Rant:

It's insane to put any sort of data-sync on kill-emacs-hook. Most of the time my Emacs goes down, it happens in a non-clean way – why would I intentionally shut off Emacs if everything is fine? Ergo, that hook never runs. Package developers, look over your code and ask what happens if kill-emacs-hook never runs.

If you want to persist state across restarts, you must write it to disk at some other time than takedown. Assume your user's customary method of restarting is yanking the power cord – code accordingly.

IMO they should warn developers about this in the docstring.


(defvar my-state-sync-hooks nil
  "Dynamic variable.
For some reason, `run-hooks' can't use a let-bound list when
lexical binding is t, so instead `my-state-sync' will work with
this global variable.")

(defun my-state-sync ()
  "Write histories and caches to disk.
This runs many members of `kill-emacs-hook' so we don't have to
rely on that hook.  You may put this on a repeating idle timer."
  (setq my-state-sync-hooks
        (seq-intersection
         ;; NOTE: Check your `kill-emacs-hook' in case there's
         ;; more functions you want to add here.
         #'(bookmark-exit-hook-internal
            savehist-autosave
            transient-maybe-save-history
            org-id-locations-save
            save-place-kill-emacs-hook
            recentf-save-list
            recentf-cleanup)
         kill-emacs-hook))
  (run-hooks 'my-state-sync-hooks))

;; Run after 3 minutes of idle.
;; (Will not repeat until user becomes idle again.)
(setq my-state-sync-timer
      (run-with-idle-timer (* 3 60) t #'my-state-sync))

Bonus tips

If your exact problem concerned abbrev or recentf, one of these lines could be sufficient for you.

(add-hook 'kill-emacs-hook #'write-abbrev-file)
(setq recentf-max-saved-items 1000)
Created (2 years ago)

Docker

Quick start

docker build -t dev -f Dockerfile.dev  . && docker run -t dev

Full wipe

docker stop $(docker ps -aq) && \
    docker rm $(docker ps -aq) && \
    docker rmi $(docker images -aq) && \
    docker volume rm $(docker volume ls -q)

ls ~/.local/share/docker/btrfs/subvolumes/ | sudo xargs btrfs subvolume delete

docker system prune

An enlightening example of what's going on

Created (2 years ago)

Recent bugs, yet to be explained

Usually when we submit bug reports, we do painstaking detective work first, for good reason. But that means we don't report all bugs we ever encounter, so here's a space for the bugs I have not investigated.

<2024-Oct-25> userlock.el presumes the current buffer's file is that of the file being handled

So write-region called from a different buffer sometimes causes the cl-assert in userlock–check-content-unchanged to fail.

Also when the user responds to userlock–ask-user-about-supersession-threat with "r" for revert, error: "Buffer does not seem to be associated with any file".

Present in Emacs 29.4 and 31.0.50. Trying to pin down the cause, but it only occurs sometimes.

[2023-01-25 Wed] Emacs freezes when editing JS files

Still current as of [2023-01-25 Wed]

I suspect it has to do with Doom Emacs' javascript module. Even without +lsp, it starts up tsserver, which is probably a bug in itself.

Until recently, starting tsserver used to freeze my Emacs.

Nowadays, with Doom's javascript module, Emacs freezes when opening some files (at least those that contain a @flow comment), or when I try to comment out certain lines of JS.

[2022-09-28 Wed] org-element–cache-sync

An open eshell sometimes seems to mess with org-element--cache-sync. This interferes with the experience of editing Org buffers.

Killing the eshell makes org behave normally.

Created (2 years ago)
Showing 493 to 496