branch: master
commit c87949847d045d22da8ebb782c082212af975fe8
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
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
---
avy.el | 27 +++++++++++++++++++++++----
1 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/avy.el b/avy.el
index 756a62e..28a07f4 100644
--- a/avy.el
+++ b/avy.el
@@ -951,15 +951,16 @@ Which one depends on variable `subword-mode'."
(defvar visual-line-mode)
-(defun avy--line (&optional arg)
+(defun avy--line (&optional arg beg end)
"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)
(avy-dowindows arg
- (let ((ws (window-start)))
+ (let ((ws (or beg (window-start))))
(save-excursion
(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))
(while (< (point) (point-max))
(unless (get-char-property
@@ -1010,6 +1011,24 @@ Otherwise, forward to `goto-line' with ARG."
(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
(defun avy-copy-line (arg)
"Copy a selected line above the current line.
ARG lines can be used."