aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2016-05-17 23:55:38 +0300
committerJuri Linkov2016-05-17 23:55:38 +0300
commit1fe1e0a8e7e3863d36c1a87ca38d2fa39bc25a56 (patch)
tree4e53bb771b1c81d7a4c79c2323c33b7c37a40274
parenta35826dbd44122b97e93d0c67bf658ced0a07ec6 (diff)
downloademacs-1fe1e0a8e7e3863d36c1a87ca38d2fa39bc25a56.tar.gz
emacs-1fe1e0a8e7e3863d36c1a87ca38d2fa39bc25a56.zip
* lisp/char-fold.el: Rename from character-fold.el.
* lisp/replace.el (replace-char-fold): Rename from replace-character-fold. * test/automated/char-fold-tests.el: Rename from character-fold-tests.el. http://lists.gnu.org/archive/html/emacs-devel/2015-12/msg00529.html
-rw-r--r--doc/emacs/search.texi8
-rw-r--r--etc/NEWS8
-rw-r--r--lisp/char-fold.el (renamed from lisp/character-fold.el)52
-rw-r--r--lisp/isearch.el10
-rw-r--r--lisp/menu-bar.el2
-rw-r--r--lisp/replace.el16
-rw-r--r--test/automated/char-fold-tests.el (renamed from test/automated/character-fold-tests.el)92
7 files changed, 94 insertions, 94 deletions
diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi
index 7958a4a2bfa..d841934c855 100644
--- a/doc/emacs/search.texi
+++ b/doc/emacs/search.texi
@@ -1264,13 +1264,13 @@ but match under character folding are known as @dfn{equivalent
1264character sequences}. 1264character sequences}.
1265 1265
1266@kindex M-s ' @r{(Incremental Search)} 1266@kindex M-s ' @r{(Incremental Search)}
1267@findex isearch-toggle-character-fold 1267@findex isearch-toggle-char-fold
1268 Generally, search commands in Emacs do not by default perform 1268 Generally, search commands in Emacs do not by default perform
1269character folding in order to match equivalent character sequences. 1269character folding in order to match equivalent character sequences.
1270You can enable this behavior by customizing the variable 1270You can enable this behavior by customizing the variable
1271@code{search-default-mode} to @code{character-fold-to-regexp}. 1271@code{search-default-mode} to @code{char-fold-to-regexp}.
1272@xref{Search Customizations}. Within an incremental search, typing 1272@xref{Search Customizations}. Within an incremental search, typing
1273@kbd{M-s '} (@code{isearch-toggle-character-fold}) toggles character 1273@kbd{M-s '} (@code{isearch-toggle-char-fold}) toggles character
1274folding, but only for that search. (Replace commands have a different 1274folding, but only for that search. (Replace commands have a different
1275default, controlled by a separate option; see @ref{Replacement and Lax 1275default, controlled by a separate option; see @ref{Replacement and Lax
1276Matches}.) 1276Matches}.)
@@ -1481,7 +1481,7 @@ replacement is done without case conversion.
1481(@pxref{Lax Search, character folding}) when looking for the text to 1481(@pxref{Lax Search, character folding}) when looking for the text to
1482replace. To enable character folding for matching in 1482replace. To enable character folding for matching in
1483@code{query-replace} and @code{replace-string}, set the variable 1483@code{query-replace} and @code{replace-string}, set the variable
1484@code{replace-character-fold} to a non-@code{nil} value. (This 1484@code{replace-char-fold} to a non-@code{nil} value. (This
1485setting does not affect the replacement text, only how Emacs finds the 1485setting does not affect the replacement text, only how Emacs finds the
1486text to replace. It also doesn't affect @code{replace-regexp}.) 1486text to replace. It also doesn't affect @code{replace-regexp}.)
1487 1487
diff --git a/etc/NEWS b/etc/NEWS
index 3031cab4782..670465f2ab8 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -633,11 +633,11 @@ as many other symbols like U+249C (PARENTHESIZED LATIN SMALL LETTER
633A). 633A).
634 634
635Character folding is enabled by customizing 'search-default-mode' to 635Character folding is enabled by customizing 'search-default-mode' to
636the value 'character-fold-to-regexp'. You can also toggle character 636the value 'char-fold-to-regexp'. You can also toggle character
637folding in the middle of a search by typing 'M-s ''. 637folding in the middle of a search by typing 'M-s ''.
638 638
639'query-replace' honors character folding if the new variable 639'query-replace' honors character folding if the new variable
640'replace-character-fold' is customized to a non-nil value. 640'replace-char-fold' is customized to a non-nil value.
641 641
642+++ 642+++
643*** New user option 'search-default-mode'. 643*** New user option 'search-default-mode'.
@@ -647,9 +647,9 @@ value, nil specifies that Isearch does literal searches (however,
647as in previous Emacs versions). 647as in previous Emacs versions).
648 648
649+++ 649+++
650*** New function 'character-fold-to-regexp' can be used 650*** New function 'char-fold-to-regexp' can be used
651by searching commands to produce a regexp matching anything that 651by searching commands to produce a regexp matching anything that
652character-folds into STRING. 652char-folds into STRING.
653 653
654+++ 654+++
655*** The new 'M-s M-w' key binding uses eww to search the web for the 655*** The new 'M-s M-w' key binding uses eww to search the web for the
diff --git a/lisp/character-fold.el b/lisp/char-fold.el
index 2d3a8c67fa5..68bea29ea45 100644
--- a/lisp/character-fold.el
+++ b/lisp/char-fold.el
@@ -1,4 +1,4 @@
1;;; character-fold.el --- match unicode to similar ASCII -*- lexical-binding: t; -*- 1;;; char-fold.el --- match unicode to similar ASCII -*- lexical-binding: t; -*-
2 2
3;; Copyright (C) 2015-2016 Free Software Foundation, Inc. 3;; Copyright (C) 2015-2016 Free Software Foundation, Inc.
4 4
@@ -22,12 +22,12 @@
22 22
23;;; Code: 23;;; Code:
24 24
25(eval-and-compile (put 'character-fold-table 'char-table-extra-slots 1)) 25(eval-and-compile (put 'char-fold-table 'char-table-extra-slots 1))
26 26
27(defconst character-fold-table 27(defconst char-fold-table
28 (eval-when-compile 28 (eval-when-compile
29 (let ((equiv (make-char-table 'character-fold-table)) 29 (let ((equiv (make-char-table 'char-fold-table))
30 (equiv-multi (make-char-table 'character-fold-table)) 30 (equiv-multi (make-char-table 'char-fold-table))
31 (table (unicode-property-table-internal 'decomposition))) 31 (table (unicode-property-table-internal 'decomposition)))
32 (set-char-table-extra-slot equiv 0 equiv-multi) 32 (set-char-table-extra-slot equiv 0 equiv-multi)
33 33
@@ -115,7 +115,7 @@
115 equiv) 115 equiv)
116 equiv)) 116 equiv))
117 "Used for folding characters of the same group during search. 117 "Used for folding characters of the same group during search.
118This is a char-table with the `character-fold-table' subtype. 118This is a char-table with the `char-fold-table' subtype.
119 119
120Let us refer to the character in question by char-x. 120Let us refer to the character in question by char-x.
121Each entry is either nil (meaning char-x only matches literally) 121Each entry is either nil (meaning char-x only matches literally)
@@ -136,18 +136,18 @@ For instance, the default alist for ?f includes:
136 136
137Exceptionally for the space character (32), ALIST is ignored.") 137Exceptionally for the space character (32), ALIST is ignored.")
138 138
139(defun character-fold--make-space-string (n) 139(defun char-fold--make-space-string (n)
140 "Return a string that matches N spaces." 140 "Return a string that matches N spaces."
141 (format "\\(?:%s\\|%s\\)" 141 (format "\\(?:%s\\|%s\\)"
142 (make-string n ?\s) 142 (make-string n ?\s)
143 (apply #'concat 143 (apply #'concat
144 (make-list n (or (aref character-fold-table ?\s) " "))))) 144 (make-list n (or (aref char-fold-table ?\s) " ")))))
145 145
146;;;###autoload 146;;;###autoload
147(defun character-fold-to-regexp (string &optional _lax from) 147(defun char-fold-to-regexp (string &optional _lax from)
148 "Return a regexp matching anything that character-folds into STRING. 148 "Return a regexp matching anything that char-folds into STRING.
149Any character in STRING that has an entry in 149Any character in STRING that has an entry in
150`character-fold-table' is replaced with that entry (which is a 150`char-fold-table' is replaced with that entry (which is a
151regexp) and other characters are `regexp-quote'd. 151regexp) and other characters are `regexp-quote'd.
152 152
153If the resulting regexp would be too long for Emacs to handle, 153If the resulting regexp would be too long for Emacs to handle,
@@ -156,7 +156,7 @@ just return the result of calling `regexp-quote' on STRING.
156FROM is for internal use. It specifies an index in the STRING 156FROM is for internal use. It specifies an index in the STRING
157from which to start." 157from which to start."
158 (let* ((spaces 0) 158 (let* ((spaces 0)
159 (multi-char-table (char-table-extra-slot character-fold-table 0)) 159 (multi-char-table (char-table-extra-slot char-fold-table 0))
160 (i (or from 0)) 160 (i (or from 0))
161 (end (length string)) 161 (end (length string))
162 (out nil)) 162 (out nil))
@@ -172,9 +172,9 @@ from which to start."
172 (pcase (aref string i) 172 (pcase (aref string i)
173 (`?\s (setq spaces (1+ spaces))) 173 (`?\s (setq spaces (1+ spaces)))
174 (c (when (> spaces 0) 174 (c (when (> spaces 0)
175 (push (character-fold--make-space-string spaces) out) 175 (push (char-fold--make-space-string spaces) out)
176 (setq spaces 0)) 176 (setq spaces 0))
177 (let ((regexp (or (aref character-fold-table c) 177 (let ((regexp (or (aref char-fold-table c)
178 (regexp-quote (string c)))) 178 (regexp-quote (string c))))
179 ;; Long string. The regexp would probably be too long. 179 ;; Long string. The regexp would probably be too long.
180 (alist (unless (> end 50) 180 (alist (unless (> end 50)
@@ -206,13 +206,13 @@ from which to start."
206 (let ((length (car entry)) 206 (let ((length (car entry))
207 (suffix-regexp (cdr entry))) 207 (suffix-regexp (cdr entry)))
208 (concat suffix-regexp 208 (concat suffix-regexp
209 (character-fold-to-regexp subs nil length)))) 209 (char-fold-to-regexp subs nil length))))
210 `((0 . ,regexp) . ,matched-entries) "\\|") 210 `((0 . ,regexp) . ,matched-entries) "\\|")
211 "\\)")))) 211 "\\)"))))
212 out)))) 212 out))))
213 (setq i (1+ i))) 213 (setq i (1+ i)))
214 (when (> spaces 0) 214 (when (> spaces 0)
215 (push (character-fold--make-space-string spaces) out)) 215 (push (char-fold--make-space-string spaces) out))
216 (let ((regexp (apply #'concat (nreverse out)))) 216 (let ((regexp (apply #'concat (nreverse out))))
217 ;; Limited by `MAX_BUF_SIZE' in `regex.c'. 217 ;; Limited by `MAX_BUF_SIZE' in `regex.c'.
218 (if (> (length regexp) 5000) 218 (if (> (length regexp) 5000)
@@ -221,22 +221,22 @@ from which to start."
221 221
222 222
223;;; Commands provided for completeness. 223;;; Commands provided for completeness.
224(defun character-fold-search-forward (string &optional bound noerror count) 224(defun char-fold-search-forward (string &optional bound noerror count)
225 "Search forward for a character-folded version of STRING. 225 "Search forward for a char-folded version of STRING.
226STRING is converted to a regexp with `character-fold-to-regexp', 226STRING is converted to a regexp with `char-fold-to-regexp',
227which is searched for with `re-search-forward'. 227which is searched for with `re-search-forward'.
228BOUND NOERROR COUNT are passed to `re-search-forward'." 228BOUND NOERROR COUNT are passed to `re-search-forward'."
229 (interactive "sSearch: ") 229 (interactive "sSearch: ")
230 (re-search-forward (character-fold-to-regexp string) bound noerror count)) 230 (re-search-forward (char-fold-to-regexp string) bound noerror count))
231 231
232(defun character-fold-search-backward (string &optional bound noerror count) 232(defun char-fold-search-backward (string &optional bound noerror count)
233 "Search backward for a character-folded version of STRING. 233 "Search backward for a char-folded version of STRING.
234STRING is converted to a regexp with `character-fold-to-regexp', 234STRING is converted to a regexp with `char-fold-to-regexp',
235which is searched for with `re-search-backward'. 235which is searched for with `re-search-backward'.
236BOUND NOERROR COUNT are passed to `re-search-backward'." 236BOUND NOERROR COUNT are passed to `re-search-backward'."
237 (interactive "sSearch: ") 237 (interactive "sSearch: ")
238 (re-search-backward (character-fold-to-regexp string) bound noerror count)) 238 (re-search-backward (char-fold-to-regexp string) bound noerror count))
239 239
240(provide 'character-fold) 240(provide 'char-fold)
241 241
242;;; character-fold.el ends here 242;;; char-fold.el ends here
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 418d9ea273a..e4de0b627e3 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -222,7 +222,7 @@ It is nil if none yet.")
222Default value, nil, means edit the string instead." 222Default value, nil, means edit the string instead."
223 :type 'boolean) 223 :type 'boolean)
224 224
225(autoload 'character-fold-to-regexp "character-fold") 225(autoload 'char-fold-to-regexp "char-fold")
226 226
227(defcustom search-default-mode nil 227(defcustom search-default-mode nil
228 "Default mode to use when starting isearch. 228 "Default mode to use when starting isearch.
@@ -236,7 +236,7 @@ isearch).
236If a function, use that function as an `isearch-regexp-function'. 236If a function, use that function as an `isearch-regexp-function'.
237Example functions (and the keys to toggle them during isearch) 237Example functions (and the keys to toggle them during isearch)
238are `word-search-regexp' \(`\\[isearch-toggle-word]'), `isearch-symbol-regexp' 238are `word-search-regexp' \(`\\[isearch-toggle-word]'), `isearch-symbol-regexp'
239\(`\\[isearch-toggle-symbol]'), and `character-fold-to-regexp' \(`\\[isearch-toggle-character-fold]')." 239\(`\\[isearch-toggle-symbol]'), and `char-fold-to-regexp' \(`\\[isearch-toggle-char-fold]')."
240 ;; :type is set below by `isearch-define-mode-toggle'. 240 ;; :type is set below by `isearch-define-mode-toggle'.
241 :type '(choice (const :tag "Literal search" nil) 241 :type '(choice (const :tag "Literal search" nil)
242 (const :tag "Regexp search" t) 242 (const :tag "Regexp search" t)
@@ -718,7 +718,7 @@ Type \\[isearch-toggle-invisible] to toggle search in invisible text.
718Type \\[isearch-toggle-regexp] to toggle regular-expression mode. 718Type \\[isearch-toggle-regexp] to toggle regular-expression mode.
719Type \\[isearch-toggle-word] to toggle word mode. 719Type \\[isearch-toggle-word] to toggle word mode.
720Type \\[isearch-toggle-symbol] to toggle symbol mode. 720Type \\[isearch-toggle-symbol] to toggle symbol mode.
721Type \\[isearch-toggle-character-fold] to toggle character folding. 721Type \\[isearch-toggle-char-fold] to toggle character folding.
722 722
723Type \\[isearch-toggle-lax-whitespace] to toggle whitespace matching. 723Type \\[isearch-toggle-lax-whitespace] to toggle whitespace matching.
724In incremental searches, a space or spaces normally matches any whitespace 724In incremental searches, a space or spaces normally matches any whitespace
@@ -1546,9 +1546,9 @@ The command then executes BODY and updates the isearch prompt."
1546Turning on word search turns off regexp mode.") 1546Turning on word search turns off regexp mode.")
1547(isearch-define-mode-toggle symbol "_" isearch-symbol-regexp "\ 1547(isearch-define-mode-toggle symbol "_" isearch-symbol-regexp "\
1548Turning on symbol search turns off regexp mode.") 1548Turning on symbol search turns off regexp mode.")
1549(isearch-define-mode-toggle character-fold "'" character-fold-to-regexp "\ 1549(isearch-define-mode-toggle char-fold "'" char-fold-to-regexp "\
1550Turning on character-folding turns off regexp mode.") 1550Turning on character-folding turns off regexp mode.")
1551(put 'character-fold-to-regexp 'isearch-message-prefix "char-fold ") 1551(put 'char-fold-to-regexp 'isearch-message-prefix "char-fold ")
1552 1552
1553(isearch-define-mode-toggle regexp "r" nil nil 1553(isearch-define-mode-toggle regexp "r" nil nil
1554 (setq isearch-regexp (not isearch-regexp)) 1554 (setq isearch-regexp (not isearch-regexp))
diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el
index 6571a4b9d4f..640395e8d7d 100644
--- a/lisp/menu-bar.el
+++ b/lisp/menu-bar.el
@@ -1257,7 +1257,7 @@ mail status in mode line"))
1257(defvar menu-bar-search-options-menu 1257(defvar menu-bar-search-options-menu
1258 (let ((menu (make-sparse-keymap "Search Options"))) 1258 (let ((menu (make-sparse-keymap "Search Options")))
1259 1259
1260 (dolist (x '((character-fold-to-regexp "Fold Characters" "Character folding") 1260 (dolist (x '((char-fold-to-regexp "Fold Characters" "Character folding")
1261 (isearch-symbol-regexp "Whole Symbols" "Whole symbol") 1261 (isearch-symbol-regexp "Whole Symbols" "Whole symbol")
1262 (word-search-regexp "Whole Words" "Whole word"))) 1262 (word-search-regexp "Whole Words" "Whole word")))
1263 (bindings--define-key menu (vector (nth 0 x)) 1263 (bindings--define-key menu (vector (nth 0 x))
diff --git a/lisp/replace.el b/lisp/replace.el
index 26e5875dc08..fe90062cc8a 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -33,7 +33,7 @@
33 :type 'boolean 33 :type 'boolean
34 :group 'matching) 34 :group 'matching)
35 35
36(defcustom replace-character-fold nil 36(defcustom replace-char-fold nil
37 "Non-nil means replacement commands should do character folding in matches. 37 "Non-nil means replacement commands should do character folding in matches.
38This means, for instance, that \\=' will match a large variety of 38This means, for instance, that \\=' will match a large variety of
39unicode quotes. 39unicode quotes.
@@ -324,7 +324,7 @@ If `replace-lax-whitespace' is non-nil, a space or spaces in the string
324to be replaced will match a sequence of whitespace chars defined by the 324to be replaced will match a sequence of whitespace chars defined by the
325regexp in `search-whitespace-regexp'. 325regexp in `search-whitespace-regexp'.
326 326
327If `replace-character-fold' is non-nil, matching uses character folding, 327If `replace-char-fold' is non-nil, matching uses character folding,
328i.e. it ignores diacritics and other differences between equivalent 328i.e. it ignores diacritics and other differences between equivalent
329character strings. 329character strings.
330 330
@@ -383,7 +383,7 @@ If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp
383to be replaced will match a sequence of whitespace chars defined by the 383to be replaced will match a sequence of whitespace chars defined by the
384regexp in `search-whitespace-regexp'. 384regexp in `search-whitespace-regexp'.
385 385
386This function is not affected by `replace-character-fold'. 386This function is not affected by `replace-char-fold'.
387 387
388Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace 388Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
389only matches surrounded by word boundaries. A negative prefix arg means 389only matches surrounded by word boundaries. A negative prefix arg means
@@ -474,7 +474,7 @@ If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp
474to be replaced will match a sequence of whitespace chars defined by the 474to be replaced will match a sequence of whitespace chars defined by the
475regexp in `search-whitespace-regexp'. 475regexp in `search-whitespace-regexp'.
476 476
477This function is not affected by `replace-character-fold'. 477This function is not affected by `replace-char-fold'.
478 478
479Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace 479Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
480only matches that are surrounded by word boundaries. 480only matches that are surrounded by word boundaries.
@@ -568,7 +568,7 @@ If `replace-lax-whitespace' is non-nil, a space or spaces in the string
568to be replaced will match a sequence of whitespace chars defined by the 568to be replaced will match a sequence of whitespace chars defined by the
569regexp in `search-whitespace-regexp'. 569regexp in `search-whitespace-regexp'.
570 570
571If `replace-character-fold' is non-nil, matching uses character folding, 571If `replace-char-fold' is non-nil, matching uses character folding,
572i.e. it ignores diacritics and other differences between equivalent 572i.e. it ignores diacritics and other differences between equivalent
573character strings. 573character strings.
574 574
@@ -623,7 +623,7 @@ If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp
623to be replaced will match a sequence of whitespace chars defined by the 623to be replaced will match a sequence of whitespace chars defined by the
624regexp in `search-whitespace-regexp'. 624regexp in `search-whitespace-regexp'.
625 625
626This function is not affected by `replace-character-fold' 626This function is not affected by `replace-char-fold'
627 627
628In Transient Mark mode, if the mark is active, operate on the contents 628In Transient Mark mode, if the mark is active, operate on the contents
629of the region. Otherwise, operate from point to the end of the buffer's 629of the region. Otherwise, operate from point to the end of the buffer's
@@ -2051,9 +2051,9 @@ It is called with three arguments, as if it were
2051 ;; used after `recursive-edit' might override them. 2051 ;; used after `recursive-edit' might override them.
2052 (let* ((isearch-regexp regexp-flag) 2052 (let* ((isearch-regexp regexp-flag)
2053 (isearch-regexp-function (or delimited-flag 2053 (isearch-regexp-function (or delimited-flag
2054 (and replace-character-fold 2054 (and replace-char-fold
2055 (not regexp-flag) 2055 (not regexp-flag)
2056 #'character-fold-to-regexp))) 2056 #'char-fold-to-regexp)))
2057 (isearch-lax-whitespace 2057 (isearch-lax-whitespace
2058 replace-lax-whitespace) 2058 replace-lax-whitespace)
2059 (isearch-regexp-lax-whitespace 2059 (isearch-regexp-lax-whitespace
diff --git a/test/automated/character-fold-tests.el b/test/automated/char-fold-tests.el
index c611217712e..485254aa6cf 100644
--- a/test/automated/character-fold-tests.el
+++ b/test/automated/char-fold-tests.el
@@ -1,4 +1,4 @@
1;;; character-fold-tests.el --- Tests for character-fold.el -*- lexical-binding: t; -*- 1;;; char-fold-tests.el --- Tests for char-fold.el -*- lexical-binding: t; -*-
2 2
3;; Copyright (C) 2013-2016 Free Software Foundation, Inc. 3;; Copyright (C) 2013-2016 Free Software Foundation, Inc.
4 4
@@ -20,42 +20,42 @@
20;;; Code: 20;;; Code:
21 21
22(require 'ert) 22(require 'ert)
23(require 'character-fold) 23(require 'char-fold)
24 24
25(defun character-fold--random-word (n) 25(defun char-fold--random-word (n)
26 (mapconcat (lambda (_) (string (+ 9 (random 117)))) 26 (mapconcat (lambda (_) (string (+ 9 (random 117))))
27 (make-list n nil) "")) 27 (make-list n nil) ""))
28 28
29(defun character-fold--test-search-with-contents (contents string) 29(defun char-fold--test-search-with-contents (contents string)
30 (with-temp-buffer 30 (with-temp-buffer
31 (insert contents) 31 (insert contents)
32 (goto-char (point-min)) 32 (goto-char (point-min))
33 (should (search-forward-regexp (character-fold-to-regexp string) nil 'noerror)) 33 (should (search-forward-regexp (char-fold-to-regexp string) nil 'noerror))
34 (goto-char (point-min)) 34 (goto-char (point-min))
35 (should (character-fold-search-forward string nil 'noerror)) 35 (should (char-fold-search-forward string nil 'noerror))
36 (should (character-fold-search-backward string nil 'noerror)))) 36 (should (char-fold-search-backward string nil 'noerror))))
37 37
38 38
39(ert-deftest character-fold--test-consistency () 39(ert-deftest char-fold--test-consistency ()
40 (dotimes (n 30) 40 (dotimes (n 30)
41 (let ((w (character-fold--random-word n))) 41 (let ((w (char-fold--random-word n)))
42 ;; A folded string should always match the original string. 42 ;; A folded string should always match the original string.
43 (character-fold--test-search-with-contents w w)))) 43 (char-fold--test-search-with-contents w w))))
44 44
45(ert-deftest character-fold--test-lax-whitespace () 45(ert-deftest char-fold--test-lax-whitespace ()
46 (dotimes (n 40) 46 (dotimes (n 40)
47 (let ((w1 (character-fold--random-word n)) 47 (let ((w1 (char-fold--random-word n))
48 (w2 (character-fold--random-word n)) 48 (w2 (char-fold--random-word n))
49 (search-spaces-regexp "\\s-+")) 49 (search-spaces-regexp "\\s-+"))
50 (character-fold--test-search-with-contents 50 (char-fold--test-search-with-contents
51 (concat w1 "\s\n\s\t\f\t\n\r\t" w2) 51 (concat w1 "\s\n\s\t\f\t\n\r\t" w2)
52 (concat w1 " " w2)) 52 (concat w1 " " w2))
53 (character-fold--test-search-with-contents 53 (char-fold--test-search-with-contents
54 (concat w1 "\s\n\s\t\f\t\n\r\t" w2) 54 (concat w1 "\s\n\s\t\f\t\n\r\t" w2)
55 (concat w1 (make-string 10 ?\s) w2))))) 55 (concat w1 (make-string 10 ?\s) w2)))))
56 56
57(defun character-fold--test-match-exactly (string &rest strings-to-match) 57(defun char-fold--test-match-exactly (string &rest strings-to-match)
58 (let ((re (concat "\\`" (character-fold-to-regexp string) "\\'"))) 58 (let ((re (concat "\\`" (char-fold-to-regexp string) "\\'")))
59 (dolist (it strings-to-match) 59 (dolist (it strings-to-match)
60 (should (string-match re it))) 60 (should (string-match re it)))
61 ;; Case folding 61 ;; Case folding
@@ -64,49 +64,49 @@
64 (should (string-match (upcase re) (downcase it))) 64 (should (string-match (upcase re) (downcase it)))
65 (should (string-match (downcase re) (upcase it))))))) 65 (should (string-match (downcase re) (upcase it)))))))
66 66
67(ert-deftest character-fold--test-some-defaults () 67(ert-deftest char-fold--test-some-defaults ()
68 (dolist (it '(("ffl" . "ffl") ("ffi" . "ffi") 68 (dolist (it '(("ffl" . "ffl") ("ffi" . "ffi")
69 ("fi" . "fi") ("ff" . "ff") 69 ("fi" . "fi") ("ff" . "ff")
70 ("ä" . "ä"))) 70 ("ä" . "ä")))
71 (character-fold--test-search-with-contents (cdr it) (car it)) 71 (char-fold--test-search-with-contents (cdr it) (car it))
72 (let ((multi (char-table-extra-slot character-fold-table 0)) 72 (let ((multi (char-table-extra-slot char-fold-table 0))
73 (character-fold-table (make-char-table 'character-fold-table))) 73 (char-fold-table (make-char-table 'char-fold-table)))
74 (set-char-table-extra-slot character-fold-table 0 multi) 74 (set-char-table-extra-slot char-fold-table 0 multi)
75 (character-fold--test-match-exactly (car it) (cdr it))))) 75 (char-fold--test-match-exactly (car it) (cdr it)))))
76 76
77(ert-deftest character-fold--test-fold-to-regexp () 77(ert-deftest char-fold--test-fold-to-regexp ()
78 (let ((character-fold-table (make-char-table 'character-fold-table)) 78 (let ((char-fold-table (make-char-table 'char-fold-table))
79 (multi (make-char-table 'character-fold-table))) 79 (multi (make-char-table 'char-fold-table)))
80 (set-char-table-extra-slot character-fold-table 0 multi) 80 (set-char-table-extra-slot char-fold-table 0 multi)
81 (aset character-fold-table ?a "xx") 81 (aset char-fold-table ?a "xx")
82 (aset character-fold-table ?1 "44") 82 (aset char-fold-table ?1 "44")
83 (aset character-fold-table ?\s "-!-") 83 (aset char-fold-table ?\s "-!-")
84 (character-fold--test-match-exactly "a1a1" "xx44xx44") 84 (char-fold--test-match-exactly "a1a1" "xx44xx44")
85 (character-fold--test-match-exactly "a1 a 1" "xx44-!--!-xx-!-44") 85 (char-fold--test-match-exactly "a1 a 1" "xx44-!--!-xx-!-44")
86 (aset multi ?a '(("1" . "99") 86 (aset multi ?a '(("1" . "99")
87 ("2" . "88") 87 ("2" . "88")
88 ("12" . "77"))) 88 ("12" . "77")))
89 (character-fold--test-match-exactly "a" "xx") 89 (char-fold--test-match-exactly "a" "xx")
90 (character-fold--test-match-exactly "a1" "xx44" "99") 90 (char-fold--test-match-exactly "a1" "xx44" "99")
91 (character-fold--test-match-exactly "a12" "77" "xx442" "992") 91 (char-fold--test-match-exactly "a12" "77" "xx442" "992")
92 (character-fold--test-match-exactly "a2" "88") 92 (char-fold--test-match-exactly "a2" "88")
93 (aset multi ?1 '(("2" . "yy"))) 93 (aset multi ?1 '(("2" . "yy")))
94 (character-fold--test-match-exactly "a1" "xx44" "99") 94 (char-fold--test-match-exactly "a1" "xx44" "99")
95 (character-fold--test-match-exactly "a12" "77" "xx442" "992") 95 (char-fold--test-match-exactly "a12" "77" "xx442" "992")
96 ;; Support for this case is disabled. See function definition or: 96 ;; Support for this case is disabled. See function definition or:
97 ;; https://lists.gnu.org/archive/html/emacs-devel/2015-11/msg02562.html 97 ;; https://lists.gnu.org/archive/html/emacs-devel/2015-11/msg02562.html
98 ;; (character-fold--test-match-exactly "a12" "xxyy") 98 ;; (char-fold--test-match-exactly "a12" "xxyy")
99 )) 99 ))
100 100
101(ert-deftest character-fold--speed-test () 101(ert-deftest char-fold--speed-test ()
102 (dolist (string (append '("tty-set-up-initial-frame-face" 102 (dolist (string (append '("tty-set-up-initial-frame-face"
103 "tty-set-up-initial-frame-face-frame-faceframe-faceframe-faceframe-face") 103 "tty-set-up-initial-frame-face-frame-faceframe-faceframe-faceframe-face")
104 (mapcar #'character-fold--random-word '(10 50 100 104 (mapcar #'char-fold--random-word '(10 50 100
105 50 100)))) 105 50 100))))
106 (message "Testing %s" string) 106 (message "Testing %s" string)
107 ;; Make sure we didn't just fallback on the trivial search. 107 ;; Make sure we didn't just fallback on the trivial search.
108 (should-not (string= (regexp-quote string) 108 (should-not (string= (regexp-quote string)
109 (character-fold-to-regexp string))) 109 (char-fold-to-regexp string)))
110 (with-temp-buffer 110 (with-temp-buffer
111 (save-excursion (insert string)) 111 (save-excursion (insert string))
112 (let ((time (time-to-seconds (current-time)))) 112 (let ((time (time-to-seconds (current-time))))
@@ -114,11 +114,11 @@
114 ;; created a lot of redundant paths in the regexp. Because of 114 ;; created a lot of redundant paths in the regexp. Because of
115 ;; that, if a really long string "almost" matches, the regexp 115 ;; that, if a really long string "almost" matches, the regexp
116 ;; engine took a long time to realize that it doesn't match. 116 ;; engine took a long time to realize that it doesn't match.
117 (should-not (character-fold-search-forward (concat string "c") nil 'noerror)) 117 (should-not (char-fold-search-forward (concat string "c") nil 'noerror))
118 ;; Ensure it took less than a second. 118 ;; Ensure it took less than a second.
119 (should (< (- (time-to-seconds (current-time)) 119 (should (< (- (time-to-seconds (current-time))
120 time) 120 time)
121 1)))))) 121 1))))))
122 122
123(provide 'character-fold-tests) 123(provide 'char-fold-tests)
124;;; character-fold-tests.el ends here 124;;; char-fold-tests.el ends here