aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Malabarba2015-10-28 15:50:17 +0000
committerArtur Malabarba2015-10-28 15:50:17 +0000
commit020e8505575390ef464b8058d07cee9b161827b1 (patch)
tree956c3caa7bb065b2e07e7ed51c2e8d41b3bef9ac
parent7dfe247864f12b93b906edb5934af3c356acade4 (diff)
downloademacs-020e8505575390ef464b8058d07cee9b161827b1.tar.gz
emacs-020e8505575390ef464b8058d07cee9b161827b1.zip
* lisp/character-fold.el (character-fold-to-regexp): Fix case
where string ends in space
-rw-r--r--lisp/character-fold.el17
1 files changed, 11 insertions, 6 deletions
diff --git a/lisp/character-fold.el b/lisp/character-fold.el
index 521e98b35c1..223a2cdd51a 100644
--- a/lisp/character-fold.el
+++ b/lisp/character-fold.el
@@ -101,6 +101,13 @@
101 equiv)) 101 equiv))
102 "Used for folding characters of the same group during search.") 102 "Used for folding characters of the same group during search.")
103 103
104(defun character-fold--make-space-string (n)
105 "Return a string that matches N spaces."
106 (format "\\(?:%s\\|%s\\)"
107 (make-string n ?\s)
108 (apply #'concat
109 (make-list n (or (aref character-fold-table ?\s) " ")))))
110
104;;;###autoload 111;;;###autoload
105(defun character-fold-to-regexp (string &optional _lax) 112(defun character-fold-to-regexp (string &optional _lax)
106 "Return a regexp matching anything that character-folds into STRING. 113 "Return a regexp matching anything that character-folds into STRING.
@@ -121,18 +128,16 @@ regexp) and other characters are `regexp-quote'd."
121 (setq spaces (1+ spaces)) 128 (setq spaces (1+ spaces))
122 nil) 129 nil)
123 ((> spaces 0) 130 ((> spaces 0)
124 (prog1 (format "\\(?:%s\\|%s\\)%s" 131 (prog1 (concat (character-fold--make-space-string spaces)
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) 132 (or (aref character-fold-table c)
130 (regexp-quote (string c)))) 133 (regexp-quote (string c))))
131 (setq spaces 0))) 134 (setq spaces 0)))
132 (t (or (aref character-fold-table c) 135 (t (or (aref character-fold-table c)
133 (regexp-quote (string c)))))) 136 (regexp-quote (string c))))))
134 (setq chars (cdr chars)))) 137 (setq chars (cdr chars))))
135 (apply #'concat out))) 138 (concat (apply #'concat out)
139 (when (> spaces 0)
140 (character-fold--make-space-string spaces)))))
136 141
137 142
138;;; Commands provided for completeness. 143;;; Commands provided for completeness.