emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 4281f72 3/4: * lisp/character-fold.el: Make compati


From: Artur Malabarba
Subject: [Emacs-diffs] master 4281f72 3/4: * lisp/character-fold.el: Make compatible with lax-whitespace
Date: Wed, 28 Oct 2015 15:41:06 +0000

branch: master
commit 4281f722dd782d91f4b2bbd03834cbd1d944db5c
Author: Artur Malabarba <address@hidden>
Commit: Artur Malabarba <address@hidden>

    * 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:
    "\\(  \\|[ ...][ ...]\\)".
---
 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 6b242f4..521e98b 100644
--- a/lisp/character-fold.el
+++ b/lisp/character-fold.el
@@ -107,10 +107,32 @@
 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."
-  (apply #'concat
-         (mapcar (lambda (c) (or (aref character-fold-table c)
-                            (regexp-quote (string c))))
-                 string)))
+  (let* ((spaces 0)
+         (chars (mapcar #'identity string))
+         (out chars))
+    ;; When the user types a space, we want to match the table entry,
+    ;; but we also want the ?\s to be visible to `search-spaces-regexp'.
+    ;; See commit message for a longer description.
+    (while chars
+      (let ((c (car chars)))
+        (setcar chars
+                (cond
+                 ((eq c ?\s)
+                  (setq spaces (1+ spaces))
+                  nil)
+                 ((> spaces 0)
+                  (prog1 (format "\\(?:%s\\|%s\\)%s"
+                                 (make-string spaces ?\s)
+                                 (apply #'concat
+                                        (make-list spaces
+                                                   (or (aref 
character-fold-table ?\s) " ")))
+                                 (or (aref character-fold-table c)
+                                     (regexp-quote (string c))))
+                    (setq spaces 0)))
+                 (t (or (aref character-fold-table c)
+                        (regexp-quote (string c))))))
+        (setq chars (cdr chars))))
+    (apply #'concat out)))
 
 
 ;;; Commands provided for completeness.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]