[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ivy-hydra 33fa992 250/395: Fix swiper handling of bol r
From: |
Basil L. Contovounesios |
Subject: |
[elpa] externals/ivy-hydra 33fa992 250/395: Fix swiper handling of bol regex |
Date: |
Thu, 25 Feb 2021 08:32:13 -0500 (EST) |
branch: externals/ivy-hydra
commit 33fa992aebe9605a3130d221543a232dafce5ab9
Author: Troy Hinckley <t.macman@gmail.com>
Commit: Oleh Krehel <ohwoeowho@gmail.com>
Fix swiper handling of bol regex
Fixes #2418
Fixes #2495
---
ivy-test.el | 7 ++++---
swiper.el | 65 +++++++++++++++++++++++--------------------------------------
2 files changed, 28 insertions(+), 44 deletions(-)
diff --git a/ivy-test.el b/ivy-test.el
index e24477b..7af21c1 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -221,12 +221,13 @@ Since `execute-kbd-macro' doesn't pick up a let-bound
`default-directory'.")
(ert-deftest swiper--re-builder ()
(setq swiper--width 4)
+ (setf (ivy-state-caller ivy-last) 'swiper)
(should (string= (swiper--re-builder "^")
- "."))
+ "^ "))
(should (string= (swiper--re-builder "^a")
- "^ ?\\(a\\)"))
+ "^ a"))
(should (string= (swiper--re-builder "^a b")
- "^ \\(a\\).*?\\(b\\)"))
+ "\\(^ a\\).*?\\(b\\)"))
(should
(string-match-p
"\\`\\\\_<.*\\\\_>\\'"
diff --git a/swiper.el b/swiper.el
index b8b0b7f..d5e32b8 100644
--- a/swiper.el
+++ b/swiper.el
@@ -734,7 +734,22 @@ When capture groups are present in the input, print them
instead of lines."
(when (bound-and-true-p evil-mode)
(evil-set-jump)))
-(declare-function char-fold-to-regexp "char-fold")
+(defun swiper--normalize-regex (re)
+ "Normalize the swiper regex RE.
+Add a space after a leading `^' if needed and apply
+`search-default-mode' if bound."
+ (replace-regexp-in-string
+ "^\\(?:\\\\(\\)?\\^"
+ (concat "\\&" (if (eq 'swiper (ivy-state-caller ivy-last)) " " ""))
+ (if (functionp (bound-and-true-p search-default-mode))
+ (mapconcat
+ (lambda (x)
+ (if (string-match-p "\\`[^$\\^]+\\'" x)
+ (funcall search-default-mode x)
+ x))
+ (split-string re "\\b") "")
+ re)
+ t))
(defun swiper--re-builder (str)
"Transform STR into a swiper regex.
@@ -742,46 +757,14 @@ This is the regex used in the minibuffer where candidates
have
line numbers. For the buffer, use `ivy--regex' instead."
(let* ((re-builder (ivy-alist-setting ivy-re-builders-alist))
(str (replace-regexp-in-string "\\\\n" "\n" str))
- (re (cond
- ((equal str "")
- "")
- ((equal str "^")
- (setq ivy--subexps 0)
- ".")
- ((= (aref str 0) ?^)
- (let* ((re (funcall re-builder (substring str 1)))
- (re (if (listp re)
- (mapconcat (lambda (x)
- (format "\\(%s\\)" (car x)))
- (cl-remove-if-not #'cdr re)
- ".*?")
- re)))
- (cond
- ((string= re "$")
- (if (eq (ivy-state-caller ivy-last) 'swiper)
- "^ $"
- "^$"))
- ((zerop ivy--subexps)
- (prog1 (format "^ ?\\(%s\\)" re)
- (setq ivy--subexps 1)))
- (t
- (format "^ %s" re)))))
- ;; Added in Emacs 25.1.
- ((fboundp (bound-and-true-p search-default-mode))
- (if (string-match "\\`\\\\_<\\(.+\\)\\\\_>\\'" str)
- (concat
- "\\_<"
- (funcall search-default-mode (match-string 1 str))
- "\\_>")
- (let ((subs (ivy--split str)))
- (setq ivy--subexps (length subs))
- (mapconcat
- (lambda (s) (format "\\(%s\\)" (funcall
search-default-mode s)))
- subs
- ".*?"))))
- (t
- (funcall re-builder str)))))
- re))
+ (re (funcall re-builder str)))
+ (if (consp re)
+ (mapcar
+ (lambda (x)
+ (cons (swiper--normalize-regex (car x))
+ (cdr x)))
+ re)
+ (swiper--normalize-regex re))))
(defvar swiper-history nil
"History for `swiper'.")
- [elpa] externals/ivy-hydra bba92e0 188/395: counsel.el (counsel-file-name-filter-alist): Modify perl entry, (continued)
- [elpa] externals/ivy-hydra bba92e0 188/395: counsel.el (counsel-file-name-filter-alist): Modify perl entry, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 64f05f4 189/395: swiper.el (swiper-font-lock-exclude): Add sieve-mode, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 6f04865 185/395: ivy.el (ivy-init-fns-alist): Add, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 1b426e1 202/395: Fix byte-compilation warning in Emacs 28, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra f9fa30d 211/395: More compatibility fixes, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 48e56da 305/395: Extend :type of counsel-async-command-delay, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 0eebf24 318/395: ivy.el (ivy--partial-cd-for-single-directory): Fix for ignore-order, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra edefba7 304/395: ivy-test.el (ivy-read-alist-multi-cands): Add test, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra aa47396 218/395: counsel.el (counsel-fonts): Preselect the current font, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 2bf7317 235/395: ivy.el: ivy--index should never be nil, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 33fa992 250/395: Fix swiper handling of bol regex,
Basil L. Contovounesios <=
- [elpa] externals/ivy-hydra 6ab24b6 249/395: * ivy.el: Use with-eval-after-load, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra ffa5a5f 258/395: counsel-describe-symbol: autoload, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 71f5727 261/395: counsel.el (counsel--git-grep-index): Don't error on null buffer-file-name, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 84efa3a 262/395: Ensure counsel--git-grep-index returns non-nil, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 6eda8fa 254/395: Fix recent ivy-auto-shrink-minibuffer-alist typo, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra b40af52 267/395: counsel.el (counsel-find-file-undo): Remap undo, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra fc3252b 274/395: Don't insert ^ on aborting completion in region, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra a4a22e0 294/395: ivy.el (ivy-display-style): Remove, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra ee747e6 290/395: ivy.el (ivy--update-history): Use ivy-state-current for file names, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra f67a2bb 215/395: ivy.el (ivy--filter): Prioritize :matcher, Basil L. Contovounesios, 2021/02/25