diff options
author | Case Duckworth | 2022-10-17 21:41:28 -0500 |
---|---|---|
committer | Case Duckworth | 2022-10-17 21:41:28 -0500 |
commit | aab5bfd074e57d06a79e39d7c7c4760e1f385a06 (patch) | |
tree | 7b111190a44458a970355f7a327cc5278c850293 /lisp/+avy.el | |
parent | asoi (diff) | |
download | emacs-aab5bfd074e57d06a79e39d7c7c4760e1f385a06.tar.gz emacs-aab5bfd074e57d06a79e39d7c7c4760e1f385a06.zip |
Bankruptcy 9
Diffstat (limited to 'lisp/+avy.el')
-rw-r--r-- | lisp/+avy.el | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/lisp/+avy.el b/lisp/+avy.el deleted file mode 100644 index b0837a3..0000000 --- a/lisp/+avy.el +++ /dev/null | |||
@@ -1,97 +0,0 @@ | |||
1 | ;;; +avy.el -*- lexical-binding: t -*- | ||
2 | |||
3 | ;;; Commentary: | ||
4 | |||
5 | ;; https://karthinks.com/software/avy-can-do-anything/ | ||
6 | |||
7 | ;;; Code: | ||
8 | |||
9 | (require 'avy) | ||
10 | |||
11 | (defun avy-action-embark (pt) | ||
12 | (unwind-protect | ||
13 | (save-excursion | ||
14 | (goto-char pt) | ||
15 | (embark-act)) | ||
16 | (select-window | ||
17 | (cdr (ring-ref avy-ring 0)))) | ||
18 | t) | ||
19 | |||
20 | |||
21 | ;;; Remove `buffer-face-mode' when avy is active. | ||
22 | |||
23 | (defcustom +avy-buffer-face-functions '(avy-goto-char | ||
24 | avy-goto-char-in-line | ||
25 | avy-goto-char-2 | ||
26 | avy-goto-char-2-above | ||
27 | avy-goto-char-2-below | ||
28 | avy-goto-word-0 | ||
29 | avy-goto-whitespace-end | ||
30 | avy-goto-word-0-above | ||
31 | avy-goto-word-0-below | ||
32 | avy-goto-whitespace-end-above | ||
33 | avy-goto-whitespace-end-below | ||
34 | avy-goto-word-1 | ||
35 | avy-goto-word-1-above | ||
36 | avy-goto-word-1-below | ||
37 | avy-goto-symbol-1 | ||
38 | avy-goto-symbol-1-above | ||
39 | avy-goto-symbol-1-below | ||
40 | avy-goto-subword-0 | ||
41 | avy-goto-subword-1 | ||
42 | avy-goto-word-or-subword-1 | ||
43 | avy-goto-line | ||
44 | avy-goto-line-above | ||
45 | avy-goto-line-below | ||
46 | avy-goto-end-of-line | ||
47 | avy-goto-char-timer) | ||
48 | "Functions to disable `buffer-face-mode' during.") | ||
49 | |||
50 | (defvar-local +avy-buffer-face-mode-face nil | ||
51 | "The state of `buffer-face-mode' before calling `avy-with'.") | ||
52 | |||
53 | ;;; XXX: Doesn't switch back if avy errors out or quits | ||
54 | (defun +avy@un-buffer-face (win) | ||
55 | "BEFORE advice on `avy-with' to disable `buffer-face-mode'." | ||
56 | (with-current-buffer (window-buffer win) | ||
57 | (when buffer-face-mode | ||
58 | (setq +avy-buffer-face-mode-face buffer-face-mode-face) | ||
59 | (buffer-face-mode -1)))) | ||
60 | |||
61 | (defun +avy@re-buffer-face (win) | ||
62 | "AFTER advice on `avy-with' to re-enable `buffer-face-mode'." | ||
63 | (with-current-buffer (window-buffer win) | ||
64 | (when +avy-buffer-face-mode-face | ||
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)))) | ||
82 | |||
83 | (define-minor-mode +avy-buffer-face-mode | ||
84 | "Turn off `buffer-face-mode' before doing Avy selections. | ||
85 | Restore the mode after the selection." | ||
86 | :lighter "" | ||
87 | :global t | ||
88 | (setq +avy-buffer-face-mode-face nil) | ||
89 | (cond | ||
90 | (+avy-buffer-face-mode | ||
91 | (dolist (fn +avy-buffer-face-functions) | ||
92 | (advice-add fn :around #'+avy@buffer-face))) | ||
93 | (t (dolist (fn +avy-buffer-face-functions) | ||
94 | (advice-remove fn #'+avy@buffer-face))))) | ||
95 | |||
96 | (provide '+avy) | ||
97 | ;;; avy.el ends here | ||