diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-08-19 16:48:59 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-08-19 16:48:59 -0700 |
commit | 07fcbb558d797272b9f43547da60beda485873a3 (patch) | |
tree | 77d5da14e9f9d9d8b1d877c70c01296fd3893796 /lisp/savehist.el | |
parent | c9bdeff3e45a7ac84a74a81bb048046f82dddc91 (diff) | |
parent | fb81c8c3adf8633f2f617c82f6019aef630860c7 (diff) | |
download | emacs-07fcbb558d797272b9f43547da60beda485873a3.tar.gz |
Merge remote-tracking branch 'origin/master' into athena/unstable
Diffstat (limited to 'lisp/savehist.el')
-rw-r--r-- | lisp/savehist.el | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/lisp/savehist.el b/lisp/savehist.el index b8e9d6b427f..6745d379cb3 100644 --- a/lisp/savehist.el +++ b/lisp/savehist.el @@ -213,6 +213,7 @@ Normally invoked by calling `savehist-mode' to unset the minor mode." (cancel-timer savehist-timer) (setq savehist-timer nil))) +(defvar savehist--has-given-file-warning nil) (defun savehist-save (&optional auto-save) "Save the values of minibuffer history variables. Unbound symbols referenced in `savehist-additional-variables' are ignored. @@ -286,23 +287,29 @@ If AUTO-SAVE is non-nil, compare the saved contents to the one last saved, ;; If autosaving, avoid writing if nothing has changed since the ;; last write. (let ((checksum (md5 (current-buffer) nil nil savehist-coding-system))) - (unless (and auto-save (equal checksum savehist-last-checksum)) - ;; Set file-precious-flag when saving the buffer because we - ;; don't want a half-finished write ruining the entire - ;; history. Remember that this is run from a timer and from - ;; kill-emacs-hook, and also that multiple Emacs instances - ;; could write to this file at once. - (let ((file-precious-flag t) - (coding-system-for-write savehist-coding-system) - (dir (file-name-directory savehist-file))) - ;; Ensure that the directory exists before saving. - (unless (file-exists-p dir) - (make-directory dir t)) - (write-region (point-min) (point-max) savehist-file nil - (unless (called-interactively-p 'interactive) 'quiet))) - (when savehist-file-modes - (set-file-modes savehist-file savehist-file-modes)) - (setq savehist-last-checksum checksum))))) + (condition-case err + (unless (and auto-save (equal checksum savehist-last-checksum)) + ;; Set file-precious-flag when saving the buffer because we + ;; don't want a half-finished write ruining the entire + ;; history. Remember that this is run from a timer and from + ;; kill-emacs-hook, and also that multiple Emacs instances + ;; could write to this file at once. + (let ((file-precious-flag t) + (coding-system-for-write savehist-coding-system) + (dir (file-name-directory savehist-file))) + ;; Ensure that the directory exists before saving. + (unless (file-exists-p dir) + (make-directory dir t)) + (write-region (point-min) (point-max) savehist-file nil + (unless (called-interactively-p 'interactive) 'quiet))) + (when savehist-file-modes + (set-file-modes savehist-file savehist-file-modes)) + (setq savehist-last-checksum checksum)) + (file-error + (unless savehist--has-given-file-warning + (lwarn '(savehist-file) :warning "Error writing `%s': %s" + savehist-file (caddr err)) + (setq savehist--has-given-file-warning t))))))) (defun savehist-autosave () "Save the minibuffer history if it has been modified since the last save. |