From 47f222f66d7d481fb0d50661d64f49440455ff6d Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 24 May 2026 19:53:28 -0500 Subject: 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. --- modules/keybindings.el | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'modules') 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) -- cgit v1.2.3