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

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

[elpa] externals/ebdb 5d7a58c 246/350: Add option for character fold sea


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb 5d7a58c 246/350: Add option for character fold searching
Date: Mon, 14 Aug 2017 11:46:47 -0400 (EDT)

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

    Add option for character fold searching
    
    * ebdb.el (ebdb-search): First of all, new defgroup.
      (ebdb-case-fold-search, ebdb-search-transform-functions): Part of
      this group.
      (ebdb-char-fold-search): New boolean customization option for
      enabling char-fold searching.
      (ebdb-search): Take new option into account.
    * ebdb-test.el (ebdb-search-transform-and-fold): Test new stuff.
    * ebdb.org (Changing Search Behavior): Document new stuff.
---
 ebdb-test.el | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ebdb.el      | 33 +++++++++++++++++++------
 ebdb.org     | 22 +++++++++++++++++
 3 files changed, 126 insertions(+), 8 deletions(-)

diff --git a/ebdb-test.el b/ebdb-test.el
index b2fd01a..93e3819 100644
--- a/ebdb-test.el
+++ b/ebdb-test.el
@@ -268,6 +268,85 @@
                         t))
                       rec))))))
 
+;; Test search folding and transform functions.
+
+(ert-deftest ebdb-search-transform-and-fold ()
+  (ebdb-test-with-records
+    (let ((recs
+          (list (make-instance
+                 'ebdb-record-person
+                 :name (ebdb-parse 'ebdb-field-name-complex "Björk 
Jónsdóttir")))))
+
+      (let ((ebdb-case-fold-search nil)
+           (ebdb-char-fold-search nil)
+           (ebdb-search-transform-functions nil))
+       (should-not (ebdb-search
+                    recs
+                    '((ebdb-field-name "Bjork"))))
+       (should-not (ebdb-search
+                    recs
+                    '((ebdb-field-name "björk"))))
+       (should (ebdb-search
+                recs
+                '((ebdb-field-name "Björk")))))
+
+      (let ((ebdb-case-fold-search t)
+           (ebdb-char-fold-search nil)
+           (ebdb-search-transform-functions nil))
+       (should-not (ebdb-search
+                    recs
+                    '((ebdb-field-name "Bjork"))))
+       (should (ebdb-search
+                recs
+                '((ebdb-field-name "björk"))))
+       (should (ebdb-search
+                recs
+                '((ebdb-field-name "Björk")))))
+
+      (let ((ebdb-case-fold-search nil)
+           (ebdb-char-fold-search t)
+           (ebdb-search-transform-functions nil))
+       (should (ebdb-search
+                recs
+                '((ebdb-field-name "Bjork"))))
+       (should-not (ebdb-search
+                    recs
+                    '((ebdb-field-name "björk"))))
+       (should (ebdb-search
+                recs
+                '((ebdb-field-name "Björk")))))
+
+      (let ((ebdb-case-fold-search t)
+           (ebdb-char-fold-search t)
+           (ebdb-search-transform-functions nil))
+       (should (ebdb-search
+                recs
+                '((ebdb-field-name "Bjork"))))
+       (should (ebdb-search
+                recs
+                '((ebdb-field-name "björk"))))
+       (should (ebdb-search
+                recs
+                '((ebdb-field-name "Björk"))))
+
+       (let ((ebdb-case-fold-search nil)
+             (ebdb-char-fold-search nil)
+             (ebdb-search-transform-functions
+              (list (lambda (str)
+                      (concat str " Jonsdottir")))))
+         (should-not (ebdb-search
+                      recs
+                      '((ebdb-field-name "Björk")))))
+
+       (let ((ebdb-case-fold-search nil)
+             (ebdb-char-fold-search t)
+             (ebdb-search-transform-functions
+              (list (lambda (str)
+                      (concat str " Jonsdottir")))))
+         (should (ebdb-search
+                  recs
+                  '((ebdb-field-name "Björk")))))))))
+
 ;; Vcard testing.
 
 (ert-deftest ebdb-vcard-escape/unescape ()
diff --git a/ebdb.el b/ebdb.el
index b22db24..0388728 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -189,6 +189,10 @@ Organization names are currently hard-coded to use
   :group 'ebdb)
 (put 'ebdb-snarf-snarf 'custom-loads '(ebdb-snarf))
 
+(defgroup ebdb-search nil
+  "Customizations for EBDB searching."
+  :group 'ebdb)
+
 (defgroup ebdb-utilities nil
   "Customizations for EBDB Utilities"
   :group 'ebdb)
@@ -399,9 +403,24 @@ 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
+  :group 'ebdb-search
   :type 'list)
 
+(defcustom ebdb-case-fold-search (default-value 'case-fold-search)
+  "Value of `case-fold-search' used when searching EBDB records."
+
+  :group 'ebdb-search
+  :type 'boolean)
+
+(defcustom ebdb-char-fold-search nil
+  "If t, record searches will use character folding.
+
+Character folding means that, for instance, searches for \"i\"
+will match \"ì\", and so on.  This may slow searching down."
+
+  :group 'ebdb-search
+  :type 'boolean)
+
 (defcustom ebdb-info-file nil
   "Location of the ebdb info file, if it's not in the standard place."
   :group 'ebdb
@@ -3501,13 +3520,6 @@ addresses."
 
 ;;; Record editing
 
-(defcustom ebdb-case-fold-search (default-value 'case-fold-search)
-  "Value of `case-fold-search' used by EBDB and friends.
-This variable lets the case-sensitivity of the EBDB commands
-be different from standard commands like command `isearch-forward'."
-  :group 'ebdb-record-edit
-  :type 'boolean)
-
 ;; The following two options should be obviated by ebdb-i18n.el
 ;; See http://en.wikipedia.org/wiki/Postal_address
 ;; 
http://www.upu.int/en/activities/addressing/postal-addressing-systems-in-member-countstateries.html
@@ -4850,6 +4862,11 @@ interpreted as t, ie the record passes."
                   (stringp (cadr c)))
          (dolist (func ebdb-search-transform-functions)
            (setf (cadr c) (funcall func (cadr c)))))))
+    (when ebdb-char-fold-search
+      (dolist (c clauses)
+       (when (and (consp c)
+                  (stringp (cadr c))))
+       (setf (cadr c) (char-fold-to-regexp (cadr c)))))
     (seq-filter
      (lambda (r)
        (eql (null invert)
diff --git a/ebdb.org b/ebdb.org
index bad0804..5e603de 100644
--- a/ebdb.org
+++ b/ebdb.org
@@ -369,6 +369,28 @@ User-created {{{ebuf}}} buffers keep track of search 
history in that
 buffer.  To pop back to previous searches, use:
 
 - "^": ebdb-search-pop
+*** Changing Search Behavior
+There are three ways to alter the behavior of EBDB searches.
+
+- Variable ebdb-case-fold-search
+  An equivalent to the regular `case-fold-search' variable, which
+  see.  Defaults to the value of that variable.
+- Variable ebdb-char-fold-search
+  Controls whether character folding is used when matching search
+  strings against record values.
+- Variable ebdb-search-transform-functions
+  A list of functions that can be used to arbitrarily transform search
+  strings.  Each function should accept a single string argument, and
+  return the transformed string.  If the search criterion is not a
+  string (some fields produce sexp search criteria) these functions
+  will not be used.
+
+Be careful of potential interaction between character folding and
+transform functions.  Character folding works by calling
+`char-fold-to-regexp' on the search string, effectively replacing
+foldable characters within the string using regular expressions.  This
+process happens /after/ the transform functions have run, so there is
+a possibility for unexpected search behavior.
 ** Marking
 Records can be marked and acted on in bulk.  The "#" key will toggle
 the mark of the record under point.  "M-#" will toggle the marks of



reply via email to

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