Tweak the `savehist-mode' setup

This commit is contained in:
Gerard Vermeulen 2024-06-14 11:10:41 +02:00
parent f01ca41b47
commit 80713070f4

View File

@ -228,6 +228,7 @@ of [[info:emacs#Saving Customizations][saving customizations (info)]].
recentf-max-saved-items 100 recentf-max-saved-items 100
recentf-mode t recentf-mode t
save-place-mode t save-place-mode t
savehist-mode t
scroll-bar-mode nil scroll-bar-mode nil
tab-always-indent 'complete tab-always-indent 'complete
tool-bar-mode nil tool-bar-mode nil
@ -1353,10 +1354,11 @@ completion in any buffer.
:END: :END:
Listing [[lst:enable-vertico-mode]] configures and enables =savehist-mode= and Listing [[lst:enable-vertico-mode]] configures and enables =savehist-mode= and
enables =vertico-mode=. The documentation src_emacs-lisp{(describe-function enables =vertico-mode=. The src_emacs-lisp{(describe-function 'savehist-mode)}
'savehist-mode)} why it is best to turn on =savehist-mode= in the Emacs init documentation explains why it is best to turn on =savehist-mode= in the
file. BUG: Adding ~eww-history~, ~register-alist~, ~regexp-search-string~, or =user-init-file=. Listing [[lst:prune-file-name-history]] allows to prune
~search-string~ to ~savehist-additional-variables~ fails to save the relevant non-existing files from the file name history. BUG: Adding ~eww-history~ or
~register-alist~ to ~savehist-additional-variables~ fails to save the relevant
histories. histories.
#+caption[Enable =savehist-mode= and =vertico-mode=]: #+caption[Enable =savehist-mode= and =vertico-mode=]:
@ -1364,8 +1366,8 @@ histories.
#+name: lst:enable-vertico-mode #+name: lst:enable-vertico-mode
#+begin_src emacs-lisp -n :results silent #+begin_src emacs-lisp -n :results silent
(with-eval-after-load 'savehist (with-eval-after-load 'savehist
(setopt savehist-additional-variables '(kill-ring search-ring)) (setopt savehist-additional-variables
(savehist-mode +1)) '(command-history kill-ring regexp-search-ring search-ring)))
(when (and (ensure-package-installation 'vertico) (when (and (ensure-package-installation 'vertico)
(fboundp 'vertico-directory-delete-char) (fboundp 'vertico-directory-delete-char)
(fboundp 'vertico-directory-delete-word) (fboundp 'vertico-directory-delete-word)
@ -1379,6 +1381,22 @@ histories.
(keymap-set vertico-map "RET" #'vertico-directory-enter))) (keymap-set vertico-map "RET" #'vertico-directory-enter)))
#+end_src #+end_src
#+caption[Prune non-existing files from =file-name-history=]:
#+caption: Prune non-existing files from =file-name-history=.
#+name: lst:prune-file-name-history
#+begin_src emacs-lisp -n :results silent
(defun prune-file-name-history ()
"Prune non-existing files from `file-name-history'."
(interactive)
(let ((old (length file-name-history)) ok)
(dolist (name file-name-history)
(when (file-exists-p name)
(push name ok)))
(setq file-name-history (nreverse ok))
(message "Pruned `file-name-history' from `%S' to `%S' files"
old (length file-name-history))))
#+end_src
#+attr_latex: :booktabs yes :float table #+attr_latex: :booktabs yes :float table
#+caption[Vertico key map bindings]: #+caption[Vertico key map bindings]:
#+caption: Vertico key map bindings. #+caption: Vertico key map bindings.