avy.el (avy-pre-action): New defvar

Fixes #260
This commit is contained in:
Oleh Krehel 2019-01-15 15:14:10 +01:00
parent 24b51374be
commit e7c0fc046d

25
avy.el
View File

@ -751,6 +751,19 @@ Set `avy-style' according to COMMMAND as well."
(when (looking-at-p "\\b") (when (looking-at-p "\\b")
(ispell-word))))))) (ispell-word)))))))
(defvar avy-pre-action #'avy-pre-action-default
"Function to call before `avy-action' is called.")
(defun avy-pre-action-default (res)
(avy-push-mark)
(when (and (consp res)
(windowp (cdr res)))
(let* ((window (cdr res))
(frame (window-frame window)))
(unless (equal frame (selected-frame))
(select-frame-set-input-focus frame))
(select-window window))))
(defun avy--process-1 (candidates overlay-fn) (defun avy--process-1 (candidates overlay-fn)
(let ((len (length candidates))) (let ((len (length candidates)))
(cond ((= len 0) (cond ((= len 0)
@ -793,16 +806,8 @@ Use OVERLAY-FN to visualize the decision overlay."
;; ignore exit from `avy-handler-function' ;; ignore exit from `avy-handler-function'
((eq res 'exit)) ((eq res 'exit))
(t (t
(avy-push-mark) (funcall avy-pre-action res)
(when (and (consp res) (setq res (car res))
(windowp (cdr res)))
(let* ((window (cdr res))
(frame (window-frame window)))
(unless (equal frame (selected-frame))
(select-frame-set-input-focus frame))
(select-window window))
(setq res (car res)))
(funcall (or avy-action 'avy-action-goto) (funcall (or avy-action 'avy-action-goto)
(if (consp res) (if (consp res)
(car res) (car res)