diff options
author | Case Duckworth | 2022-01-02 01:15:02 -0600 |
---|---|---|
committer | Case Duckworth | 2022-01-02 01:15:02 -0600 |
commit | f33ffe13705f404b26246ff6edb5fa36200b4d47 (patch) | |
tree | 4a5afe3fbfc1f06a061fe6a26669921ff33e9945 /lisp | |
parent | Add org-visibility (diff) | |
download | emacs-f33ffe13705f404b26246ff6edb5fa36200b4d47.tar.gz emacs-f33ffe13705f404b26246ff6edb5fa36200b4d47.zip |
Update +key to use menu as a prefix key too
I should probably choose one or the other to use.... or something. h/t to https://old.reddit.com/r/emacs/comments/rr330u/weekly_tips_tricks_c_thread/hqwbz6p/?context=3
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/+key.el | 61 |
1 files changed, 47 insertions, 14 deletions
diff --git a/lisp/+key.el b/lisp/+key.el index 7a51be1..4638e95 100644 --- a/lisp/+key.el +++ b/lisp/+key.el | |||
@@ -24,32 +24,57 @@ | |||
24 | map) | 24 | map) |
25 | "A leader keymap under the \"C-z\" bind.") | 25 | "A leader keymap under the \"C-z\" bind.") |
26 | 26 | ||
27 | ;; http://xahlee.info/emacs/emacs/emacs_menu_app_keys.html and | ||
28 | (defvar +key-menu-map (let ((map (make-sparse-keymap))) | ||
29 | (define-key map (kbd "<menu>") | ||
30 | #'execute-extended-command) | ||
31 | map) | ||
32 | "Custom bindings behind the menu key.") | ||
33 | |||
27 | (defvar +key-mode-map (let ((map (make-sparse-keymap))) | 34 | (defvar +key-mode-map (let ((map (make-sparse-keymap))) |
28 | (define-key map "\C-z" +key-leader-map) | 35 | (define-key map "\C-z" +key-leader-map) |
29 | map) | 36 | (define-key map (kbd "<menu>") +key-menu-map) |
37 | map) | ||
30 | "Keymap for `+key-mode'.") | 38 | "Keymap for `+key-mode'.") |
31 | 39 | ||
40 | (defun turn-off-+key-mode () | ||
41 | "Turn off `+key-mode'." | ||
42 | (+key-mode -1)) | ||
43 | |||
32 | ;;;###autoload | 44 | ;;;###autoload |
33 | (define-minor-mode +key-mode | 45 | (define-minor-mode +key-mode |
34 | "A minor mode with keybindings that will override every other mode." | 46 | "A minor mode with keybindings that will override every other mode." |
35 | :init-value t | 47 | :init-value t |
36 | :lighter " +") | 48 | :lighter " +" |
37 | (add-to-list 'emulation-mode-map-alists `((+key-mode . ,+key-mode-map))) | 49 | (if +key-mode |
38 | 50 | (progn ; Enable | |
39 | ;;;###autoload | 51 | (add-to-list 'emulation-mode-map-alists |
40 | (define-globalized-minor-mode +key-global-mode +key-mode +key-mode) | 52 | `((+key-mode . ,+key-mode-map))) |
53 | ;; Disable in minibuffer | ||
54 | (add-hook 'minibuffer-setup-hook #'turn-off-+key-mode) | ||
55 | ;; compat Linux-Windows | ||
56 | (define-key key-translation-map (kbd "<apps>") (kbd "<menu>")) | ||
57 | ;; curse you, thinkpad keyboard!!! | ||
58 | (define-key key-translation-map (kbd "<print>") (kbd "<menu>")) | ||
59 | ) | ||
60 | ;; Disable | ||
61 | (setq emulation-mode-map-alists | ||
62 | (assoc-delete-all '+key-mode emulation-mode-map-alists | ||
63 | (lambda (a b) | ||
64 | (equal (car a) b)))) | ||
65 | (remove-hook 'minibuffer-setup-hook #'turn-off-+key-mode) | ||
66 | (define-key key-translation-map (kbd "<print>") nil) | ||
67 | (define-key key-translation-map (kbd "<apps>") nil))) | ||
41 | 68 | ||
42 | ;;;###autoload | 69 | ;;;###autoload |
43 | (defun +key-setup () | 70 | (defun +key-setup () |
44 | "Setup `+key-mode' after everything else." | 71 | "Ensure `+key-mode' happens after init." |
45 | (if after-init-time | 72 | (if after-init-time |
46 | (+key-global-mode +1) | 73 | (+key-global-mode) |
47 | (add-hook 'after-init-hook '+key-global-mode))) | 74 | (add-hook 'after-init-hook #'+key-global-mode))) |
48 | 75 | ||
49 | (defun turn-off-+key-mode () | 76 | ;;;###autoload |
50 | "Turn off `+key-mode'." | 77 | (define-globalized-minor-mode +key-global-mode +key-mode +key-mode) |
51 | (+key-mode -1)) | ||
52 | (add-hook 'minibuffer-setup-hook 'turn-off-+key-mode) | ||
53 | 78 | ||
54 | ;; Extras for `setup' | 79 | ;; Extras for `setup' |
55 | (with-eval-after-load 'setup | 80 | (with-eval-after-load 'setup |
@@ -67,6 +92,14 @@ | |||
67 | :documentation "Bind KEY to COMMAND in `+key-leader-map'." | 92 | :documentation "Bind KEY to COMMAND in `+key-leader-map'." |
68 | :debug '(form sexp) | 93 | :debug '(form sexp) |
69 | :ensure '(kbd func) | 94 | :ensure '(kbd func) |
95 | :repeatable t) | ||
96 | |||
97 | (setup-define :+menu | ||
98 | (lambda (key command) | ||
99 | `(define-key +key-menu-map ,key ,command)) | ||
100 | :documentation "Bind KEY to COMMAND in `+key-leader-map'." | ||
101 | :debug '(form sexp) | ||
102 | :ensure '(kbd func) | ||
70 | :repeatable t)) | 103 | :repeatable t)) |
71 | 104 | ||
72 | (provide '+key) | 105 | (provide '+key) |