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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ebdb 1c4fadd 080/350: Make ebdb-record-name a get-or-ge


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb 1c4fadd 080/350: Make ebdb-record-name a get-or-get-and-set operation
Date: Mon, 14 Aug 2017 11:46:07 -0400 (EDT)

branch: externals/ebdb
commit 1c4fadd92199f18ed5503e4e1c20aedd7ceeb964
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>

    Make ebdb-record-name a get-or-get-and-set operation
    
    * ebdb.el (ebdb-record-name): If the cached string isn't there,
      generate it.
      (ebdb-init-record): Don't do the caching here.
      (ebdb-string): This method for records should make use of
      `ebdb-record-name'.
    
    This ought to work okay. It might shift a tiny bit of user wait time
    from load/initialize, to the first search. Probably negligible.
---
 ebdb-com.el |  2 +-
 ebdb.el     | 18 ++++++++++--------
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/ebdb-com.el b/ebdb-com.el
index 5572f62..4a805a1 100644
--- a/ebdb-com.el
+++ b/ebdb-com.el
@@ -589,7 +589,7 @@ This happens in addition to any pre-defined indentation of 
STRING."
     ;; We don't actually ask the name field to format itself, just use
     ;; the cached canonical name string.  We do add the field to the
     ;; string as a text property, however.
-    (insert (slot-value (ebdb-record-cache record) 'name-string))
+    (insert (ebdb-record-name record))
     (add-text-properties (line-beginning-position) (point)
                         (list 'ebdb-record record-class))
     (add-text-properties step (point)
diff --git a/ebdb.el b/ebdb.el
index cceccb7..117f3e6 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -1988,7 +1988,13 @@ only return fields that are suitable for user editing.")
 
 ;; TODO: rename this to `ebdb-record-name-string', it's confusing.
 (cl-defmethod ebdb-record-name ((record ebdb-record))
-  (slot-value (ebdb-record-cache record) 'name-string))
+  "Get or set-and-get the cached name string of RECORD."
+  (let ((cached (slot-value (ebdb-record-cache record) 'name-string))
+       str)
+    (or cached
+       (and (slot-value record 'name)
+            (setf (slot-value (ebdb-record-cache record) 'name-string)
+                  (ebdb-string (slot-value record 'name)))))))
 
 (cl-defmethod ebdb-record-alt-names ((record ebdb-record))
   (slot-value (ebdb-record-cache record) 'alt-names))
@@ -2244,7 +2250,7 @@ priority."
 
 (cl-defmethod ebdb-string ((record ebdb-record-person))
   "Return a readable string label for RECORD."
-  (slot-value (ebdb-record-cache record) 'name-string))
+  (ebdb-record-name record))
 
 (cl-defmethod ebdb-read ((class (subclass ebdb-record-person)) &optional slots)
   "Read the name slot for a \"person\" record."
@@ -2253,9 +2259,7 @@ priority."
      class (plist-put slots :name name))))
 
 (cl-defmethod ebdb-init-record ((record ebdb-record-person))
-  (let ((name (slot-value record 'name)))
-    (ebdb-init-field name record)
-    (setf (slot-value (ebdb-record-cache record) 'name-string) (ebdb-string 
name)))
+  (ebdb-init-field (slot-value record 'name) record)
   (dolist (aka (slot-value record 'aka))
     (ebdb-init-field aka record))
   (dolist (relation (slot-value record 'relations))
@@ -2470,8 +2474,6 @@ Currently only works for mail fields."
 (cl-defmethod ebdb-init-record ((record ebdb-record-organization))
   (let ((name (slot-value record 'name)))
     (ebdb-init-field name record)
-    (setf (slot-value (ebdb-record-cache record) 'name-string)
-         (ebdb-string name))
     (cl-call-next-method)))
 
 (cl-defmethod ebdb-delete-record ((org ebdb-record-organization) &optional _db 
unload)
@@ -2490,7 +2492,7 @@ Currently only works for mail fields."
 
 (cl-defmethod ebdb-string ((record ebdb-record-organization))
   "Return a string representation of RECORD."
-  (slot-value (ebdb-record-cache record) 'name-string))
+  (ebdb-record-name record))
 
 (cl-defmethod ebdb-read ((class (subclass ebdb-record-organization)) &optional 
slots)
   (let ((name (ebdb-read 'ebdb-field-name-simple slots



reply via email to

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