[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ebdb 8291f3d 13/33: Refine database disabling/re-enabli
From: |
Eric Abrahamsen |
Subject: |
[elpa] externals/ebdb 8291f3d 13/33: Refine database disabling/re-enabling |
Date: |
Sun, 3 Sep 2017 17:02:21 -0400 (EDT) |
branch: externals/ebdb
commit 8291f3d923d44032bde3542c3d766b676bae0ec3
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>
Refine database disabling/re-enabling
* ebdb.el (ebdb-load): If a database has been disabled, it is still
read next time EBDB is loaded. In the case of ebdb-db-file, that
means the databases records have been directly loaded and added to
ebdb-record-tracker, which will wreak havoc. Delete the db's records
after loading. Also, add the db to ebdb-db-list here, because it
needs to be in the list so that users can edit it to re-enable it.
(ebdb-db-load): Don't add to the list in the :after method anymore.
* ebdb-com.el (ebdb-redisplay-records): After a database is re-enabled
and re-loaded, its records will first be un-displayed with this
function. Since the records aren't hashed yet, that will cause an
error. If a record is given as a uuid, but it can't be looked up in
the hash table, simply discard the uuid.
---
ebdb-com.el | 107 +++++++++++++++++++++++++++++++-----------------------------
ebdb.el | 9 +++--
2 files changed, 61 insertions(+), 55 deletions(-)
diff --git a/ebdb-com.el b/ebdb-com.el
index c42cc08..34b0105 100644
--- a/ebdb-com.el
+++ b/ebdb-com.el
@@ -817,61 +817,64 @@ displayed records."
local-record renumber-index marker end-marker record-number ret)
(setq records (ebdb-record-list records))
;; First check if we've been given any records as uuid strings,
- ;; rather than actual records.
- (setq records (mapcar
- (lambda (r)
- (or (and (stringp r)
- (ebdb-gethash r 'uuid))
- r))
- records))
+ ;; rather than actual records. If it's a uuid but we can't look
+ ;; it up, then discard it, we can't do anything with it anyway.
+ (setq records
+ (delq nil
+ (mapcar
+ (lambda (r)
+ (if (stringp r)
+ (ebdb-gethash r 'uuid)
+ r))
+ records)))
(dolist (b bufs)
(with-current-buffer b
(let (renumber buffer-read-only)
- (dolist (r records)
- (catch 'bail
- ;; Find the location of record in this buffer. The
- ;; majority of the time this function will be working on
- ;; the single record under point, so short-circuit that
- ;; case. Check if record is present, or if its uuid has
- ;; been left behind by some previous redisplay. If
- ;; record isn't in this buffer, then bail.
- (setq local-record (cond ((equal r (ignore-errors
(ebdb-current-record)))
- (ebdb-current-record t))
- ((assoc r ebdb-records))
- ((assoc (ebdb-record-uuid r)
ebdb-records))
- (t (throw 'bail nil)))
- marker (nth 2 local-record)
- end-marker (nth 2 (car (cdr (memq local-record
ebdb-records)))))
- (unless renumber-index
- (setq renumber-index (cl-position local-record ebdb-records)))
- ;; If point is inside record, put it at the beginning of the
record.
- (when (and (<= marker (point))
- (< (point) (or end-marker (point-max))))
- (goto-char marker))
- (save-excursion
- (goto-char marker)
- (setq record-number (get-text-property (point)
'ebdb-record-number))
- ;; First insert the reformatted record, then delete the old one,
- ;; so that the marker of this record cannot collapse with the
- ;; marker of the subsequent record
- (setq ret (ebdb-redisplay-record r action local-record))
- (put-text-property marker (point) 'ebdb-record-number
record-number)
- (when (eq ret 'removed)
- (setq renumber t))
- (when (memq ret '(removed replaced))
- (delete-region (point) (or end-marker (point-max)))))))
- (when renumber
- ;; If we deleted a record we need to update the subsequent
- ;; record numbers.
- (let* ((markers (append (mapcar (lambda (x) (nth 2 x))
- (cl-subseq ebdb-records
renumber-index))
- (list (point-max))))
- (start (pop markers)))
- (dolist (end markers)
- (put-text-property start end
- 'ebdb-record-number record-number)
- (setq start end
- record-number (1+ record-number))))))
+ (dolist (r records)
+ (catch 'bail
+ ;; Find the location of record in this buffer. The
+ ;; majority of the time this function will be working on
+ ;; the single record under point, so short-circuit that
+ ;; case. Check if record is present, or if its uuid has
+ ;; been left behind by some previous redisplay. If
+ ;; record isn't in this buffer, then bail.
+ (setq local-record (cond ((equal r (ignore-errors
(ebdb-current-record)))
+ (ebdb-current-record t))
+ ((assoc r ebdb-records))
+ ((assoc (ebdb-record-uuid r)
ebdb-records))
+ (t (throw 'bail nil)))
+ marker (nth 2 local-record)
+ end-marker (nth 2 (car (cdr (memq local-record
ebdb-records)))))
+ (unless renumber-index
+ (setq renumber-index (cl-position local-record ebdb-records)))
+ ;; If point is inside record, put it at the beginning of the
record.
+ (when (and (<= marker (point))
+ (< (point) (or end-marker (point-max))))
+ (goto-char marker))
+ (save-excursion
+ (goto-char marker)
+ (setq record-number (get-text-property (point)
'ebdb-record-number))
+ ;; First insert the reformatted record, then delete the old one,
+ ;; so that the marker of this record cannot collapse with the
+ ;; marker of the subsequent record
+ (setq ret (ebdb-redisplay-record r action local-record))
+ (put-text-property marker (point) 'ebdb-record-number
record-number)
+ (when (eq ret 'removed)
+ (setq renumber t))
+ (when (memq ret '(removed replaced))
+ (delete-region (point) (or end-marker (point-max)))))))
+ (when renumber
+ ;; If we deleted a record we need to update the subsequent
+ ;; record numbers.
+ (let* ((markers (append (mapcar (lambda (x) (nth 2 x))
+ (cl-subseq ebdb-records
renumber-index))
+ (list (point-max))))
+ (start (pop markers)))
+ (dolist (end markers)
+ (put-text-property start end
+ 'ebdb-record-number record-number)
+ (setq start end
+ record-number (1+ record-number))))))
(run-hooks 'ebdb-display-hook)))))
(easy-menu-define
diff --git a/ebdb.el b/ebdb.el
index 81a3f1a..cab67e2 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -3618,7 +3618,6 @@ records."
(time-less-p left-time right-time))))
(cl-defmethod ebdb-db-load :after ((db ebdb-db))
- (cl-pushnew db ebdb-db-list)
(setf (slot-value db 'sync-time) (current-time))
(run-hook-with-args 'ebdb-after-read-db-hook db))
@@ -4674,7 +4673,8 @@ important work is done by the `ebdb-db-load' method."
(progn (setq s (eieio-persistent-read auto-save-file
'ebdb-db t))
(setf (slot-value s 'file) orig-filename)
(setf (slot-value s 'dirty) t))
- (setq s (eieio-persistent-read s 'ebdb-db t))))
+ (setq s (eieio-persistent-read s 'ebdb-db t)))
+ (cl-pushnew s ebdb-db-list))
;; Handle new/nonexistent databases.
(when (yes-or-no-p (format "%s does not exist, create? " s))
(setq s (make-instance 'ebdb-db-file :file s :dirty t))
@@ -4686,7 +4686,10 @@ important work is done by the `ebdb-db-load' method."
(if (object-of-class-p s 'ebdb-db)
(if (null (slot-value s 'disabled))
(ebdb-db-load s)
- (message "Database %s is currently disabled." s)
+ (message "%s is currently disabled." (ebdb-string s))
+ ;; Remove this database's records from
+ ;; `ebdb-record-tracker'.
+ (mapcar #'delete-instance (slot-value s 'records))
(sit-for 2))
(error "Object %s is not a EBDB database" s)))
(if (and
- [elpa] externals/ebdb 999374c 03/33: Make ebdb-hashtable weak on value, (continued)
- [elpa] externals/ebdb 999374c 03/33: Make ebdb-hashtable weak on value, Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb b4a24c1 07/33: Revert "Make ebdb-hashtable weak on value", Eric Abrahamsen, 2017/09/03
- [elpa] externals/ebdb cb92680 04/33: Fix mis-named variable, Eric Abrahamsen, 2017/09/03
- [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 <=
- [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, 2017/09/03
- [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