emacs-elpa-diffs
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]