Showing 353 to 356

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)

Recent bugs, yet to be explained

Usually when we submit bug reports, we do painstaking detective work first, for good reason. But I often run across bugs I can't be bothered to track down, and I leave them unfixed for months or years. Why not publish them too? Hence this page. Maybe someone Googles a bug here and gets the chance to talk to me about it.

[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)

Confirmation bias

An arch-bias, supporting many other biases.

We all hear about confirmation bias, and maybe we even have a habit of keeping it in mind. That doesn't mean it's solved, nor that we should focus on other less-known biases as if they were bigger fish to fry. Paraphrasing Raymond Nickerson 1998: If there were a contest for the single largest problem in human reasoning, confirmation bias would have to be a candidate. No one is free from it.

Countermeasures

Related

What links here

Created (2 years ago)

Portal: Rationality

Rationality techniques๐Ÿ”—

Vocabulary that could be helpful

  • The expression To lose the root for the tree
  • Burdensome details
  • Your strength as a rationalist is your ability to be more confused by fiction than by reality
  • I notice that I am confused (Hallowed phrases)

Notes on battle plans

My wetware๐Ÿ”—

Human heuristics, biases and fallacies๐Ÿ”—

For failures of groups, see Human cooperation.

Mistakes you tend to keep making even if you understand them

Mistakes you tend to stop making after you understand them (at least in each example situation pointed out)

Unsorted cogsci

Psychology

Other

Reasoning๐Ÿ”—

General principles of minds (that would apply to alien and artificial minds as much as our own; for what's more to do with our mind-implementation on a homo sapiens brain, see rather My wetware)

Decision/game theory

Probability theory๐Ÿ”—

Value/moral theory

  • Metaethics
  • EY's Fun Theory

Anthropic reasoning

The universe

My gameboard๐Ÿ”—

Interpersonal๐Ÿ”—

Human cooperation๐Ÿ”—

What links here

Created (2 years ago)
Showing 353 to 356