emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/consult 7f0a8c7: consult--default-regexp-compiler: Allo


From: ELPA Syncer
Subject: [elpa] externals/consult 7f0a8c7: consult--default-regexp-compiler: Allow escaping spaces (See #393)
Date: Tue, 10 Aug 2021 09:57:07 -0400 (EDT)

branch: externals/consult
commit 7f0a8c72abf606624e5ced6070f864ed4c81723b
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    consult--default-regexp-compiler: Allow escaping spaces (See #393)
---
 README.org |  3 ++-
 consult.el | 12 +++++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/README.org b/README.org
index e7c51b2..12c2dfe 100644
--- a/README.org
+++ b/README.org
@@ -251,7 +251,8 @@ their descriptions.
    character is a punctuation character, like =#=. For example
    =#grep-regexps#filter-string=, is split at the second =#=. The string
    =grep-regexps= is passed to Grep. If you enter multiple regular expressions
-   separated by space only lines matching all regular expressions are shown. 
The
+   separated by space only lines matching all regular expressions are shown. In
+   order to match space literally, escape the space with a backslash. The
    =filter-string= is passed to the /fast/ Emacs filtering to further narrow 
down
    the list of matches. This is particularly useful if you are using an 
advanced
    completion style like orderless. =consult-grep= supports preview. If the
diff --git a/consult.el b/consult.el
index c1bf880..6517388 100644
--- a/consult.el
+++ b/consult.el
@@ -608,12 +608,22 @@ The function should return a pair, the list of regular 
expressions and a
 highlight function. The highlight function should take a single argument, the
 string to highlight given the INPUT. TYPE is the desired type of regular
 expression, which can be `basic', `extended', `emacs' or `pcre'."
-  (setq input (split-string input nil 'omit-nulls))
+  (setq input (consult--split-escaped input))
   (cons (mapcar (lambda (x) (consult--convert-regexp x type)) input)
         (when-let (regexps (seq-filter #'consult--valid-regexp-p input))
           (lambda (str)
             (consult--highlight-regexps regexps str)))))
 
+(defun consult--split-escaped (str)
+  "Split STR at spaces, which can be escaped with backslash."
+  (mapcar
+   (lambda (x) (replace-regexp-in-string (string 0) " " x))
+   (split-string (replace-regexp-in-string
+                  "\\\\\\\\\\|\\\\ "
+                  (lambda (x) (if (equal x "\\ ") (string 0) x))
+                  str)
+                 " +" t)))
+
 (defun consult--join-regexps (regexps type)
   "Join REGEXPS of TYPE."
   ;; Add lookahead wrapper only if there is more than one regular expression



reply via email to

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