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

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

[elpa] externals/ebdb e169e58 4/8: Add guards against fields failing to


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb e169e58 4/8: Add guards against fields failing to produce strings
Date: Mon, 6 Jan 2020 14:39:42 -0500 (EST)

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

    Add guards against fields failing to produce strings
    
    * ebdb-com.el (ebdb-fmt-field-label): There always needs to be
    a string to get propertized, otherwise the user can't edit/delete the
    field.
    (ebdb-current-field): Raise an error if no field is found.
---
 ebdb-com.el | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/ebdb-com.el b/ebdb-com.el
index dfdc216..09f5011 100644
--- a/ebdb-com.el
+++ b/ebdb-com.el
@@ -385,7 +385,8 @@ position-marker mark)."
         (next-single-property-change (point)
                                      'ebdb-field nil
                                      (line-end-position)))
-       'ebdb-field)))
+       'ebdb-field)
+      (error "No field at point")))
 
 ;;; *EBDB* formatting
 
@@ -555,7 +556,16 @@ choice: that formatter should be selected explicitly."
                                      (_record ebdb-record))
   "Put the 'ebdb-field text property on FIELD.  The value of the
 property is the field instance itself."
-  (propertize (cl-call-next-method) 'ebdb-field field))
+  (let ((str (cl-call-next-method)))
+    ;; If the field fails to produce a string, or produces an empty
+    ;; string, `propertize' will fail to add the 'ebdb-field property.
+    ;; Put in a dummy string to be propertized, otherwise the user
+    ;; will have no way of interacting with the field.
+    (propertize (if (or (null str)
+                       (string-empty-p str))
+                   "<empty>"
+                 str)
+               'ebdb-field field)))
 
 (cl-defmethod ebdb-fmt-field ((_fmt ebdb-formatter-ebdb)
                              (field ebdb-field)



reply via email to

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