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

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

[elpa] externals/ebdb 498a580 214/350: Allow user transformation of sear


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb 498a580 214/350: Allow user transformation of search strings
Date: Mon, 14 Aug 2017 11:46:39 -0400 (EDT)

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

    Allow user transformation of search strings
    
    Addresses #23
    
    * ebdb.el (ebdb-search-transform-functions): New custom option -- a
      list of functions used to transform search strings.
      (ebdb-search-read): Add an :around method that runs search strings
      through the functions in the above method.
---
 ebdb.el | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/ebdb.el b/ebdb.el
index a7b69ae..2acd3f8 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -383,6 +383,24 @@ Lisp Hackers: See also `ebdb-silent-internal'."
   :type '(choice (const :tag "Run silently" t)
                  (const :tag "Disable silent running" nil)))
 
+(defcustom ebdb-search-transform-functions nil
+  "A list of functions used to transform strings during
+  searching.
+
+Each time the user enters a search search string during
+interactive search, that string will be passed through each of
+the functions in this list, which have a chance to modify the
+string somehow before it is actually matched against field
+values.
+
+Each function should accept a single argument, a string, and
+return the transformed string.  If the criteria for any given
+search is not a string, it will not be passed through these
+functions."
+
+  :group 'ebdb
+  :type 'list)
+
 (defcustom ebdb-info-file nil
   "Location of the ebdb info file, if it's not in the standard place."
   :group 'ebdb
@@ -4750,6 +4768,16 @@ values, by default the search is not handed to the name 
field itself."
 In most cases this is a simple regexp, but field classes can
 prompt users for more complex search criteria, if necessary.")
 
+(cl-defmethod ebdb-search-read :around ((cls (subclass ebdb-field)))
+  "Give the functions in `ebdb-search-transform-functions' a
+chance to transform the search string."
+  (let ((criterion (cl-call-next-method)))
+    (if (and ebdb-search-transform-functions
+            (stringp criterion))
+       (dolist (f ebdb-search-transform-functions criterion)
+         (setq criterion (funcall f criterion)))
+      criterion)))
+
 (cl-defmethod ebdb-search-read ((cls (subclass ebdb-field)))
   (read-string (format "Search records with %s %smatching regexp: "
                       (ebdb-field-readable-name cls)



reply via email to

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