branch: externals/ebdb
commit 7da77f4cbf63dfe6f0dd91f2b06a92dc74dfe672
Author: Eric Abrahamsen <[email protected]>
Commit: Eric Abrahamsen <[email protected]>
Expand ebdb-with-record-edits
Fixes #13
* ebdb-com.el (ebdb-with-record-edits): Provide more feedback and
choices to the user when the databases have problems. Should
actually work correctly now.
---
ebdb-com.el | 37 ++++++++++++++++++++++++++++---------
1 file changed, 28 insertions(+), 9 deletions(-)
diff --git a/ebdb-com.el b/ebdb-com.el
index 76d3b89..061f7bc 100644
--- a/ebdb-com.el
+++ b/ebdb-com.el
@@ -1599,15 +1599,34 @@ actually-editable records."
;; "Unless the record has a bum database..."
(catch 'bad
;; Return nil unless we throw a 'bad.
- (dolist (d (slot-value (ebdb-record-cache r) 'database) nil)
- (cond ((object-assoc (slot-value d 'file) 'file ,good-dbs))
- ((object-assoc (slot-value d 'file) 'file ,bad-dbs)
- (throw 'bad t))
- (t
- (if (ebdb-db-editable d)
- (push d ,good-dbs)
- (push d ,bad-dbs)
- (throw 'bad t))))))
+ (condition-case err
+ (dolist (d (slot-value (ebdb-record-cache r) 'database) nil)
+ (cond ((object-assoc (slot-value d 'file) 'file ,good-dbs))
+ ((object-assoc (slot-value d 'file) 'file ,bad-dbs)
+ (throw 'bad t))
+ (t
+ (ebdb-db-editable d)
+ (push d ,good-dbs))))
+ (ebdb-unsynced-db
+ (let ((db (cadr err)))
+ (if (ebdb-db-dirty db)
+ (error "Database %s is out of sync and has unsaved
changes" db)
+ (if (or ebdb-auto-revert
+ (yes-or-no-p
+ (format "Database %s is out of sync, reload?"
+ (ebdb-string db))))
+ (progn
+ (ebdb-reload-database db)
+ (push db ,good-dbs))
+ (push db ,bad-dbs)
+ (message "Database %s is out of sync" db)
+ (sit-for 1)
+ (throw 'bad t)))))
+ (ebdb-readonly-db
+ (push (cadr err) ,bad-dbs)
+ (message "Database %s is read-only" (cadr err))
+ (sit-for 1)
+ (throw 'bad t))))
;; No bum database, it's okay.
(push r ,editable-records)))
(dolist (,(car spec) ,editable-records)