From: Eshel Yaron Date: Mon, 14 Apr 2025 17:01:15 +0000 (+0200) Subject: savehist: Only save readable values X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=cc91652bdd60f9d4501f2c242df6c74dacdfbe15;p=emacs.git savehist: Only save readable values --- diff --git a/lisp/savehist.el b/lisp/savehist.el index 2a6b450280a..cb680dcfd9b 100644 --- a/lisp/savehist.el +++ b/lisp/savehist.el @@ -242,8 +242,10 @@ Unbound symbols referenced in `savehist-additional-variables' are ignored." (prin1 (seq-keep (lambda (sym) - (when (and (boundp sym) (not (memq sym savehist-ignored-variables))) - (cons sym (symbol-value sym)))) + (and (boundp sym) + (not (memq sym savehist-ignored-variables)) + (readablep (symbol-value sym)) + (cons sym (symbol-value sym)))) (cons 'savehist-minibuffer-history-variables (append savehist-minibuffer-history-variables savehist-additional-variables))) @@ -275,31 +277,6 @@ Unbound symbols referenced in `savehist-additional-variables' are ignored." Does nothing if Savehist mode is off." (when savehist-mode (savehist-save))) -(define-obsolete-function-alias 'savehist-trim-history #'identity "27.1") - -(defun savehist-printable (value) - "Return non-nil if VALUE is printable." - (cond - ;; Quick response for oft-encountered types known to be printable. - ((numberp value)) - ((symbolp value)) - ;; String without properties - ((and (stringp value) - (equal-including-properties value (substring-no-properties value)))) - (t - ;; For others, check explicitly. - (with-temp-buffer - (condition-case nil - (let ((print-level nil)) - ;; Print the value into a buffer... - (prin1 value (current-buffer)) - ;; ...and attempt to read it. - (read (point-min-marker)) - ;; The attempt worked: the object is printable. - t) - ;; The attempt failed: the object is not printable. - (error nil)))))) - (defun savehist-minibuffer-hook () (unless (or (eq minibuffer-history-variable t) ;; If `read-string' is called with a t HISTORY argument