diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-24 19:53:28 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-24 19:53:28 -0500 |
| commit | 47f222f66d7d481fb0d50661d64f49440455ff6d (patch) | |
| tree | ce208be918001b30ed67cf80292b47e5b22c46f0 /modules | |
| parent | 36a453d2c1237b49f594b23433858a0146dbf31e (diff) | |
| download | dotemacs-47f222f66d7d481fb0d50661d64f49440455ff6d.tar.gz dotemacs-47f222f66d7d481fb0d50661d64f49440455ff6d.zip | |
feat(keybindings): add cj/custom-keymap registration API
Phase 3 of the load-graph project. cj/register-prefix-map and cj/register-command bind a prefix map or command under the C-; prefix and register the which-key label once which-key loads. Feature modules will route their registration through these instead of mutating cj/custom-keymap directly, so keybindings.el stays the sole owner of the prefix and modules stop assuming the keymap already exists at load.
Adds test-init-keymap-registration.el covering prefix-map and command resolution, the optional label, and invalid-key rejection. No modules are migrated yet; that follows in batches.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/keybindings.el | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/keybindings.el b/modules/keybindings.el index 6e8adeac..db480087 100644 --- a/modules/keybindings.el +++ b/modules/keybindings.el @@ -36,6 +36,32 @@ :doc "User custom prefix keymap base for nested keymaps.") (keymap-global-set "C-;" cj/custom-keymap) +;; ------------------------ Custom Keymap Registration ------------------------- + +;; Feature modules register into the C-; prefix through these helpers rather +;; than mutating `cj/custom-keymap' directly. This keeps keybindings.el the +;; sole owner of the prefix and removes each module's hidden assumption that +;; the keymap already exists. KEY is a `keymap-set'-style key relative to the +;; C-; prefix (e.g. "c" binds C-; c). Modules must (require 'keybindings). + +(defun cj/register-prefix-map (key map &optional label) + "Bind prefix keymap MAP under KEY within `cj/custom-keymap'. +When LABEL is non-nil, register it as the which-key description for the +\"C-; KEY\" prefix once which-key loads." + (keymap-set cj/custom-keymap key map) + (when label + (with-eval-after-load 'which-key + (which-key-add-key-based-replacements (concat "C-; " key) label)))) + +(defun cj/register-command (key command &optional label) + "Bind COMMAND under KEY within `cj/custom-keymap'. +When LABEL is non-nil, register it as the which-key description for the +\"C-; KEY\" key once which-key loads." + (keymap-set cj/custom-keymap key command) + (when label + (with-eval-after-load 'which-key + (which-key-add-key-based-replacements (concat "C-; " key) label)))) + ;; ------------------------------ Jump To Commands ----------------------------- (defun cj/jump-open-var (var) |
