From f33ffe13705f404b26246ff6edb5fa36200b4d47 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 2 Jan 2022 01:15:02 -0600 Subject: 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 --- lisp/+key.el | 61 ++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 14 deletions(-) (limited to 'lisp') 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 @@ map) "A leader keymap under the \"C-z\" bind.") +;; http://xahlee.info/emacs/emacs/emacs_menu_app_keys.html and +(defvar +key-menu-map (let ((map (make-sparse-keymap))) + (define-key map (kbd "") + #'execute-extended-command) + map) + "Custom bindings behind the menu key.") + (defvar +key-mode-map (let ((map (make-sparse-keymap))) - (define-key map "\C-z" +key-leader-map) - map) + (define-key map "\C-z" +key-leader-map) + (define-key map (kbd "") +key-menu-map) + map) "Keymap for `+key-mode'.") +(defun turn-off-+key-mode () + "Turn off `+key-mode'." + (+key-mode -1)) + ;;;###autoload (define-minor-mode +key-mode "A minor mode with keybindings that will override every other mode." :init-value t - :lighter " +") -(add-to-list 'emulation-mode-map-alists `((+key-mode . ,+key-mode-map))) - -;;;###autoload -(define-globalized-minor-mode +key-global-mode +key-mode +key-mode) + :lighter " +" + (if +key-mode + (progn ; Enable + (add-to-list 'emulation-mode-map-alists + `((+key-mode . ,+key-mode-map))) + ;; Disable in minibuffer + (add-hook 'minibuffer-setup-hook #'turn-off-+key-mode) + ;; compat Linux-Windows + (define-key key-translation-map (kbd "") (kbd "")) + ;; curse you, thinkpad keyboard!!! + (define-key key-translation-map (kbd "") (kbd "")) + ) + ;; Disable + (setq emulation-mode-map-alists + (assoc-delete-all '+key-mode emulation-mode-map-alists + (lambda (a b) + (equal (car a) b)))) + (remove-hook 'minibuffer-setup-hook #'turn-off-+key-mode) + (define-key key-translation-map (kbd "") nil) + (define-key key-translation-map (kbd "") nil))) ;;;###autoload (defun +key-setup () - "Setup `+key-mode' after everything else." + "Ensure `+key-mode' happens after init." (if after-init-time - (+key-global-mode +1) - (add-hook 'after-init-hook '+key-global-mode))) + (+key-global-mode) + (add-hook 'after-init-hook #'+key-global-mode))) -(defun turn-off-+key-mode () - "Turn off `+key-mode'." - (+key-mode -1)) -(add-hook 'minibuffer-setup-hook 'turn-off-+key-mode) +;;;###autoload +(define-globalized-minor-mode +key-global-mode +key-mode +key-mode) ;; Extras for `setup' (with-eval-after-load 'setup @@ -67,6 +92,14 @@ :documentation "Bind KEY to COMMAND in `+key-leader-map'." :debug '(form sexp) :ensure '(kbd func) + :repeatable t) + + (setup-define :+menu + (lambda (key command) + `(define-key +key-menu-map ,key ,command)) + :documentation "Bind KEY to COMMAND in `+key-leader-map'." + :debug '(form sexp) + :ensure '(kbd func) :repeatable t)) (provide '+key) -- cgit 1.4.1-21-gabe81