[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 5b3676f 095/110: avy.el (avy-next): New command to go to t
From: |
Oleh Krehel |
Subject: |
[elpa] master 5b3676f 095/110: avy.el (avy-next): New command to go to the next candidate after avy-read |
Date: |
Sat, 11 May 2019 10:15:52 -0400 (EDT) |
branch: master
commit 5b3676f1a4212b43de33e8c7a8f3a2de933068c7
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
avy.el (avy-next): New command to go to the next candidate after avy-read
Example config:
(defhydra hydra-avy-cycle ()
("j" avy-next "next")
("k" avy-prev "prev")
("q" nil "quit"))
(global-set-key (kbd "C-M-'") 'hydra-avy-cycle/body)
After e.g. `avy-goto-char' or `avy-goto-char-timer', use the above
hydra to cycle between the last candidates.
Fixes #254
---
avy.el | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/avy.el b/avy.el
index 560401a..7d949ea 100644
--- a/avy.el
+++ b/avy.el
@@ -787,6 +787,40 @@ Set `avy-style' according to COMMMAND as well."
#'avy--remove-leading-chars))))
(avy--done))))))
+(defvar avy-last-candidates nil
+ "Store the last candidate list.")
+
+(defun avy--last-candidates-cycle (advancer)
+ (let* ((avy-last-candidates
+ (cl-remove-if-not
+ (lambda (x) (equal (cdr x) (selected-window)))
+ avy-last-candidates))
+ (min-dist
+ (apply #'min
+ (mapcar (lambda (x) (abs (- (caar x) (point))))
avy-last-candidates)))
+ (pos
+ (cl-position-if
+ (lambda (x)
+ (= (- (caar x) (point)) min-dist))
+ avy-last-candidates)))
+ (funcall advancer pos avy-last-candidates)))
+
+(defun avy-prev ()
+ "Go to the previous candidate of the last `avy-read'."
+ (interactive)
+ (avy--last-candidates-cycle
+ (lambda (pos lst)
+ (when (> pos 0)
+ (goto-char (caar (nth (1- pos) lst)))))))
+
+(defun avy-next ()
+ "Go to the next candidate of the last `avy-read'."
+ (interactive)
+ (avy--last-candidates-cycle
+ (lambda (pos lst)
+ (when (< pos (1- (length lst)))
+ (goto-char (caar (nth (1+ pos) lst)))))))
+
(defun avy--process (candidates &optional overlay-fn)
"Select one of CANDIDATES using `avy-read'.
Use OVERLAY-FN to visualize the decision overlay."
@@ -796,6 +830,7 @@ Use OVERLAY-FN to visualize the decision overlay."
(setq candidates
(mapcar (lambda (x) (cons x (selected-window)))
candidates)))
+ (setq avy-last-candidates (copy-sequence candidates))
(let ((original-cands (copy-sequence candidates))
(res (avy--process-1 candidates overlay-fn)))
(cond
- [elpa] master updated (1744d5a -> 4acafa6), Oleh Krehel, 2019/05/11
- [elpa] master 4acafa6 110/110: Merge commit '0e59474430cbfbe7caf2a41cf7935fc613648c49' from avy, Oleh Krehel, 2019/05/11
- [elpa] master b408f76 108/110: doc/Changelog.org: quote issues, Oleh Krehel, 2019/05/11
- [elpa] master f2cf43b 107/110: doc/Changelog.org: Release 0.5.0, Oleh Krehel, 2019/05/11
- [elpa] master 0e59474 109/110: avy.el (avy--read-candidates): Fix docstring, Oleh Krehel, 2019/05/11
- [elpa] master 85b5d57 104/110: avy.el (avy-jump): Add predicate argument, Oleh Krehel, 2019/05/11
- [elpa] master 152b07f 102/110: avy.el (avy-process): Return res, Oleh Krehel, 2019/05/11
- [elpa] master a723090 106/110: avy.el (avy--overlay-at-full): More consistent face order, Oleh Krehel, 2019/05/11
- [elpa] master 5b3676f 095/110: avy.el (avy-next): New command to go to the next candidate after avy-read,
Oleh Krehel <=
- [elpa] master 4d52b5c 105/110: avy.el (avy--line-cands): Allow "invisible" 'org-link, Oleh Krehel, 2019/05/11
- [elpa] master e9f4d85 092/110: avy.el (avy-goto-char-timer): Obey avy-background for initial search, Oleh Krehel, 2019/05/11
- [elpa] master 9124022 097/110: avy.el (avy--generic-jump): Update docstring about removed arg, Oleh Krehel, 2019/05/11
- [elpa] master b19a23a 096/110: avy.el (avy--visible-p): buffer-invisibility-spec can be t, Oleh Krehel, 2019/05/11
- [elpa] master 118a3d6 093/110: Update readme.md: add melpa badges, Oleh Krehel, 2019/05/11
- [elpa] master 9a15d1f 103/110: avy.el (avy-show-dispatch-help): Add and bind to "?", Oleh Krehel, 2019/05/11
- [elpa] master 74501e1 094/110: avy.el: More fixes to org-toggle-link-display, Oleh Krehel, 2019/05/11
- [elpa] master 8db2759 099/110: Change avy--process to accept cleanup function, Oleh Krehel, 2019/05/11
- [elpa] master 7d73cee 100/110: avy.el: Use avy-process instead of avy--process, Oleh Krehel, 2019/05/11
- [elpa] master fd0101e 101/110: avy.el (avy-push-mark): Turn off message, Oleh Krehel, 2019/05/11