[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
- [elpa] externals/ebdb 40d71b9 222/350: Steal UUID generating function from Org, (continued)
- [elpa] externals/ebdb 40d71b9 222/350: Steal UUID generating function from Org, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 4937cbd 225/350: Specify class of name fields when updating from MUA, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 13c0a38 216/350: Tweaks to testing macros, more tests, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 2b28f57 239/350: Bump to version 0.2, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb ff3cfa4 232/350: ebdb-parse-i18n for Chinese phones should pass class arg through, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb d5bec83 229/350: Fix to UUID change, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 72aba6a 228/350: New label/field alist for vcard export, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb d0d0bbb 233/350: Shift transformation of search strings into ebdb-search, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb dc4217d 213/350: Compiler-inspired fixes, volume 5453, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb ce5d9ee 242/350: Fix vCard formatting for anniversaries, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 5d7a58c 246/350: Add option for character fold searching,
Eric Abrahamsen <=
- [elpa] externals/ebdb e5696fa 253/350: Add counsel-ebdb.el, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb fb4d5d5 255/350: Migration should guard against unparseable emails, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb aa15250 252/350: Change newline approach in vCard handling, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 0120729 240/350: Add vcard unescaping, and some vcard tests, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 6f8d59b 254/350: Fix record citation, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 3106b45 256/350: Require ebdb-format in ebdb-vcard, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 7549366 259/350: New method: ebdb-db-load-records, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb b37356a 270/350: Fix docstring of ebdb-create-record, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 5135645 260/350: Split out ebdb-notice-record and ebdb-notice-field methods, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 71a93f5 268/350: Put a load protection in ebdb-mua-update-records, Eric Abrahamsen, 2017/08/14