feat(emacs): savehist-mode

This commit is contained in:
Madeleine Sydney
2025-02-17 02:10:48 -07:00
parent 6c9213d532
commit 326ae2442a
2 changed files with 42 additions and 0 deletions

View File

@@ -38,5 +38,38 @@
(find-file-hook . recentf-save-list))
:custom (recentf-save-file (file-name-concat syd-data-dir "recentf")))
(use-package savehist
:defer-incrementally custom
:hook (on-first-input-hook . savehist-mode)
:custom (savehist-file (file-name-concat syd-cache-dir "savehist"))
:config
(setq savehist-save-minibuffer-history t
savehist-autosave-interval nil ; save on kill only
savehist-additional-variables
'(kill-ring ; persist clipboard
register-alist ; persist macros
mark-ring global-mark-ring ; persist marks
search-ring regexp-search-ring)) ; persist searches
(syd-add-hook 'savehist-save-hook
(defun syd--savehist-unpropertize-variables-h ()
"Remove text properties from `kill-ring' to reduce savehist cache size."
(setq kill-ring
(mapcar #'substring-no-properties
(cl-remove-if-not #'stringp kill-ring))
register-alist
(cl-loop for (reg . item) in register-alist
if (stringp item)
collect (cons reg (substring-no-properties item))
else collect (cons reg item))))
(defun syd--savehist-remove-unprintable-registers-h ()
"Remove unwriteable registers (e.g. containing window configurations).
Otherwise, `savehist' would discard `register-alist' entirely if we don't omit
the unwritable tidbits."
;; Save new value in the temp buffer savehist is running
;; `savehist-save-hook' in. We don't want to actually remove the
;; unserializable registers in the current session!
(setq-local register-alist
(cl-remove-if-not #'savehist-printable register-alist)))))
(provide 'syd-autosave)