[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ebdb aa668d7 08/33: Add "force" argument to ebdb-db-sav
From: |
Eric Abrahamsen |
Subject: |
[elpa] externals/ebdb aa668d7 08/33: Add "force" argument to ebdb-db-save |
Date: |
Sun, 3 Sep 2017 17:02:20 -0400 (EDT) |
branch: externals/ebdb
commit aa668d7086bf86952b2a759fdc1cc03c6b44e15d
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>
Add "force" argument to ebdb-db-save
* ebdb.el (ebdb-db-save): Make a defgeneric; add a force argument.
When non-nil, the save call will go through regardless of errors
raised, and regardless of whether the database or its records are
"dirty".
---
ebdb.el | 57 ++++++++++++++++++++++++++++-----------------------------
1 file changed, 28 insertions(+), 29 deletions(-)
diff --git a/ebdb.el b/ebdb.el
index 39b8d89..2b3e2f7 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -3630,23 +3630,42 @@ of sync but has no local modifications.")
nil
(signal err (list db))))))
-(cl-defmethod ebdb-db-save :before ((db ebdb-db) &optional _prompt)
- "Prepare DB to be saved."
- (when (ebdb-db-dirty db)
- (ebdb-db-editable db)))
-
-(cl-defmethod ebdb-db-save ((db ebdb-db) &optional _prompt)
+(cl-defgeneric ebdb-db-save ((db ebdb-db) &optional prompt force)
"Save DB to its persistence file.
+When PROMPT is non-nil, prompt the user before saving (currently
+unimplemented). When FORCE is non-nil, save regardless of
+whether the database is dirty or not, and ignore all database
+errors.
This method is only responsible for saving the database
definition to disk. Database subclasses are responsible for
saving or otherwise persisting their records, and setting
their :records slot to nil before calling this method with
`cl-call-next-method'. They can either catch errors thrown by
-the persistent save, or allow them to propagate."
- (eieio-persistent-save db))
+the persistent save, or allow them to propagate.")
+
+(cl-defmethod ebdb-db-save :before ((db ebdb-db) &optional _prompt force)
+ "Prepare DB to be saved."
+ (when (and (null force)
+ (ebdb-db-dirty db))
+ (ebdb-db-editable db)))
+
+(cl-defmethod ebdb-db-save ((db ebdb-db-file) &optional _prompt force)
+ "Mark DB and all its records as \"clean\" after saving."
+ (let ((recs (ebdb-dirty-records (slot-value db 'records))))
+ (when (or force recs (slot-value db 'dirty))
+ (setf (slot-value db 'dirty) nil)
+ (dolist (r recs)
+ (setf (slot-value r 'dirty) nil))
+ (condition-case err
+ (cl-call-next-method)
+ (error
+ (setf (slot-value db 'dirty) t)
+ (dolist (r recs)
+ (setf (slot-value r 'dirty) t))
+ (signal 'error err))))))
-(cl-defmethod ebdb-db-save :after ((db ebdb-db) &optional _prompt)
+(cl-defmethod ebdb-db-save :after ((db ebdb-db) &optional _prompt _force)
"After saving DB, also delete its auto-save file, if any."
(let ((auto-save-file
(ebdb-db-make-auto-save-file-name
@@ -3742,26 +3761,6 @@ the persistent save, or allow them to propagate."
;; so simply reading the object in with `eieio-persistent-read' does
;; all the set up we need.
-(cl-defmethod ebdb-db-save ((db ebdb-db-file) &optional _prompt)
- "Mark DB and all its records as \"clean\" after saving."
- (let ((recs (ebdb-dirty-records (slot-value db 'records))))
- ;; Don't do anything if nothing's dirty. Later we can have a
- ;; "force" argument.
- (when (or recs (slot-value db 'dirty))
- ;; These slots must be set to nil, or else we'll write ":dirty
- ;; t" slot values to file, which would be nonsensical.
- (setf (slot-value db 'dirty) nil)
- (dolist (r recs)
- (setf (slot-value r 'dirty) nil))
- (condition-case err
- ;; This does the actual writing to file.
- (cl-call-next-method)
- (error
- (setf (slot-value db 'dirty) t)
- (dolist (r recs)
- (setf (slot-value r 'dirty) t))
- (signal 'error err))))))
-
(cl-defmethod initialize-instance ((db ebdb-db-file) &optional slots)
(let ((object-name (concat "File: " (plist-get slots :file))))
(setq slots (plist-put slots :object-name object-name))
- [elpa] externals/ebdb be4168a 05/33: People have hyphens and apostrophes in their surnames, (continued)
- [elpa] externals/ebdb be4168a 05/33: People have hyphens and apostrophes in their surnames, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb 235dad2 10/33: Fix to database disabling, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb 3d819bc 17/33: Have ebdb-do-records filter out stub uuids, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb 423be4d 14/33: Add ebdb-field-singleton abstract field class, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb 9b07ad6 15/33: Add gender field class, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb 123ebae 09/33: Base ebdb-db-save method should be on ebdb-db class, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb 63509c6 01/33: Work on getting ebdb-vm.el back into place, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb 8291f3d 13/33: Refine database disabling/re-enabling, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb 21ed4b7 19/33: Don't hide cl-print-object definitions, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb 99a1563 12/33: Fix custom type for database buffer-char slot, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb aa668d7 08/33: Add "force" argument to ebdb-db-save,
Eric Abrahamsen <=
- [elpa] externals/ebdb 7bed578 11/33: Provide more careful control of finding related records, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb 9b1a2cf 25/33: Use simpler home-grown version of char-fold-to-regexp, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb c362c2a 23/33: Protect against searching labeled fields with no label, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb 9ff8795 30/33: Alter migration process to convert various folder fields, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb af264e3 18/33: Stop pretending we don't depend on calendar.el, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb 764d89d 21/33: Provide ebdb-load guard in mua-auto-update, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb 70ef68e 22/33: Fix compiler warnings, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb 886c134 27/33: Add new ebdb-field-mail-folder fieldclass, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb 823a7d4 29/33: Use value of ebdb-mua-folder-list in VM splitting, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb a5ffda9 33/33: Merge remote-tracking branch 'elpa/externals/ebdb', Eric Abrahamsen, 2017/09/03