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

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

[elpa] externals/consult 030b771 1/2: consult--split-style-perl: Don't s


From: ELPA Syncer
Subject: [elpa] externals/consult 030b771 1/2: consult--split-style-perl: Don't split if the first character is a space
Date: Thu, 5 Aug 2021 20:57:06 -0400 (EDT)

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

    consult--split-style-perl: Don't split if the first character is a space
---
 README.org | 41 +++++++++++++++++++++++------------------
 consult.el | 31 ++++++++++++++++++-------------
 2 files changed, 41 insertions(+), 31 deletions(-)

diff --git a/README.org b/README.org
index f49b1ce..218c9d1 100644
--- a/README.org
+++ b/README.org
@@ -244,20 +244,25 @@ their descriptions.
  #+findex: consult-git-grep
  #+findex: consult-find
  #+findex: consult-locate
- - =consult-grep=, =consult-ripgrep=, =consult-git-grep=: Search for
-   regular expression in files. Consult invokes Grep asynchronously, while you
-   enter the search term. After at least =consult-async-min-input= characters, 
the
-   search gets started. Consult splits the input string into two parts, if the
-   first character is a punctuation character, like =#=. For example
-   =#grep-regexp#filter-string=, is split at the second =#=. The string 
=grep-regexp=
-   is passed to Grep. By default, spaces are replaced by ~.*~. 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
-   =consult-project-root-function= is [[#use-package-example][configured]] and 
returns non-nil, =consult-grep=
-   searches the current project directory. Otherwise the =default-directory= is
-   searched. If =consult-grep= is invoked with prefix argument =C-u M-s g=, 
you can
-   specify the directory manually.
+ - =consult-grep=, =consult-ripgrep=, =consult-git-grep=: Search for regular 
expression
+   in files. Consult invokes Grep asynchronously, while you enter the search
+   term. After at least =consult-async-min-input= characters, the search gets
+   started. Consult splits the input string into two parts, if the first
+   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. If
+   the grep program has support for Perl-compatible regular expressions (PCRE),
+   then the regular expressions can appear in any order. If not, the regular
+   expressions must appear in the input order. In this case, spaces are
+   essentially replaced by ~.*~. 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 =consult-project-root-function= is
+   [[#use-package-example][configured]] and returns non-nil, =consult-grep= 
searches the current project
+   directory. Otherwise the =default-directory= is searched. If =consult-grep= 
is
+   invoked with prefix argument =C-u M-s g=, you can specify the directory
+   manually.
  - =consult-find=, =consult-locate=: Find file by
    matching the path against a regexp. Like for =consult-grep,= either the 
project
    root or the current directory is the root directory for the search. The 
input
@@ -526,14 +531,13 @@ their descriptions.
  used for filtering.
 
  The =perl= splitting style splits the input string at a punctuation character,
- using a similar syntax as Perl regular expressions.
+ using a similar syntax as Perl regular expressions. If the first character is
+ a space, the space is ignored and the remaining string is not split.
 
  Examples:
 
  - =#defun=: Search for "defun" using grep.
- - =#consult embark=: Search for "consult.*embark" using grep.
-   If the grep program has support for Perl-compatible regular expressions
-   (PCRE), the search includes both "consult.*embark" and "embark.*consult".
+ - =#consult embark=: Search for "consult" and "embark" using grep.
  - =#defun#consult=: Search for "defun" using grep, filter with the word
    "consult".
  - =/defun/consult=: It is also possible to use other punctuation
@@ -541,6 +545,7 @@ their descriptions.
  - =#to#=: Force searching for "to" using grep, since the grep pattern
    must be longer than =consult-async-min-input= characters by default.
  - =#defun -- --invert-match#=: Pass argument =--invert-match= to grep.
+ - =_+consult=: Search for "+consult". Note the space in the beginning!
 
  Asynchronous processes like =find= and =grep= create an error log buffer
  =_*consult-async*= (note the leading space), which is useful for
diff --git a/consult.el b/consult.el
index 5a098cc..bb5891f 100644
--- a/consult.el
+++ b/consult.el
@@ -1339,19 +1339,24 @@ The function returns a list with four elements: The 
async string, the
 completion filter string, the new point position computed from POINT and a
 force flag. If the first character is a punctuation character it determines the
 separator. Examples: \"/async/filter\", \"#async#filter\"."
-  (if (string-match-p "^[[:punct:]]" str)
-      (save-match-data
-        (let ((q (regexp-quote (substring str 0 1))))
-          (string-match (concat "^" q "\\([^" q "]*\\)\\(" q "\\)?") str)
-          `(,(match-string 1 str)
-            ,(substring str (match-end 0))
-            ,(max 0 (- point (match-end 0)))
-            ;; Force update it two punctuation characters are entered.
-            ,(match-end 2)
-            ;; List of highlights
-            (0 . ,(match-beginning 1))
-            ,@(and (match-end 2) `((,(match-beginning 2) . ,(match-end 2)))))))
-    `(,str "" 0)))
+  (cond
+   ;; If first character is a punctuation character, perform splitting.
+   ((string-match-p "^[[:punct:]]" str)
+    (save-match-data
+      (let ((q (regexp-quote (substring str 0 1))))
+        (string-match (concat "^" q "\\([^" q "]*\\)\\(" q "\\)?") str)
+        `(,(match-string 1 str)
+          ,(substring str (match-end 0))
+          ,(max 0 (- point (match-end 0)))
+          ;; Force update it two punctuation characters are entered.
+          ,(match-end 2)
+          ;; List of highlights
+          (0 . ,(match-beginning 1))
+          ,@(and (match-end 2) `((,(match-beginning 2) . ,(match-end 2))))))))
+   ;; If first character is a space, ignore it!
+   ((string-prefix-p " " str) `(,(substring str 1) "" 0))
+   ;; Otherwise the whole string is to be treated as async input.
+   (t `(,str "" 0))))
 
 (defun consult--split-separator (sep str point)
   "Split input STR in async input and filtering part at the first separator 
SEP.



reply via email to

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