From f5f18f95d459a4031eda4b7f43a151e12a386338 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 25 Oct 2015 01:43:23 +0100 Subject: [PATCH] * 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. --- lisp/character-fold.el | 47 ++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/lisp/character-fold.el b/lisp/character-fold.el index 988a5065c0d..6b242f45f4e 100644 --- a/lisp/character-fold.el +++ b/lisp/character-fold.el @@ -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 -- 2.39.5