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

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

[elpa] externals/ebdb 9ac0f0f 111/350: Searching on empty strings should


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb 9ac0f0f 111/350: Searching on empty strings should happen in field-search method
Date: Mon, 14 Aug 2017 11:46:17 -0400 (EDT)

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

    Searching on empty strings should happen in field-search method
    
    * ebdb.el (ebdb-record-search): There's no reason to do the check
      here.
    * ebdb.el (ebdb-field-search): Instead, do it here.  I suppose this
      could even be an :around method on ebdb-field-search, to
      short-circuit the test.
---
 ebdb.el | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/ebdb.el b/ebdb.el
index 6620a91..3bea000 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -4508,7 +4508,8 @@ interpreted as t, ie the record passes."
 
 (cl-defmethod ebdb-field-search ((field ebdb-field) (regex string))
   (condition-case nil
-      (string-match-p regex (ebdb-string field))
+      (or (string-empty-p regex)
+         (string-match-p regex (ebdb-string field)))
     (cl-no-applicable-method nil)))
 
 (cl-defmethod ebdb-field-search ((field ebdb-field-labeled) (pair cons))
@@ -4518,7 +4519,6 @@ interpreted as t, ie the record passes."
             (string-empty-p label)
             (string-match-p label (slot-value field 'object-name)))
         (or (null value)
-            (string-empty-p value)
             (ebdb-field-search field value)))))
 
 (cl-defmethod ebdb-field-search ((_field ebdb-field-name-complex) _regex)
@@ -4583,20 +4583,20 @@ values, by default the search is not handed to the name 
field itself."
   (catch 'found
     (pcase search-clause
       (`(* ,(and regexp (pred stringp)))
-       ;; check all user fields
+       ;; Check all user fields.
        (dolist (f (ebdb-record-user-fields record))
         (when (ebdb-field-search f regexp)
-          (throw 'found t)))
-       ;; so that "^$" can be used to find records that
-       ;; have no notes
-       (when (string-match-p regexp "")
-        (throw 'found t)))
+          (throw 'found t))))
+      ;; This is bad, we should not be hard-coding for specific
+      ;; classes.  Should just be composing the right kind of search
+      ;; criteria, then passing it on.
       (`((,(and label (pred stringp)) . ,'ebdb-field-user-simple) ,(and regexp 
(pred stringp)))
        (dolist (f (ebdb-record-user-fields record))
         (when (and (object-of-class-p f ebdb-field-user-simple)
                    (ebdb-field-search f (cons label regexp)))
           (throw 'found t))))
-      (`((,(and field-string (pred stringp)) . ,(and class (pred symbolp))) 
,criterion) ; check one field
+       ;; Check one field.
+      (`((,(and field-string (pred stringp)) . ,(and class (pred symbolp))) 
,criterion)
        (dolist (f (ebdb-record-user-fields record))
         (when (and (object-of-class-p f class)
                    (ebdb-field-search f criterion))



reply via email to

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