Skip to content

Commit

Permalink
[spacemacs-defaults] Tweak savehist configuration
Browse files Browse the repository at this point in the history
1. Use an idle timer instead of a strict periodic autosave interval. Saving
large histories can cause noticable delays, and the default `history-length` set
by Spacemacs is relatively large (1000).

2. Save `kill-ring` without text properties, as they are known to cause
significant performance problems and huge history files in some cases, and
persisting them in the kill-ring usually brings little benefit.
This should fix #1300, #1369 and #9409 again.

3. Add `kmacro-ring` and `log-edit-comment-ring` as additional variables. They
are useful and usually not very large. BTW, `search-ring`, `regexp-search-ring`
and `extended-command-history` are redundant here as long as long as
`savehist-save-minibuffer-history` is non-nil (the default). I decided to leave
them there for now to avoid any breaking changes for users that customized that
option, though I guess it could be okay to change this.
  • Loading branch information
fnussbaum authored and smile13241324 committed Dec 31, 2024
1 parent ae848a1 commit 5fb42ce
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
7 changes: 7 additions & 0 deletions layers/+spacemacs/spacemacs-defaults/config.el
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ or `nil' to only save and not visit the file."
;; Session
;; ---------------------------------------------------------------------------

(spacemacs|defc spacemacs-savehist-autosave-idle-interval 60
"Idle interval between autosaves of minibuffer histories and other
variables (see `savehist-mode' and `savehist-additional-variables')."
'integer)

(defvar spacemacs--savehist-idle-timer nil)

;; scratch buffer empty
(setq initial-scratch-message dotspacemacs-initial-scratch-message)
;; don't create backup~ files
Expand Down
27 changes: 24 additions & 3 deletions layers/+spacemacs/spacemacs-defaults/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,30 @@
savehist-additional-variables '(search-ring
regexp-search-ring
extended-command-history
kill-ring)
savehist-autosave-interval 60)
(savehist-mode t)))
kill-ring
kmacro-ring
log-edit-comment-ring)
;; We use an idle timer instead, as saving can cause
;; noticable delays with large histories.
savehist-autosave-interval nil)
(savehist-mode t)
(define-advice savehist-save
(:around (orig &rest args) spacemacs//kill-ring-no-properties)
"Text properties can blow up the savehist file and lead to
excessive pauses when saving."
(if (memq 'kill-ring savehist-additional-variables)
(let ((kill-ring (mapcar #'substring-no-properties
(cl-remove-if-not #'stringp kill-ring))))
(apply orig args))
(apply orig args)))
(when (and (boundp 'spacemacs--savehist-idle-timer)
(timerp spacemacs--savehist-idle-timer))
(cancel-timer spacemacs--savehist-idle-timer))
(setq spacemacs--savehist-idle-timer
(run-with-idle-timer
spacemacs-savehist-autosave-idle-interval
spacemacs-savehist-autosave-idle-interval
#'savehist-autosave))))

(defun spacemacs-defaults/init-saveplace ()
(use-package saveplace
Expand Down

0 comments on commit 5fb42ce

Please sign in to comment.