diff options
Diffstat (limited to 'lisp/+avy.el')
-rw-r--r-- | lisp/+avy.el | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/lisp/+avy.el b/lisp/+avy.el index 8056f00..b0837a3 100644 --- a/lisp/+avy.el +++ b/lisp/+avy.el | |||
@@ -50,17 +50,35 @@ | |||
50 | (defvar-local +avy-buffer-face-mode-face nil | 50 | (defvar-local +avy-buffer-face-mode-face nil |
51 | "The state of `buffer-face-mode' before calling `avy-with'.") | 51 | "The state of `buffer-face-mode' before calling `avy-with'.") |
52 | 52 | ||
53 | (defun +avy@un-buffer-face (&rest _) | 53 | ;;; XXX: Doesn't switch back if avy errors out or quits |
54 | (defun +avy@un-buffer-face (win) | ||
54 | "BEFORE advice on `avy-with' to disable `buffer-face-mode'." | 55 | "BEFORE advice on `avy-with' to disable `buffer-face-mode'." |
55 | (when buffer-face-mode | 56 | (with-current-buffer (window-buffer win) |
56 | (setq +avy-buffer-face-mode-face buffer-face-mode-face) | 57 | (when buffer-face-mode |
57 | (buffer-face-mode -1))) | 58 | (setq +avy-buffer-face-mode-face buffer-face-mode-face) |
59 | (buffer-face-mode -1)))) | ||
58 | 60 | ||
59 | (defun +avy@re-buffer-face (&rest _) | 61 | (defun +avy@re-buffer-face (win) |
60 | "AFTER advice on `avy-with' to re-enable `buffer-face-mode'." | 62 | "AFTER advice on `avy-with' to re-enable `buffer-face-mode'." |
61 | (when +avy-buffer-face-mode-face | 63 | (with-current-buffer (window-buffer win) |
62 | (setq buffer-face-mode-face +avy-buffer-face-mode-face) | 64 | (when +avy-buffer-face-mode-face |
63 | (buffer-face-mode +1))) | 65 | (setq buffer-face-mode-face +avy-buffer-face-mode-face) |
66 | (buffer-face-mode +1))) | ||
67 | (let ((bounds (bounds-of-thing-at-point 'symbol))) | ||
68 | (when (and (car bounds) | ||
69 | (cdr bounds)) | ||
70 | (pulse-momentary-highlight-region (car bounds) (cdr bounds))))) | ||
71 | |||
72 | (defun +avy@buffer-face (fn &rest r) | ||
73 | "AROUND advice for avy to dis/enable `buffer-face-mode'." | ||
74 | (if avy-all-windows | ||
75 | (walk-windows #'+avy@un-buffer-face nil (eq avy-all-windows 'all-frames))) | ||
76 | (condition-case e | ||
77 | (apply fn r) | ||
78 | ((quit error) (message "Avy: %S" e) nil) | ||
79 | (:sucess e)) | ||
80 | (if avy-all-windows | ||
81 | (walk-windows #'+avy@re-buffer-face nil (eq avy-all-windows 'all-frames)))) | ||
64 | 82 | ||
65 | (define-minor-mode +avy-buffer-face-mode | 83 | (define-minor-mode +avy-buffer-face-mode |
66 | "Turn off `buffer-face-mode' before doing Avy selections. | 84 | "Turn off `buffer-face-mode' before doing Avy selections. |
@@ -71,11 +89,9 @@ Restore the mode after the selection." | |||
71 | (cond | 89 | (cond |
72 | (+avy-buffer-face-mode | 90 | (+avy-buffer-face-mode |
73 | (dolist (fn +avy-buffer-face-functions) | 91 | (dolist (fn +avy-buffer-face-functions) |
74 | (advice-add fn :before #'+avy@un-buffer-face)) | 92 | (advice-add fn :around #'+avy@buffer-face))) |
75 | (advice-add 'avy--done :after #'+avy@re-buffer-face)) | ||
76 | (t (dolist (fn +avy-buffer-face-functions) | 93 | (t (dolist (fn +avy-buffer-face-functions) |
77 | (advice-remove fn #'+avy@un-buffer-face)) | 94 | (advice-remove fn #'+avy@buffer-face))))) |
78 | (advice-remove 'avy--done #'+avy@re-buffer-face)))) | ||
79 | 95 | ||
80 | (provide '+avy) | 96 | (provide '+avy) |
81 | ;;; avy.el ends here | 97 | ;;; avy.el ends here |