[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 2a036b8 002/184: swiper.el (swiper--isearch-function): Cha
From: |
Oleh Krehel |
Subject: |
[elpa] master 2a036b8 002/184: swiper.el (swiper--isearch-function): Change. |
Date: |
Wed, 16 Oct 2019 13:14:38 -0400 (EDT) |
branch: master
commit 2a036b8a42633a8f7de7bb3b3db13a5f06867b32
Author: Brian Leung <address@hidden>
Commit: Brian Leung <address@hidden>
swiper.el (swiper--isearch-function): Change.
Having point before the last "o" in "dodo", as in "dod|o", should hop
to the beginning of the string upon entering "do" as the regexp. This
is because when searching backward, the (match-end) of the match to
which we hop should not cross the starting point of the search. When
changing the search string from "do" to "do?", we hop back to the
second occurrence of "do", since "do?" can match the second "d" taken
in isolation.
---
ivy-test.el | 32 ++++++++++++++++----------------
swiper.el | 33 +++++++++++++--------------------
2 files changed, 29 insertions(+), 36 deletions(-)
diff --git a/ivy-test.el b/ivy-test.el
index 386fe9c..0d53b07 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -1129,24 +1129,12 @@ a buffer visiting a file."
(global-set-key (kbd "C-r") #'isearch-backward-regexp)
("C-r" "defun\\|defvar" "RET"))
"(defun foo)\nasdf\n(|defvar bar)"))
- ;; NOTE: The following two behaviors do not match
- ;; `isearch-backward-regexp', but they match that of
- ;; `swiper-isearch-forward', as `swiper-isearch' does not reset the
- ;; point when the regexp becomes invalid, meaning the point is left
- ;; at the initial match of the first part of the regexp.
(should
(string=
(ivy-with-text
"(defun foo)\nasdf\n(defvar bar)|"
(global-set-key (kbd "C-r") #'swiper-isearch-backward)
("C-r" "defun\\|defvar" "RET"))
- "(|defun foo)\nasdf\n(defvar bar)"))
- (should
- (string=
- (ivy-with-text
- "(defun foo)\nasdf\n(defvar bar)|"
- (global-set-key (kbd "C-r") #'swiper-isearch-backward)
- ("C-r" "defun\\|defvar" "C-n RET"))
"(defun foo)\nasdf\n(|defvar bar)"))
(should
(string=
@@ -1161,7 +1149,21 @@ a buffer visiting a file."
"(defun foo)\nasdf\n(|defun bar)"
(global-set-key (kbd "C-r") #'swiper-isearch-backward)
("C-r" "defun" "RET"))
- "(|defun foo)\nasdf\n(defun bar)")))
+ "(|defun foo)\nasdf\n(defun bar)"))
+ (should
+ (string=
+ (ivy-with-text
+ "(defun foo)\nasdf\n(de|fun bar)"
+ (global-set-key (kbd "C-r") #'swiper-isearch-backward)
+ ("C-r" "def" "RET"))
+ "(|defun foo)\nasdf\n(defun bar)"))
+ (should
+ (string=
+ (ivy-with-text
+ "(defun foo)\nasdf\n(de|fun bar)"
+ (global-set-key (kbd "C-r") #'swiper-isearch-backward)
+ ("C-r" "def?" "RET"))
+ "(defun foo)\nasdf\n(|defun bar)")))
(ert-deftest swiper-isearch-backward-backspace ()
(should
@@ -1205,9 +1207,7 @@ a buffer visiting a file."
"Foo\nfoo|\nFOO\n")))
(ert-deftest swiper--isearch-format ()
- (setq swiper--isearch-point-history
- (list
- (cons "" 1)))
+ (setq swiper--isearch-start-point 0)
(with-temp-buffer
(insert
"line0\nline1\nline line\nline line\nline5")
diff --git a/swiper.el b/swiper.el
index 500ac18..7eeefcf 100644
--- a/swiper.el
+++ b/swiper.el
@@ -1285,14 +1285,6 @@ See `ivy-format-functions-alist' for further
information."
res))
;;* `swiper-isearch'
-(defvar swiper--isearch-point-history nil
- "Store the current input and point history for a single search.
-Each element is a cons cell of an input and a point position that
-corresponds to it.
-
-This ensures that if the user enters \"ab\", the point will
-come back to the same place as when \"a\" was initially entered.")
-
(defun swiper-isearch-function (str)
"Collect STR matches in the current buffer for `swiper-isearch'."
(with-ivy-window
@@ -1306,6 +1298,7 @@ come back to the same place as when \"a\" was initially
entered.")
(overlays-at (point))))))
(defvar swiper--isearch-backward nil)
+(defvar swiper--isearch-start-point nil)
(defun swiper--isearch-function (str)
(let* ((case-fold-search (ivy--case-fold-p str))
@@ -1315,7 +1308,6 @@ come back to the same place as when \"a\" was initially
entered.")
(let ((re (if (string-match "\\`\\(.*\\)[\\]|\\'" re)
(match-string 1 re)
re))
- (pt-hist (cdr (assoc str swiper--isearch-point-history)))
cands
idx-found
(idx 0))
@@ -1324,12 +1316,17 @@ come back to the same place as when \"a\" was initially
entered.")
(while (funcall (if swiper--isearch-backward #'re-search-backward
#'re-search-forward) re nil t)
(when (swiper-match-usable-p)
(unless idx-found
- (when (or
- (eq (match-beginning 0) pt-hist)
- (if swiper--isearch-backward
- (<= (match-beginning 0) (cdar
swiper--isearch-point-history))
- (>= (match-beginning 0) (cdar
swiper--isearch-point-history))))
- (push (cons str (match-beginning 0))
swiper--isearch-point-history)
+ (when (if swiper--isearch-backward
+ (or (<= (match-end 0) swiper--isearch-start-point)
+ (and (< (match-beginning 0)
swiper--isearch-start-point)
+ (let ((mb-match
+ (string-match-p
+ re
+ (buffer-substring-no-properties
+ (match-beginning 0)
+ swiper--isearch-start-point))))
+ (eq mb-match 0))))
+ (>= (match-beginning 0) swiper--isearch-start-point))
(setq idx-found idx)))
(cl-incf idx)
(let ((pos (if (or swiper--isearch-backward
swiper-goto-start-of-match)
@@ -1399,8 +1396,6 @@ When not running `swiper-isearch' already, start it."
(deactivate-mark))
(bounds-of-thing-at-point 'symbol)))
(setq str (buffer-substring-no-properties (car bnd) (cdr bnd))))
- (setq swiper--isearch-point-history
- (list (cons "" (car bnd))))
(insert str)
(unless regionp
(ivy--insert-symbol-boundaries)))
@@ -1519,12 +1514,10 @@ When not running `swiper-isearch' already, start it."
(interactive)
(swiper--init)
(swiper-font-lock-ensure)
- (setq swiper--isearch-point-history
- (list
- (cons "" (- (point) (if swiper--isearch-backward 1 0)))))
(let ((ivy-fixed-height-minibuffer t)
(cursor-in-non-selected-windows nil)
(swiper-min-highlight 1)
+ (swiper--isearch-start-point (point))
res)
(unwind-protect
(and
- [elpa] master updated (22e3e88 -> c2d3a4c), Oleh Krehel, 2019/10/16
- [elpa] master 196b4ea 001/184: doc/Makefile: Add target to install the info pages, Oleh Krehel, 2019/10/16
- [elpa] master 0a9fb0c 009/184: swiper.el (swiper--isearch-function): Refactor, Oleh Krehel, 2019/10/16
- [elpa] master f0ec850 005/184: swiper.el (swiper-isearch): Fix for ivy-resume, Oleh Krehel, 2019/10/16
- [elpa] master 2a036b8 002/184: swiper.el (swiper--isearch-function): Change.,
Oleh Krehel <=
- [elpa] master ad0f605 008/184: swiper.el (swiper--isearch-function-1): Extract, Oleh Krehel, 2019/10/16
- [elpa] master dc7f5e0 012/184: swiper.el (swiper--isearch-function): Works for ivy--regex-ignore-order, Oleh Krehel, 2019/10/16
- [elpa] master 50ead7e 013/184: ivy-test.el (swiper-thing-at-point): Add and fix test, Oleh Krehel, 2019/10/16
- [elpa] master ec3e062 034/184: counsel (counsel-file-jump): Use temp buffer instead of split-string, Oleh Krehel, 2019/10/16
- [elpa] master 13be8ab 004/184: ivy.el (ivy--reset-state): Fix ivy-resume, Oleh Krehel, 2019/10/16
- [elpa] master 039353d 007/184: ivy.el (ivy--preselect-index): Fix ivy-resume for swiper-isearch, Oleh Krehel, 2019/10/16
- [elpa] master c7ffd06 016/184: swiper.el (swiper-isearch-action): Make ivy-previous-line-or-history work, Oleh Krehel, 2019/10/16
- [elpa] master b4c4a7f 011/184: swiper.el (swiper--isearch-next-item): Extract, Oleh Krehel, 2019/10/16
- [elpa] master b9f3e3b 017/184: swiper.el (swiper-isearch-action): Simplify, Oleh Krehel, 2019/10/16
- [elpa] master 38b5d83 015/184: swiper.el (swiper--isearch-filter-ignore-order): Extract, Oleh Krehel, 2019/10/16