]> git.eshelyaron.com Git - emacs.git/commitdiff
savehist: Only save readable values
authorEshel Yaron <me@eshelyaron.com>
Mon, 14 Apr 2025 17:01:15 +0000 (19:01 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 14 Apr 2025 17:01:15 +0000 (19:01 +0200)
lisp/savehist.el

index 2a6b450280ab535d9e95abe10e936934830cac72..cb680dcfd9bcd065f4a3b038b1839fec1f4545a3 100644 (file)
@@ -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