[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dict-tree c1eeabe 081/154: Made dictionary auto-saving
From: |
Stefan Monnier |
Subject: |
[elpa] externals/dict-tree c1eeabe 081/154: Made dictionary auto-saving more robust against dictionary save failures. |
Date: |
Mon, 14 Dec 2020 12:21:49 -0500 (EST) |
branch: externals/dict-tree
commit c1eeabe015e226b3fa7646c22c2ebf86ed935d05
Author: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Commit: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Made dictionary auto-saving more robust against dictionary save failures.
* Modified dictree-save-modified to catch errors when saving dictionaries,
and indicate failures in its return value.
* Removed dictree-save-modified from kill-emacs-hook and added it instead to
kill-emacs-query-functions, so that dictionary save failures don't make it
impossible to quit Emacs.
* Removed predictive-save-used-dicts from kill-buffer-hook and added it
instead to kill-buffer-query-functions, so that dictionary save failures
don't make it impossible to kill buffers.
---
dict-tree.el | 68 +++++++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 54 insertions(+), 14 deletions(-)
diff --git a/dict-tree.el b/dict-tree.el
index af1f5a4..60675c3 100644
--- a/dict-tree.el
+++ b/dict-tree.el
@@ -56,7 +56,16 @@
;; * minor bug-fix to `dictree--edebug-pretty-print' to print "nil"
;; instead of "()"
;;
-;; Version 0.2.3
+;; Version 0.12.4
+;; * minor bug-fix to `dictree--edebug-pretty-print' to print "nil"
+;; instead of "()"
+;; * modified `dictree-save-modified' to catch errors when saving
+;; dictionaries, and indicate failures via its return value
+;; * removed `dictree-save-modified' from `kill-emacs-hook' and added it
+;; instead to `kill-emacs-query-functions', so that dictionary save
+;; failures don't make it impossible to quie Emacs
+;;
+;; Version 0.12.3
;; * bug-fix in `dictree--edebug-pretty-print'
;;
;; Version 0.12.2
@@ -2509,8 +2518,13 @@ and OVERWRITE is the prefix argument."
-(defun dictree-save-modified (&optional dict ask compilation force)
+(defun dictree-save-modified (&optional dict ask compilation force
+ no-fail-query)
"Save all modified dictionaries that have their autosave flag set.
+Returns t if all dictionaries were successfully saved. Otherwise,
+inform the user about the dictionaries which failed to save
+properly, ask them whether they wish to continue anyway, and
+return t or nil accordingly.
If optional argument DICT is a list of dictionaries or a single
dictionary, only save those.
@@ -2525,7 +2539,12 @@ save both forms. See `dictree-write'.
If optional argument FORCE is non-nil, save modified dictionaries
irrespective of their autosave flag.
-Interactively, FORCE is the prefix argument."
+If optional argument NO-FAIL-QUERY is non-nil, the user will not
+be queried if a dictionary fails to save properly, and the return
+value is always nil.
+
+Interactively, FORCE is the prefix argument, and the user will not be
+asked whether they wish to continue after a failed save."
(interactive "P")
;; sort out arguments
@@ -2535,21 +2554,42 @@ Interactively, FORCE is the prefix argument."
;; For each dictionary in list / each loaded dictionary, check if
;; dictionary has been modified. If so, save it if autosave is set or
;; FORCE is non-nil.
- (dolist (dic (if (null dict)
- dictree-loaded-list
- dict))
- (when (and (dictree-modified dic)
- (or force (dictree-autosave dic))
- (or (not ask)
- (y-or-n-p (format "Save modified dictionary %s? "
- (dictree-filename dic)))))
- (dictree-save dic compilation)
- (setf (dictree-modified dic) nil))))
+ (let (save-failures)
+ (dolist (dic (if (null dict)
+ dictree-loaded-list
+ dict))
+ (when (and (dictree-modified dic)
+ (or force (dictree-autosave dic))
+ (or (not ask)
+ (y-or-n-p (format "Save modified dictionary %s? "
+ (dictree-filename dic)))))
+ (condition-case nil
+ (progn
+ (dictree-save dic compilation)
+ (setf (dictree-modified dic) nil))
+ (error (push dic save-failures)))))
+
+ ;; prompt if dictionary saving failed
+ (if save-failures
+ (if (or (interactive-p) no-fail-query)
+ (progn
+ (message
+ (concat
+ "Error: failed to save the following modified "
+ "dictionaries: "
+ (mapconcat 'dictree--name save-failures ", ")))
+ nil)
+ (yes-or-no-p
+ (concat "Error: failed to save the following modified "
+ "dictionaries: "
+ (mapconcat 'dictree--name save-failures ", ")
+ "; continue anyway? ")))
+ t)))
;; Add the dictree-save-modified function to the kill-emacs-hook to save
;; modified dictionaries when exiting emacs
-(add-hook 'kill-emacs-hook 'dictree-save-modified)
+(add-hook 'kill-emacs-query-functions 'dictree-save-modified)
- [elpa] externals/dict-tree b3eb0f1 031/154: Bug-fix to dictree-insert, (continued)
- [elpa] externals/dict-tree b3eb0f1 031/154: Bug-fix to dictree-insert, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 0774b51 048/154: Added support for wildcard searches, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 06f5039 055/154: Bug-fix to 'resultfun' feature in dictree--query and dictree--do-query, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 9e9d7e9 056/154: Added dictree-clear-caches for doing the obvious, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 32bb6e2 061/154: Replaced wildcard searches with more powerful and efficient regexp searches., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree aa22866 062/154: minor fix: added tNFA to required packages, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree c53e4b8 064/154: Bumped copyright year, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 61f0ce6 068/154: Bug-fix in dictree--query, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 168cdb5 072/154: Improved edebug-prin1 advice, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 8810d3e 076/154: Bug-fixes to edebug pretty-print functions., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree c1eeabe 081/154: Made dictionary auto-saving more robust against dictionary save failures.,
Stefan Monnier <=
- [elpa] externals/dict-tree 2666377 084/154: Fixed implementation of 'both cache policy., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 5cc5449 091/154: Fixed obsolete functions and other compiler warnings., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 0ea66e7 090/154: Added fboundp guard around ad-define-subr-args (removed in Emacs-24)., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree cfdc73d 099/154: Fixed calls to dictree-create-meta-dict., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 2a1d749 098/154: Minor change to package description, to match other data structure packages., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 7ab8f94 095/154: Updated copyright attribution and license (GPL2 -> GPL3)., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 09b388f 108/154: Add note to self to use cust-print pretty-printing instead of advice., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree d96b1c5 097/154: More minor whitespace and commentary changes., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 1ec9d58 102/154: Restore trie print/read transformer functions., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 48ab389 092/154: Simplified persistent-storage code for tries and dict-trees., Stefan Monnier, 2020/12/14