New commands avy-goto-line-above and avy-goto-line-below

* avy.el (avy--line): Add BEG, END optional args.
(avy-goto-line-above): New command.
(avy-goto-line-below): New command.

Fixes #106
This commit is contained in:
Oleh Krehel 2015-10-19 11:57:47 +02:00
parent 248bff08bb
commit c87949847d

27
avy.el
View File

@ -951,15 +951,16 @@ Which one depends on variable `subword-mode'."
(defvar visual-line-mode) (defvar visual-line-mode)
(defun avy--line (&optional arg) (defun avy--line (&optional arg beg end)
"Select a line. "Select a line.
The window scope is determined by `avy-all-windows' (ARG negates it)." The window scope is determined by `avy-all-windows' (ARG negates it).
Narrow the scope to BEG END."
(let (candidates) (let (candidates)
(avy-dowindows arg (avy-dowindows arg
(let ((ws (window-start))) (let ((ws (or beg (window-start))))
(save-excursion (save-excursion
(save-restriction (save-restriction
(narrow-to-region ws (window-end (selected-window) t)) (narrow-to-region ws (or end (window-end (selected-window) t)))
(goto-char (point-min)) (goto-char (point-min))
(while (< (point) (point-max)) (while (< (point) (point-max))
(unless (get-char-property (unless (get-char-property
@ -1009,6 +1010,24 @@ Otherwise, forward to `goto-line' with ARG."
(unless (eq r t) (unless (eq r t)
(avy-action-goto r)))))) (avy-action-goto r))))))
;;;###autoload
(defun avy-goto-line-above ()
"Goto visible line above the cursor."
(interactive)
(let ((r (avy--line nil (window-start) (point))))
(unless (eq r t)
(avy-action-goto r))))
;;;###autoload
(defun avy-goto-line-below ()
"Goto visible line below the cursor."
(interactive)
(let ((r (avy--line
nil (point)
(window-end (selected-window) t))))
(unless (eq r t)
(avy-action-goto r))))
;;;###autoload ;;;###autoload
(defun avy-copy-line (arg) (defun avy-copy-line (arg)
"Copy a selected line above the current line. "Copy a selected line above the current line.