*** savehist-CVS-2007-09-09a.el	Sun Sep  9 09:32:10 2007
--- savehist-patched-2007-09-09.el	Sun Sep  9 13:55:20 2007
***************
*** 118,124 ****
    :type 'file
    :group 'savehist)
  
! (defcustom savehist-file-modes #o600
    "*Default permissions of the history file.
  This is decimal, not octal.  The default is 384 (0600 in octal).
  Set to nil to use the default permissions that Emacs uses, typically
--- 118,124 ----
    :type 'file
    :group 'savehist)
  
! (defcustom savehist-file-modes 384      ; Octal: #o600
    "*Default permissions of the history file.
  This is decimal, not octal.  The default is 384 (0600 in octal).
  Set to nil to use the default permissions that Emacs uses, typically
***************
*** 299,325 ****
  	  (print-string-length nil)
  	  (print-level nil)
  	  (print-readably t)
! 	  (print-quoted t))
        ;; Save the minibuffer histories, along with the value of
        ;; savehist-minibuffer-history-variables itself.
        (when savehist-save-minibuffer-history
  	(prin1 `(setq savehist-minibuffer-history-variables
! 		      ',savehist-minibuffer-history-variables)
! 	       (current-buffer))
  	(insert ?\n)
  	(dolist (symbol savehist-minibuffer-history-variables)
  	  (when (boundp symbol)
  	    (let ((value (savehist-trim-history (symbol-value symbol))))
  	      (when value		; don't save empty histories
! 		(prin1 `(setq ,symbol ',value) (current-buffer))
! 		(insert ?\n))))))
        ;; Save the additional variables.
        (dolist (symbol savehist-additional-variables)
  	(when (boundp symbol)
! 	  (let ((value (symbol-value symbol)))
! 	    (when (savehist-printable value)
! 	      (prin1 `(setq ,symbol ',value) (current-buffer))
! 	      (insert ?\n))))))
      ;; If autosaving, avoid writing if nothing has changed since the
      ;; last write.
      (let ((checksum (md5 (current-buffer) nil nil savehist-no-conversion)))
--- 299,326 ----
  	  (print-string-length nil)
  	  (print-level nil)
  	  (print-readably t)
! 	  (print-quoted t)
!           (print-unreadable-function t)
!           (standard-output (current-buffer)))
        ;; Save the minibuffer histories, along with the value of
        ;; savehist-minibuffer-history-variables itself.
        (when savehist-save-minibuffer-history
  	(prin1 `(setq savehist-minibuffer-history-variables
!                  ',savehist-minibuffer-history-variables))
  	(insert ?\n)
  	(dolist (symbol savehist-minibuffer-history-variables)
  	  (when (boundp symbol)
  	    (let ((value (savehist-trim-history (symbol-value symbol))))
  	      (when value		; don't save empty histories
!  		(insert "(setq ") (prin1 symbol) (insert " '(")
!  		(while value
!  		  (and (savehist-prin1-readable (car value))
!  		       (setq value (cdr value)) (insert " ")))
!  		(insert "))\n"))))))
        ;; Save the additional variables.
        (dolist (symbol savehist-additional-variables)
  	(when (boundp symbol)
!           (savehist-prin1-readable `(setq ,symbol ',(symbol-value symbol))))))
      ;; If autosaving, avoid writing if nothing has changed since the
      ;; last write.
      (let ((checksum (md5 (current-buffer) nil nil savehist-no-conversion)))
***************
*** 340,347 ****
  (defun savehist-autosave ()
    "Save the minibuffer history if it has been modified since the last save.
  Does nothing if `savehist-mode' is off."
!   (when savehist-mode
!     (savehist-save t)))
  
  (defun savehist-trim-history (value)
    "Retain only the first `history-length' items in VALUE.
--- 341,347 ----
  (defun savehist-autosave ()
    "Save the minibuffer history if it has been modified since the last save.
  Does nothing if `savehist-mode' is off."
!   (condition-case nil (when savehist-mode (savehist-save t)) (error nil)))
  
  (defun savehist-trim-history (value)
    "Retain only the first `history-length' items in VALUE.
***************
*** 376,381 ****
--- 376,391 ----
  	;; The attempt failed: the object is not printable.
  	(error nil))))))
  
+ (defun savehist-prin1-readable (value)
+   "Print VALUE in the current buffer, if it's readable.
+ Return non-nil if it was printed."
+   (let ((opoint (point)))
+     (condition-case nil
+ 	(progn (when (stringp value) (setq value (format "%s" value)))
+                (prin1 value (current-buffer))
+                t)
+       (error (delete-region opoint (point)) nil))))
+ 
  (defun savehist-minibuffer-hook ()
    (unless (or (eq minibuffer-history-variable t)
  	      ;; XEmacs sets minibuffer-history-variable to t to mean "no
