about summary refs log tree commit diff stats
path: root/lisp/+key.el
diff options
context:
space:
mode:
authorCase Duckworth2021-12-06 19:58:46 -0600
committerCase Duckworth2021-12-06 19:58:46 -0600
commitc7a9cba8247444ab08a9f3266404bb2156924cf0 (patch)
treeb739d84c4f9c7d2bc50f0787050789c004db65dc /lisp/+key.el
parentStuff... (diff)
downloademacs-c7a9cba8247444ab08a9f3266404bb2156924cf0.tar.gz
emacs-c7a9cba8247444ab08a9f3266404bb2156924cf0.zip
Mostley add +key.el (but of course other stuff)
Diffstat (limited to 'lisp/+key.el')
-rw-r--r--lisp/+key.el65
1 files changed, 65 insertions, 0 deletions
diff --git a/lisp/+key.el b/lisp/+key.el new file mode 100644 index 0000000..5b4f467 --- /dev/null +++ b/lisp/+key.el
@@ -0,0 +1,65 @@
1;;; +key.el --- minor mode for keymaps -*- lexical-binding: t; -*-
2
3;;; Commentary:
4
5;; Much of the code here was cribbed from https://emacs.stackexchange.com/a/358,
6;; which in turn was cribbed in part from
7;; https://github.com/kaushalmodi/.emacs.d/blob/master/elisp/modi-mode.el,
8;; https://github.com/jwiegley/use-package/blob/master/bind-key.el and
9;; elsewhere.
10
11;; The basic idea is to have a minor-mode for my personal key customizations,
12;; especially a "leader key" set up à la vim. In Emacs, I use `C-z' for this
13;; leader key, because of its easy location and relative uselessness by default.
14
15;;; Code:
16
17;; I need to define this map before the proper mode map.
18(defvar +key-leader-map (let ((map (make-sparse-keymap))
19 (c-z (global-key-binding "\C-z")))
20 (define-key map "\C-z" c-z)
21 map)
22 "A leader keymap under the \"C-z\" bind.")
23
24(defvar +key-mode-map (let ((map (make-sparse-keymap)))
25 (define-key map "\C-z" +key-leader-map)
26 map)
27 "Keymap for `+key-mode'.")
28
29;;;###autoload
30(define-minor-mode +key-mode
31 "A minor mode with keybindings that will override every other mode."
32 :init-value t
33 :lighter " +"
34 :keymap +key-mode-map)
35
36;;;###autoload
37(define-globalized-minor-mode +key-global-mode +key-mode +key-mode)
38
39(add-to-list 'emulation-mode-map-alists `((+key-mode . ,+key-mode-map)))
40
41(defun turn-off-+key-mode ()
42 "Turn off `+key-mode'."
43 (+key-mode -1))
44(add-hook 'minibuffer-setup-hook 'turn-off-+key-mode)
45
46;; Extras for `setup'
47(with-eval-after-load 'setup
48 (setup-define :+key
49 (lambda (key command)
50 `(define-key +key-mode-map ,key ,command))
51 :documentation "Bind KEY to COMMAND in `+key-mode-map'."
52 :debug '(form sexp)
53 :ensure '(kbd func)
54 :repeatable t)
55
56 (setup-define :+leader
57 (lambda (key command)
58 `(define-key +key-leader-map ,key ,command))
59 :documentation "Bind KEY to COMMAND in `+key-leader-map'."
60 :debug '(form sexp)
61 :ensure '(kbd func)
62 :repeatable t))
63
64(provide '+key)
65;;; +key.el ends here