diff options
| author | Artur Malabarba | 2015-10-28 15:03:47 +0000 |
|---|---|---|
| committer | Artur Malabarba | 2015-10-28 15:40:23 +0000 |
| commit | 4281f722dd782d91f4b2bbd03834cbd1d944db5c (patch) | |
| tree | 280599df8bf6d01f77debaf922e39e581be8ae78 | |
| parent | faace42f8a4c8f53f629419ba89a5196d62ee006 (diff) | |
| download | emacs-4281f722dd782d91f4b2bbd03834cbd1d944db5c.tar.gz emacs-4281f722dd782d91f4b2bbd03834cbd1d944db5c.zip | |
* lisp/character-fold.el: Make compatible with lax-whitespace
(character-fold-to-regexp): Rework internals to play nice with
lax-whitespacing.
When the user types a space, we want to match the table entry for
?\s, which is generally a regexp like "[ ...]". However, the
`search-spaces-regexp' variable doesn't "see" spaces inside these
regexp constructs, so we need to use "\\( \\|[ ...]\\)" instead (to
manually expose a space).
Furthermore, the lax search engine acts on a bunch of spaces, not
on individual spaces, so if the string contains sequential spaces
like " ", we need to keep them grouped together like this:
"\\( \\|[ ...][ ...]\\)".
| -rw-r--r-- | lisp/character-fold.el | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/lisp/character-fold.el b/lisp/character-fold.el index 6b242f45f4e..521e98b35c1 100644 --- a/lisp/character-fold.el +++ b/lisp/character-fold.el | |||
| @@ -107,10 +107,32 @@ | |||
| 107 | Any character in STRING that has an entry in | 107 | Any character in STRING that has an entry in |
| 108 | `character-fold-table' is replaced with that entry (which is a | 108 | `character-fold-table' is replaced with that entry (which is a |
| 109 | regexp) and other characters are `regexp-quote'd." | 109 | regexp) and other characters are `regexp-quote'd." |
| 110 | (apply #'concat | 110 | (let* ((spaces 0) |
| 111 | (mapcar (lambda (c) (or (aref character-fold-table c) | 111 | (chars (mapcar #'identity string)) |
| 112 | (regexp-quote (string c)))) | 112 | (out chars)) |
| 113 | string))) | 113 | ;; When the user types a space, we want to match the table entry, |
| 114 | ;; but we also want the ?\s to be visible to `search-spaces-regexp'. | ||
| 115 | ;; See commit message for a longer description. | ||
| 116 | (while chars | ||
| 117 | (let ((c (car chars))) | ||
| 118 | (setcar chars | ||
| 119 | (cond | ||
| 120 | ((eq c ?\s) | ||
| 121 | (setq spaces (1+ spaces)) | ||
| 122 | nil) | ||
| 123 | ((> spaces 0) | ||
| 124 | (prog1 (format "\\(?:%s\\|%s\\)%s" | ||
| 125 | (make-string spaces ?\s) | ||
| 126 | (apply #'concat | ||
| 127 | (make-list spaces | ||
| 128 | (or (aref character-fold-table ?\s) " "))) | ||
| 129 | (or (aref character-fold-table c) | ||
| 130 | (regexp-quote (string c)))) | ||
| 131 | (setq spaces 0))) | ||
| 132 | (t (or (aref character-fold-table c) | ||
| 133 | (regexp-quote (string c)))))) | ||
| 134 | (setq chars (cdr chars)))) | ||
| 135 | (apply #'concat out))) | ||
| 114 | 136 | ||
| 115 | 137 | ||
| 116 | ;;; Commands provided for completeness. | 138 | ;;; Commands provided for completeness. |