Skip to content

Commit

Permalink
reimplement as a minor-mode.
Browse files Browse the repository at this point in the history
resolves #3.
  • Loading branch information
bling committed Dec 23, 2014
1 parent 253e8a5 commit de939b4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ This is a port of one of the many visual-star plugins for Vim to work with [evil
installation
============

Add `evil-visualstar.el` to the `load-path` and `(require 'evil-visualstar)`.
Install `evil-visualstar` from [MELPA][1].

usage
=====

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.

[1]: http://melpa.org
33 changes: 27 additions & 6 deletions evil-visualstar.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;; Filename: evil-visualstar.el
;; Description: Starts a * or # search from the visual selection
;; Created: 2013-09-24
;; Version: 0.0.1
;; Version: 0.1.0
;; Keywords: evil vim visualstar
;; Package-Requires: ((evil "0"))
;;
Expand Down Expand Up @@ -36,14 +36,15 @@
;;
;; Usage:
;;
;; (global-evil-visualstar-mode t)
;;
;; Make a visual selection with `v` or `V`, and then hit `*` to search
;; the selection forward, or # to search that selection backward.

;;; Code:

(require 'evil)

;;;###autoload
(defun evil-visualstar/begin-search (beg end direction)
(when (evil-visual-state-p)
(evil-exit-visual-state)
Expand All @@ -59,20 +60,40 @@
(evil-ex-search-activate-highlight pattern)
(evil-ex-search-next))))))

;;;###autoload
(defun evil-visualstar/begin-search-forward (beg end)
"Search for the visual selection forwards."
(interactive "r")
(evil-visualstar/begin-search beg end t))

;;;###autoload
(defun evil-visualstar/begin-search-backward (beg end)
"Search for the visual selection backwards."
(interactive "r")
(evil-visualstar/begin-search beg end nil))

(define-key evil-visual-state-map (kbd "*") 'evil-visualstar/begin-search-forward)
(define-key evil-visual-state-map (kbd "#") 'evil-visualstar/begin-search-backward)
;;;###autoload
(define-minor-mode evil-visualstar-mode
"Minor mode for visual star selection."
:keymap (let ((map (make-sparse-keymap)))
(evil-define-key 'visual map (kbd "*") #'evil-visualstar/begin-search-forward)
(evil-define-key 'visual map (kbd "#") #'evil-visualstar/begin-search-backward)
map)
(evil-normalize-keymaps))

;;;###autoload
(define-globalized-minor-mode global-evil-visualstar-mode
evil-visualstar-mode turn-on-evil-visualstar-mode)

;;;###autoload
(defun turn-on-evil-visualstar-mode ()
"Turns on visual star selection."
(interactive)
(evil-visualstar-mode t))

;;;###autoload
(defun turn-off-evil-visualstar-mode ()
"Turns off visual star selection."
(interactive)
(evil-visualstar-mode -1))

(provide 'evil-visualstar)
;;; evil-visualstar.el ends here

0 comments on commit de939b4

Please sign in to comment.