branch: elpa/evil-visualstar
commit 3f9bb0e6a169242b76519e0fcd28e2ac9d5352a8
Merge: 6e9f2349ad a18dfe7612
Author: Guido Van Hoecke <[email protected]>
Commit: Guido Van Hoecke <[email protected]>
Allow for option controlled persistent visualstar searches
---
README.md | 6 ++++++
evil-visualstar.el | 16 ++++++++++++----
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 0c0fe6c97a..6cb854549e 100644
--- a/README.md
+++ b/README.md
@@ -15,4 +15,10 @@ Add `(global-evil-visualstar-mode)` to your configuration.
Make a visual selection with `v` or `V`, and then hit `*` to search that
selection forward, or `#` to search that selection backward.
+If the `evil-visualstar/persistent` option is not nil, visual-state will
+remain in effect, allowing for repeated `*` or #`.
+
+Note that you than have to exit visualstar-mode before hitting a
+direction key to avoid extending the selection.
+
[1]: http://melpa.org
diff --git a/evil-visualstar.el b/evil-visualstar.el
index df596b41d3..3aa9568f85 100644
--- a/evil-visualstar.el
+++ b/evil-visualstar.el
@@ -45,6 +45,11 @@
(require 'evil)
+(defvar evil-visualstar/persistent nil
+ "Set to t if * or # should keep visual-mode.
+This allows for repeated use of * in # but keeps vusual mode.
+You'd need to hit escape to leave visual-mode.")
+
(defun evil-visualstar/begin-search (beg end direction)
(when (evil-visual-state-p)
(evil-exit-visual-state)
@@ -59,11 +64,14 @@
(setq evil-ex-search-direction direction)
(setq evil-ex-search-pattern pattern)
(evil-ex-search-activate-highlight pattern)
+ ;; update search history unless this pattern equals the
+ ;; previous pattern
+ (unless (equal (car-safe evil-ex-search-history) selection)
+ (push selection evil-ex-search-history))
+ (evil-push-search-history selection (eq direction 'forward))
(setq found (evil-ex-search-next))))
- (when found
- (push-mark (- (+ end (point)) beg) t)
- (exchange-point-and-mark)
- (exchange-point-and-mark)))))
+ (when (and evil-visualstar/persistent found)
+ (push-mark (+ (point) (- end beg)) nil t)))))
(defun evil-visualstar/begin-search-forward (beg end)
"Search for the visual selection forwards."