[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 4f1bbc1 151/399: swiper.el (swiper-isearch-function): Full
From: |
Oleh Krehel |
Subject: |
[elpa] master 4f1bbc1 151/399: swiper.el (swiper-isearch-function): Full point history for DEL |
Date: |
Sat, 20 Jul 2019 14:57:13 -0400 (EDT) |
branch: master
commit 4f1bbc177a871eaab2edc4d701ef8f63d2715cb4
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
swiper.el (swiper-isearch-function): Full point history for DEL
* swiper.el (swiper--isearch-point-history): Store point positions for
all previous states of the input. This way, if the input is restored
to an older state with "DEL", the point will also be restored.
* ivy-test.el (swiper-isearch): Add test, making sure the behavior is
the same as that of `isearch-forward-regexp'.
---
ivy-test.el | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
swiper.el | 30 ++++++++++++++++++++----------
2 files changed, 70 insertions(+), 10 deletions(-)
diff --git a/ivy-test.el b/ivy-test.el
index 4579894..4a24366 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -1003,6 +1003,56 @@ a buffer visiting a file."
(counsel--grep-regex "ivy"))
"(i)[^v\n]*(v)[^y\n]*(y)")))
+(defmacro ivy-with-text (text &rest body)
+ (let ((old-bindings
+ (delq nil (mapcar
+ (lambda (x)
+ (when (and (listp x)
+ (eq (car x) 'global-set-key))
+ (let ((key (eval (cadr x))))
+ (list key (lookup-key global-map key)))))
+ body))))
+ `(let ((temp-buffer (generate-new-buffer " *temp*")))
+ (save-window-excursion
+ (unwind-protect
+ (progn
+ (switch-to-buffer temp-buffer)
+ (insert ,text)
+ (search-backward "|")
+ (delete-char 1)
+ (setq current-prefix-arg nil)
+ ,@(mapcar (lambda (x)
+ (if (and (listp x)
+ (stringp (car x)))
+ `(execute-kbd-macro
+ (vconcat ,@(mapcar #'kbd x)))
+ x))
+ body)
+ (insert "|")
+ (buffer-substring-no-properties
+ (point-min)
+ (point-max)))
+ (dolist (old-binding ',old-bindings)
+ (apply #'global-set-key old-binding))
+ (and (buffer-name temp-buffer)
+ (kill-buffer temp-buffer)))))))
+
+(ert-deftest swiper-isearch ()
+ (should
+ (string=
+ (ivy-with-text
+ "abc\na|sdf123 def\ndem"
+ (global-set-key (kbd "C-s") #'isearch-forward-regexp)
+ ("C-s" "de" "" "RET"))
+ "abc\nasd|f123 def\ndem"))
+ (should
+ (string=
+ (ivy-with-text
+ "abc\na|sdf123 def\ndem"
+ (global-set-key (kbd "C-s") #'swiper-isearch)
+ ("C-s" "de" "" "RET"))
+ "abc\nasd|f123 def\ndem")))
+
(provide 'ivy-test)
;;; ivy-test.el ends here
diff --git a/swiper.el b/swiper.el
index 960010d..60a8d37 100644
--- a/swiper.el
+++ b/swiper.el
@@ -1132,24 +1132,32 @@ See `ivy-format-function' for further information."
res))
;;* `swiper-isearch'
-(defvar swiper--isearch-last-point nil)
+(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'."
(unless (string= str "")
- (let ((re-full (funcall ivy--regex-function str))
- re
- cands
- idx-found
- (idx 0))
- (setq re (ivy-re-to-str re-full))
+ (let* ((re-full (funcall ivy--regex-function str))
+ (re (ivy-re-to-str re-full))
+ (pt-hist (cdr (assoc str swiper--isearch-point-history)))
+ cands
+ idx-found
+ (idx 0))
(with-ivy-window
(save-excursion
(goto-char (point-min))
(while (re-search-forward re nil t)
(unless idx-found
- (when (>= (match-beginning 0) swiper--isearch-last-point)
- (setq swiper--isearch-last-point (match-beginning 0))
+ (when (or
+ (eq (match-beginning 0) pt-hist)
+ (>= (match-beginning 0) (cdar
swiper--isearch-point-history)))
+ (push (cons str (match-beginning 0))
swiper--isearch-point-history)
(setq idx-found idx)))
(cl-incf idx)
(let ((line (buffer-substring
@@ -1186,7 +1194,9 @@ See `ivy-format-function' for further information."
"A `swiper' that's not line-based."
(interactive)
(swiper--init)
- (setq swiper--isearch-last-point (line-beginning-position))
+ (setq swiper--isearch-point-history
+ (list
+ (cons "" (line-beginning-position))))
(let ((ivy-fixed-height-minibuffer t)
(cursor-in-non-selected-windows nil)
(swiper-min-highlight 1)
- [elpa] master fef96f4 139/399: counsel.el (counsel--find-file-1): Extract, (continued)
- [elpa] master fef96f4 139/399: counsel.el (counsel--find-file-1): Extract, Oleh Krehel, 2019/07/20
- [elpa] master 3b40e99 142/399: swiper.el (swiper-isearch-action): Fix fake cursor at eol, Oleh Krehel, 2019/07/20
- [elpa] master eaba38a 145/399: counsel.el (counsel-dired-jump-args): Fix for OSX, Oleh Krehel, 2019/07/20
- [elpa] master 7c9d960 143/399: swiper.el (swiper--add-cursor-overlay): Extract, Oleh Krehel, 2019/07/20
- [elpa] master 9988904 150/399: counsel.el (counsel--switch-buffer-update-fn): Fix for when find-file fails, Oleh Krehel, 2019/07/20
- [elpa] master 05a4e59 147/399: Do not use invalid :preselect as a regexp, Oleh Krehel, 2019/07/20
- [elpa] master 3ab3d5f 152/399: swiper.el (swiper-isearch): Check executing-kbd-macro, Oleh Krehel, 2019/07/20
- [elpa] master 302d23f 149/399: counsel.el: Fix org-version testing, Oleh Krehel, 2019/07/20
- [elpa] master cd41f70 153/399: ivy-test.el: Add inhibit-message, Oleh Krehel, 2019/07/20
- [elpa] master 1df4ccf 154/399: ivy.el (ivy-occur-revert-buffer): Add swiper-isearch, Oleh Krehel, 2019/07/20
- [elpa] master 4f1bbc1 151/399: swiper.el (swiper-isearch-function): Full point history for DEL,
Oleh Krehel <=
- [elpa] master 0bf94f8 156/399: ivy.el (ivy--occur-press-update-window): Add swiper-isearch, Oleh Krehel, 2019/07/20
- [elpa] master 0d2ab52 157/399: swiper.el (swiper--isearch-occur-cands): Faster version, Oleh Krehel, 2019/07/20
- [elpa] master 1bf56c3 165/399: swiper.el (swiper--query-replace-setup): Fix for ivy--regex-ignore-order, Oleh Krehel, 2019/07/20
- [elpa] master 4492054 167/399: ivy.el (ivy--recompute-index): Speed up, Oleh Krehel, 2019/07/20
- [elpa] master 11b0007 158/399: swiper.el (swiper--action): Simplify, Oleh Krehel, 2019/07/20
- [elpa] master 1ebbb5f 136/399: swiper.el (swiper-isearch): Set swiper-min-highlight to 1, Oleh Krehel, 2019/07/20
- [elpa] master b34bf45 140/399: counsel.el (counsel-dired): Add, Oleh Krehel, 2019/07/20
- [elpa] master 1e38ed4 146/399: counsel.el (counsel-minor): Add command to toggle minor mode, Oleh Krehel, 2019/07/20
- [elpa] master 2098d27 148/399: swiper.el: Set up occur for swiper-isearch, Oleh Krehel, 2019/07/20
- [elpa] master dceecd8 155/399: swiper.el (swiper-occur): Adapt to swiper-isearch, Oleh Krehel, 2019/07/20