[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/consult 31e5460 1/4: Support Emacs special treatment of
From: |
ELPA Syncer |
Subject: |
[elpa] externals/consult 31e5460 1/4: Support Emacs special treatment of + and * |
Date: |
Thu, 5 Aug 2021 17:57:07 -0400 (EDT) |
branch: externals/consult
commit 31e546093dd0f2a6a6030bbf43fac466f2eb05f9
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Support Emacs special treatment of + and *
---
consult.el | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/consult.el b/consult.el
index 2940e57..c9d7b5f 100644
--- a/consult.el
+++ b/consult.el
@@ -555,23 +555,37 @@ This function only changes the escaping of parentheses,
braces and pipes."
regexp
;; See
https://stackoverflow.com/questions/1946352/comparison-table-for-emacs-regexp-and-perl-compatible-regular-expression-pcre
;; XXX Unsupported Emacs regexp features:
- ;; - * or + at the beginning of a choice, e.g, \(?:* or \|+
;; - \= point matching
;; - Syntax classes \sx \Sx
;; - Character classes \cx \Cx
(let ((swap '(("\\|" . "|")
- ("\\(" . "(") ("\\)" . ")")
- ("\\{" . "{") ("\\}" . "}")))
+ ("\\(" . "(") ("\\)" . ")")
+ ("\\{" . "{") ("\\}" . "}")))
(subst (append
;; Treat \` and \' as beginning and end of line. This is more
;; widely supported and makes sense for line-based commands.
'(("\\`" . "^") ("\\'" . "$"))
+ ;; Star and plus at beginning is supported by Emacs regexps
+ (mapcan (lambda (x)
+ (mapcar (lambda (y)
+ (cons (concat x y)
+ (concat (string-remove-prefix "\\"
x) "\\" y)))
+ '("*" "+")))
+ '("" "\\(" "\\(?:" "\\|"))
+ ;; Word beginning/end replacements
(if (memq type '(pcre rust))
'(("\\<" . "\\b") ("\\>" . "\\b")
("\\_<" . "\\b") ("\\_>" . "\\b"))
'(("\\_<" . "\\<") ("\\_>" . "\\>"))))))
(replace-regexp-in-string
- "\\\\\\\\\\|\\\\?[(){}|]\\|\\\\[`'<>]\\|\\\\_[<>]"
+ (string-join
+ '("\\\\\\(?:(\\|(\\?:\\||\\)[+*]" ;; (+ or (?:* etc
+ "\\`[+*]" ;; + or * at the beginning
+ "\\\\\\\\" ;; backslash
+ "\\\\?[(){}|]" ;; parentheses/braces/pipe, escaped
and unescaped
+ "\\\\[`'<>]" ;; special escapes
+ "\\\\_[<>]") ;; beginning/end of symbol
+ "\\|")
(lambda (x)
(or (cdr (assoc x subst)) (cdr (assoc x swap)) (car (rassoc x swap))
x))
regexp 'fixedcase 'literal))))