1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-04 08:47:11 +00:00

* lisp/character-fold.el: Many improvements

(character-fold-search-forward, character-fold-search-backward):
New command
(character-fold-to-regexp): Remove lax-whitespace hack.
(character-fold-search): Remove variable.  Only isearch and
query-replace use char-folding, and they both have their own
variables to configure that.
This commit is contained in:
Artur Malabarba 2015-10-25 01:43:23 +01:00
parent c5f9ccfce2
commit f5f18f95d4

View File

@ -23,14 +23,6 @@
;;; Code:
;;;###autoload
(defvar character-fold-search nil
"Non-nil if searches should fold similar characters.
This means some characters will match entire groups of characters.
For instance, \" will match all variants of double quotes, and
the letter a will match all of its accented versions (and then
some).")
(defconst character-fold-table
(eval-when-compile
(let* ((equiv (make-char-table 'character-fold-table))
@ -110,21 +102,32 @@ some).")
"Used for folding characters of the same group during search.")
;;;###autoload
(defun character-fold-to-regexp (string &optional lax)
(defun character-fold-to-regexp (string &optional _lax)
"Return a regexp matching anything that character-folds into STRING.
If `character-fold-search' is nil, `regexp-quote' string.
Otherwise, any character in STRING that has an entry in
Any character in STRING that has an entry in
`character-fold-table' is replaced with that entry (which is a
regexp) and other characters are `regexp-quote'd.
If LAX is non-nil, any single whitespace character is allowed to
match any number of times."
(if character-fold-search
(apply #'concat
(mapcar (lambda (c) (if (and lax (memq c '(?\s ?\t ?\r ?\n)))
"[ \t\n\r\xa0\x2002\x2d\x200a\x202f\x205f\x3000]+"
(or (aref character-fold-table c)
(regexp-quote (string c)))))
string))
(regexp-quote string)))
regexp) and other characters are `regexp-quote'd."
(apply #'concat
(mapcar (lambda (c) (or (aref character-fold-table c)
(regexp-quote (string c))))
string)))
;;; Commands provided for completeness.
(defun character-fold-search-forward (string &optional bound noerror count)
"Search forward for a character-folded version of STRING.
STRING is converted to a regexp with `character-fold-to-regexp',
which is searched for with `re-search-forward'.
BOUND NOERROR COUNT are passed to `re-search-forward'."
(interactive "sSearch: ")
(re-search-forward (character-fold-to-regexp string) bound noerror count))
(defun character-fold-search-backward (string &optional bound noerror count)
"Search backward for a character-folded version of STRING.
STRING is converted to a regexp with `character-fold-to-regexp',
which is searched for with `re-search-backward'.
BOUND NOERROR COUNT are passed to `re-search-backward'."
(interactive "sSearch: ")
(re-search-backward (character-fold-to-regexp string) bound noerror count))
;;; character-fold.el ends here