I don't exit Emacs often, but when I do it is bothersome to lose recently used commands and filenames. As usual, others have felt this way and mitigated the issue with the creation of
(savehist-mode &optional ARG)
Toggle saving of minibuffer history (Savehist mode). With a prefix argument ARG, enable Savehist mode if ARG is positive, and disable it otherwise. If called from Lisp, enable the mode if ARG is omitted or nil.
When Savehist mode is enabled, minibuffer history is saved periodically and when exiting Emacs. When Savehist mode is enabled for the first time in an Emacs session, it loads the previous minibuffer history from ‘savehist-file’.
While saving the text in the minibuffer is a good start, there are a number of other aspects of a session that I would like to be saved. Surprising nobody, the variable
savehist-additional-variables addresses this:
List of additional variables to save.
Each element is a symbol whose value will be persisted across Emacs sessions that use Savehist. The contents of variables should be printable with the Lisp printer. You don’t need to add minibuffer history variables to this list, all minibuffer histories will be saved automatically as long as ‘savehist-save-minibuffer-history’ is non-nil.
So let's add every history-related variable that I can find. This will even maintain the clipboard and its history (
(setq savehist-file "~/.emacs.p/savehist") (setq savehist-additional-variables '(buffer-name-history compile-command extended-command-history file-name-history kill-ring regexp-search-ring search-ring))
Now that we've configured the mode, we activate it:
Henceforth I don't need to worry about losing previously-entered commands/parameters on my rare exits from Emacs. I'll probably have to add more variables later.