[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/consult 95dadd9 4/5: Ripgrep regular expressions are pe
From: |
ELPA Syncer |
Subject: |
[elpa] externals/consult 95dadd9 4/5: Ripgrep regular expressions are perl-style, but without lookahead |
Date: |
Thu, 5 Aug 2021 15:57:09 -0400 (EDT) |
branch: externals/consult
commit 95dadd98a6a0f08955f67f1e9a7cc312435a86b8
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Ripgrep regular expressions are perl-style, but without lookahead
We have to distinguish the following regular expression types:
- emacs
- basic
- extended
- pcre
- rust
---
consult.el | 53 +++++++++++++++++++++++++++++------------------------
1 file changed, 29 insertions(+), 24 deletions(-)
diff --git a/consult.el b/consult.el
index 40838bc..904c8c3 100644
--- a/consult.el
+++ b/consult.el
@@ -562,7 +562,7 @@ This function only changes the escaping of parentheses,
braces and pipes."
(let ((swap '(("\\|" . "|")
("\\(" . "(") ("\\)" . ")")
("\\{" . "{") ("\\}" . "}")))
- (subst (if (eq type 'pcre)
+ (subst (if (memq type '(pcre rust))
;; \z matches at the end, \Z matches at the end and
before the last \n
'(("\\`" . "\\A") ("\\'" . "\\z")
("\\<" . "\\b") ("\\>" . "\\b")
@@ -4064,23 +4064,23 @@ INITIAL is inital input."
:history '(:input consult--grep-history)
:sort nil)))
-(defvar consult--grep-supported-regexp nil)
-(defun consult--grep-supported-regexp (cmd)
- "Return regexp type supported by grep CMD."
- (or (alist-get cmd consult--grep-supported-regexp)
- (let ((supported (with-temp-buffer
- (insert "^(?=.*b)(?=.*a)")
- (if (eq 0 (call-process-region (point-min) (point-max)
- (symbol-name cmd) nil
nil nil "-P" "^(?=.*b)(?=.*a)"))
- 'pcre
- 'extended))))
- ;; XXX On Emacs 26 does not return the value from setf, this has been
fixed in 27.
- (setf (alist-get cmd consult--grep-supported-regexp) supported)
- supported)))
+(defun consult--grep-lookahead-p (&rest cmd)
+ "Return t if grep CMD supports lookahead."
+ (with-temp-buffer
+ (insert "xaxbx")
+ (eq 0 (apply #'call-process-region (point-min) (point-max)
+ (car cmd) nil nil nil `(,@cmd "^(?=.*b)(?=.*a)")))))
+
+(defvar consult--grep-regexp-type nil)
+(defun consult--grep-regexp-type ()
+ "Return regexp type supported by grep command."
+ (or consult--grep-regexp-type
+ (setq consult--grep-regexp-type
+ (if (consult--grep-lookahead-p "grep" "-P") 'pcre 'extended))))
(defun consult--grep-command-builder (config input)
"Build command line given CONFIG and INPUT."
- (let ((type (consult--grep-supported-regexp 'grep)))
+ (let ((type (consult--grep-regexp-type)))
(setq input (consult--command-split input))
(append (split-string-and-unquote (plist-get config :args))
(list (if (eq type 'pcre) "--perl-regexp" "--extended-regexp")
@@ -4125,9 +4125,16 @@ See `consult-grep' for more details."
(interactive "P")
(consult--grep "Git-grep" consult-git-grep-command dir initial))
+(defvar consult--ripgrep-regexp-type nil)
+(defun consult--ripgrep-regexp-type ()
+ "Return regexp type supported by ripgrep command."
+ (or consult--ripgrep-regexp-type
+ (setq consult--ripgrep-regexp-type
+ (if (consult--grep-lookahead-p "rg" "-P") 'pcre 'rust))))
+
(defun consult--ripgrep-command-builder (config input)
"Build command line given CONFIG and INPUT."
- (let ((type (consult--grep-supported-regexp 'rg)))
+ (let ((type (consult--ripgrep-regexp-type)))
(setq input (consult--command-split input))
(append (split-string-and-unquote (plist-get config :args))
(and (eq type 'pcre) '("-P"))
@@ -4168,18 +4175,16 @@ INITIAL is inital input."
:category 'file
:history '(:input consult--find-history)))
-(defvar consult--find-supported-regexp nil)
-(defun consult--find-supported-regexp ()
+(defvar consult--find-regexp-type nil)
+(defun consult--find-regexp-type ()
"Return regexp type supported by find command."
- (or consult--find-supported-regexp
- (setq consult--find-supported-regexp
- (if (string-match-p "GNU findutils" (shell-command-to-string "find
--version"))
- 'emacs
- 'basic))))
+ (or consult--find-regexp-type
+ (setq consult--find-regexp-type
+ (if (string-match-p "GNU" (shell-command-to-string "find
--version")) 'emacs 'basic))))
(defun consult--find-command-builder (config input)
"Build command line given CONFIG and INPUT."
- (let ((type (consult--find-supported-regexp)))
+ (let ((type (consult--find-regexp-type)))
(setq input (consult--command-split input))
(append (split-string-and-unquote (plist-get config :args))
(cdr (mapcan (lambda (x) `("-and" "-iregex" ,(format ".*%s.*" x)))
- [elpa] externals/consult updated (f31ac4d -> bf598c8), ELPA Syncer, 2021/08/05
- [elpa] externals/consult 1d50745 1/5: Update comment, ELPA Syncer, 2021/08/05
- [elpa] externals/consult 05089f0 2/5: Add lookahead wrapper only if there is more than one regular expression, ELPA Syncer, 2021/08/05
- [elpa] externals/consult 95dadd9 4/5: Ripgrep regular expressions are perl-style, but without lookahead,
ELPA Syncer <=
- [elpa] externals/consult ddc67f1 3/5: consult--convert-regexp: Use \z instead of \Z, ELPA Syncer, 2021/08/05
- [elpa] externals/consult bf598c8 5/5: Always treat \` and \' as ^ and $ respectively, ELPA Syncer, 2021/08/05