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

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

[elpa] externals/ebdb ef673e2 094/350: Improve organization searching


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb ef673e2 094/350: Improve organization searching
Date: Mon, 14 Aug 2017 11:46:14 -0400 (EDT)

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

    Improve organization searching
    
    * ebdb.el (ebdb-record-search): New methods that specialize on the
      'organization symbol. Implement for person and organization records.
      While we're at it, add a record-search implementation for
      organizations and mails -- it should also check the domain slot.
    * ebdb-com.el (ebdb-search-organization): Alter this accordingly.
---
 ebdb-com.el |  6 ++++--
 ebdb.el     | 35 ++++++++++++++++++++++++-----------
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/ebdb-com.el b/ebdb-com.el
index bea3a7a..14b1df2 100644
--- a/ebdb-com.el
+++ b/ebdb-com.el
@@ -1954,8 +1954,10 @@ in either the name(s), organization, address, phone, 
mail, or xfields."
   "Display all records in the EBDB matching REGEXP in the organization field."
   (interactive (list (ebdb-search-read "organization") 
(ebdb-formatter-prefix)))
   (ebdb-display-records
-   (ebdb-search (ebdb-records 'ebdb-record-organization t)
-               regexp)
+   (seq-filter
+    (lambda (r)
+      (ebdb-record-search r 'organization regexp))
+    (ebdb-records))
    fmt))
 
 ;;;###autoload
diff --git a/ebdb.el b/ebdb.el
index 89b3dae..ce8d723 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -2420,6 +2420,14 @@ Currently only works for mail fields."
   "Return a list of organization string names from RECORD's cache."
   (slot-value (ebdb-record-cache record) 'organizations))
 
+(cl-defmethod ebdb-record-search ((record ebdb-record-person)
+                                 (_type (eql organization))
+                                 (regex string))
+  (or (seq-find (lambda (org)
+                 (string-match-p regex org))
+               (ebdb-record-organizations record))
+      (string-match-p regex "")))
+
 ;;; This needs some more thought.
 ;; (cl-defmethod ebdb-mail-set-priority ((mail ebdb-field-mail)
 ;;                                   (record ebdb-record-person)
@@ -2572,7 +2580,21 @@ Currently only works for mail fields."
 (cl-defmethod ebdb-record-search ((record ebdb-record-organization)
                                  (_type (eql name))
                                  (regex string))
-  (string-match-p regex (ebdb-string (slot-value record 'name))))
+  (string-match-p regex (ebdb-record-name record)))
+
+(cl-defmethod ebdb-record-search ((record ebdb-record-organization)
+                                 (_type (eql organization))
+                                 (regex string))
+  (or (string-match-p regex (ebdb-record-name record))
+      (and (slot-value record 'domain)
+          (string-match-p regex (ebdb-string (slot-value record 'domain))))))
+
+(cl-defmethod ebdb-record-search ((record ebdb-record-organization)
+                                 (_type (eql mail))
+                                 (regexp string))
+  (let ((domain (slot-value record 'domain)))
+    (or (and domain (string-match-p regexp (ebdb-string domain)))
+       (cl-call-next-method))))
 
 (cl-defmethod ebdb-record-insert-field :after ((org ebdb-record-organization)
                                               _slot
@@ -4619,16 +4641,7 @@ but not allowing for regexps."
     (when name-re
       (push `(ebdb-record-search record 'name ,name-re) clauses))
     (when org-re
-      (push `(let ((organizations (when (slot-exists-p record 'organizations)
-                                   (slot-value record 'organizations)))
-                  org done)
-              (if organizations
-                  (while (and (setq org (pop organizations)) (not done))
-                    (setq done (string-match ,org-re (ebdb-string org))))
-                ;; so that "^$" can be used to find records that
-                ;; have no organization
-                (setq done (string-match ,org-re "")))
-              done)
+      (push `(ebdb-record-search record 'organization ,org-re)
            clauses))
 
     (when phone-re



reply via email to

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