[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ivy-explorer 6481247 08/29: Refactor ivy-explorer-avy
From: |
Clemens Radermacher |
Subject: |
[elpa] externals/ivy-explorer 6481247 08/29: Refactor ivy-explorer-avy |
Date: |
Tue, 12 Mar 2019 09:04:35 -0400 (EDT) |
branch: externals/ivy-explorer
commit 6481247374880b979ebf1761c0d10edb59e941c4
Author: Clemens Radermacher <address@hidden>
Commit: Clemens Radermacher <address@hidden>
Refactor ivy-explorer-avy
---
ivy-explorer.el | 127 +++++++++++++++++++++++++++++++++-----------------------
1 file changed, 75 insertions(+), 52 deletions(-)
diff --git a/ivy-explorer.el b/ivy-explorer.el
index 3b001d3..1441929 100644
--- a/ivy-explorer.el
+++ b/ivy-explorer.el
@@ -290,6 +290,78 @@ menu string as `cdr'."
(if (characterp char) (string char) char))
(throw 'done 'restart))))))
+(defvar ivy-explorer-avy-handler-alist
+ (list (cons #'ivy-explorer--lv-message
+ #'ivy-explorer-avy-default-handler)))
+
+(defun ivy-explorer--avy ()
+ (let* ((avy-all-windows nil)
+ (avy-keys (or (cdr (assq 'ivy-avy avy-keys-alist))
+ avy-keys))
+ (avy-handler-function #'ivy-explorer--ace-handler)
+ (avy-pre-action #'ignore)
+ (avy-style (or (cdr (assq 'ivy-avy
+ avy-styles-alist))
+ avy-style))
+ (avy-action #'identity)
+ (handler (cdr (assq ivy-explorer-message-function
+ ivy-explorer-avy-handler-alist)))
+ (success (if handler (funcall handler)
+ (user-error "No handler for %s found in
`ivy-explorer-avy-handler-alist'"
+ ivy-explorer-message-function))))
+ success))
+
+(defun ivy-explorer-avy-default-handler ()
+ (let* ((w (ivy-explorer--lv))
+ (b (window-buffer w)))
+ (with-selected-window w
+ (ivy-explorer--avy-1 b))))
+
+(defun ivy-explorer--avy-1 (&optional buffer)
+ (let ((candidate (avy--process
+ (ivy-explorer--parse-avy-buffer buffer)
+ (avy--style-fn avy-style))))
+ (when (number-or-marker-p candidate)
+ (prog1 t
+ (ivy-set-index
+ (get-text-property candidate 'ivy-explorer-count))))))
+
+
+(defun ivy-explorer--parse-avy-buffer (&optional buffer)
+ (let ((count 0)
+ (candidates ()))
+ (with-current-buffer (or buffer (current-buffer))
+ (save-excursion
+ (goto-char (point-min))
+ ;; ignore the first candidate if at ./
+ ;; this command is meant to be used for navigation
+ ;; navigate to same folder you are in makes no sense
+ (unless (looking-at "./")
+ (push (cons (point)
+ (selected-window))
+ candidates)
+ (put-text-property
+ (point) (1+ (point)) 'ivy-explorer-count count))
+ (goto-char
+ (or (next-single-property-change
+ (point) 'mouse-face)
+ (point-max)))
+ (while (< (point) (point-max))
+ (unless (looking-at "[[:blank:]\r\n]\\|\\'")
+ (cl-incf count)
+ (put-text-property
+ (point) (1+ (point)) 'ivy-explorer-count count)
+ (push
+ (cons (point)
+ (selected-window))
+ candidates))
+ (goto-char
+ (or (next-single-property-change
+ (point)
+ 'mouse-face)
+ (point-max))))))
+ (nreverse candidates)))
+
;; Ivy explorer avy, adapted from ivy-avy
(defun ivy-explorer-avy (&optional action)
@@ -302,64 +374,15 @@ style with C-g.
If called from code ACTION is the action to trigger afterwards,
in this case `avy' is not invoked again."
(interactive)
- (when (with-selected-window (ivy-explorer--lv)
- (unless (require 'avy nil 'noerror)
- (error "Package avy isn't installed"))
- (let* ((avy-all-windows nil)
- (avy-keys (or (cdr (assq 'ivy-avy avy-keys-alist))
- avy-keys))
- (avy-handler-function #'ivy-explorer--ace-handler)
- (avy-style (or (cdr (assq 'ivy-avy
- avy-styles-alist))
- avy-style))
- (count 0)
- (candidate
- (let ((candidates))
- (save-excursion
- (goto-char (point-min))
- ;; ignore the first candidate if at ./
- ;; this command is meant to be used for navigation
- ;; navigate to same folder you are in makes no sense
- (unless (looking-at "./")
- (push (cons (point)
- (selected-window))
- candidates)
- (put-text-property
- (point) (1+ (point)) 'ivy-explorer-count count))
- (goto-char
- (or (next-single-property-change
- (point) 'mouse-face)
- (point-max)))
- (while (< (point) (point-max))
- (unless (looking-at "[[:blank:]\r\n]\\|\\'")
- (cl-incf count)
- (put-text-property
- (point) (1+ (point)) 'ivy-explorer-count count)
- (push
- (cons (point)
- (selected-window))
- candidates))
- (goto-char
- (or (next-single-property-change
- (point)
- 'mouse-face)
- (point-max)))))
- (setq avy-action #'identity)
- (avy--process
- (nreverse candidates)
- (avy--style-fn avy-style)))))
- (when (number-or-marker-p candidate)
- (prog1 candidate
- (ivy-set-index
- (get-text-property candidate 'ivy-explorer-count))))))
+ (unless (require 'avy nil 'noerror)
+ (error "Package avy isn't installed"))
+ (when (ivy-explorer--avy)
(ivy--exhibit)
(funcall (or action #'ivy-alt-done))
(unless action
(ivy-explorer-avy))))
;; adapted from ivy-hydra
-
-
(defun ivy-explorer-avy-dispatching-done-hydra ()
"Choose action and afterwards target using `hydra'."
(interactive)
- [elpa] externals/ivy-explorer 4a48ec4 17/29: Add posframe screenshot, (continued)
- [elpa] externals/ivy-explorer 4a48ec4 17/29: Add posframe screenshot, Clemens Radermacher, 2019/03/12
- [elpa] externals/ivy-explorer bc207da 10/29: Add basic posframe support for #7, Clemens Radermacher, 2019/03/12
- [elpa] externals/ivy-explorer f9e3b7a 07/29: Add auto-init-avy option, and improve avy exit behaviour, Clemens Radermacher, 2019/03/12
- [elpa] externals/ivy-explorer 9af0805 27/29: Improve ivy-explorer-read function again, Clemens Radermacher, 2019/03/12
- [elpa] externals/ivy-explorer e4bb026 26/29: Allow specifying height of grid display, Clemens Radermacher, 2019/03/12
- [elpa] externals/ivy-explorer 5fb5512 20/29: Only parse visible window part for avy selection with posframe, Clemens Radermacher, 2019/03/12
- [elpa] externals/ivy-explorer 6245f34 28/29: Change some frame paramaters for better posframe display, Clemens Radermacher, 2019/03/12
- [elpa] externals/ivy-explorer 72a511e 21/29: Don't keep avy on after first use, Clemens Radermacher, 2019/03/12
- [elpa] externals/ivy-explorer 384e241 18/29: Use ivy posframe dispatching done when using posframe, Clemens Radermacher, 2019/03/12
- [elpa] externals/ivy-explorer 5f9dafc 29/29: Version bump, Clemens Radermacher, 2019/03/12
- [elpa] externals/ivy-explorer 6481247 08/29: Refactor ivy-explorer-avy,
Clemens Radermacher <=
- [elpa] externals/ivy-explorer 2badbe3 09/29: Bytec. fixes for free avy vars, Clemens Radermacher, 2019/03/12
- [elpa] externals/ivy-explorer c2ef475 19/29: Update ivy explorere avy dispatch for posframe, Clemens Radermacher, 2019/03/12
- [elpa] externals/ivy-explorer 8cfe1b4 23/29: Update docstrings, Clemens Radermacher, 2019/03/12
- [elpa] externals/ivy-explorer 9f63344 25/29: Allow specifiying width to create the menu string, Clemens Radermacher, 2019/03/12
- [elpa] externals/ivy-explorer 36fef40 14/29: Update description, Clemens Radermacher, 2019/03/12
- [elpa] externals/ivy-explorer 81b2a17 24/29: Improve ivy-explorer-read, Clemens Radermacher, 2019/03/12