Showing 492 to 495

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)

Löb's Theorem

One of the top-5 most important things I've ever read: Löb's Theorem Cured My Social Anxiety. Teaser:

During the conversation in which I described my plan to him, we meandered to the topic of a meetup of professional hypnotists he’d recently attended. He told me they talked in passing about what it’s like to change their own behaviors. They all knew they could use a long, draw-out induction (or series of inductions and post-hypnotic suggestions) to self-modify if they wanted. But that takes time and energy, and it turns out that if you’re sufficiently confident it’ll work… you don’t have to bother with the hypnosis.

Think about that for a minute. They treated it as a perfectly normal, every-day occurrence. Basically they were saying, “Yeah, when I don’t like what System 1 is doing, I just tell it to do something else instead. No biggy.” They seem to have this available as a primitive action.

Initially, I said it sort of tongue-in-cheek: “Ha, well I guess we don’t really need that induction I described then!”

Pause.

System 2: Surely not. It can't be that simple. There’s just no way that will actually work. Nobody cures a life-long psychological disorder overnight. Don’t be ridiculous.

Background

What is it? Has to do with Peano arithmetic and logic… A Cartoon Guide to Löb's Theorem

The Santa Claus sentence

"If this sentence is true, then Santa Claus exists." (Clearly, if that sentence were really true, then Santa Claus would have to exist. But this is just what the sentence asserts, so it is true, and Santa Claus does exist.)

Created (2 years ago)
Showing 492 to 495