diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-03 19:10:50 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-03 19:10:50 -0500 |
| commit | c2f355bf601fd9b7db0107c163c64432a7ae9a80 (patch) | |
| tree | 9df8e899861bb0374d9a9157b7a37962b6f5d5e7 | |
| parent | 875887fc3821869c7ca8f23777e79caa00b3999e (diff) | |
| download | dotemacs-c2f355bf601fd9b7db0107c163c64432a7ae9a80.tar.gz dotemacs-c2f355bf601fd9b7db0107c163c64432a7ae9a80.zip | |
fix: keep C-; ! as system command prefix
The module was binding `cj/system-command-map` under `C-; !`, then a few lines later overwriting the same prefix with `cj/system-command-menu`. The second bind won, so every documented subkey, like `C-; ! r` for reboot and `C-; ! l` for lock, was unreachable.
I kept the prefix map and folded the completing-read menu into it at `C-; ! !`. So `C-; !` still opens the prefix, the menu is one extra `!` away, and the single-letter shortcuts work again. I also added which-key labels for every documented subkey so the popup actually says what each one does.
I added `tests/test-system-commands-keymap.el`. It asserts the prefix stays mounted and that every binding (`!`, `L`, `r`, `s`, `S`, `l`, `E`, `e`) resolves to the right command.
| -rw-r--r-- | modules/system-commands.el | 34 | ||||
| -rw-r--r-- | tests/test-system-commands-keymap.el | 36 |
2 files changed, 57 insertions, 13 deletions
diff --git a/modules/system-commands.el b/modules/system-commands.el index fb8c0611..8b155746 100644 --- a/modules/system-commands.el +++ b/modules/system-commands.el @@ -104,17 +104,6 @@ If CONFIRM is non-nil, mark VAR to always require confirmation." (run-at-time 1 nil #'kill-emacs) (message "Restarting Emacs...")) -(defvar-keymap cj/system-command-map - :doc "Keymap for system commands." - "L" #'cj/system-cmd-logout - "r" #'cj/system-cmd-reboot - "s" #'cj/system-cmd-shutdown - "S" #'cj/system-cmd-suspend - "l" #'cj/system-cmd-lock - "E" #'cj/system-cmd-exit-emacs - "e" #'cj/system-cmd-restart-emacs) -(keymap-set cj/custom-keymap "!" cj/system-command-map) - (defun cj/system-command-menu () "Present system commands via \='completing-read\='." (interactive) @@ -129,10 +118,29 @@ If CONFIRM is non-nil, mark VAR to always require confirmation." (when-let ((cmd (alist-get choice commands nil nil #'equal))) (call-interactively cmd)))) -(keymap-set cj/custom-keymap "!" #'cj/system-command-menu) +(defvar-keymap cj/system-command-map + :doc "Keymap for system commands." + "!" #'cj/system-command-menu + "L" #'cj/system-cmd-logout + "r" #'cj/system-cmd-reboot + "s" #'cj/system-cmd-shutdown + "S" #'cj/system-cmd-suspend + "l" #'cj/system-cmd-lock + "E" #'cj/system-cmd-exit-emacs + "e" #'cj/system-cmd-restart-emacs) +(keymap-set cj/custom-keymap "!" cj/system-command-map) (with-eval-after-load 'which-key - (which-key-add-key-based-replacements "C-; !" "system commands")) + (which-key-add-key-based-replacements + "C-; !" "system commands" + "C-; ! !" "system command menu" + "C-; ! L" "logout" + "C-; ! E" "exit Emacs" + "C-; ! S" "suspend" + "C-; ! e" "restart Emacs" + "C-; ! l" "lock screen" + "C-; ! r" "reboot" + "C-; ! s" "shutdown")) (provide 'system-commands) ;;; system-commands.el ends here diff --git a/tests/test-system-commands-keymap.el b/tests/test-system-commands-keymap.el new file mode 100644 index 00000000..ac78a25d --- /dev/null +++ b/tests/test-system-commands-keymap.el @@ -0,0 +1,36 @@ +;;; test-system-commands-keymap.el --- Tests for system command keymap -*- lexical-binding: t; -*- + +;;; Commentary: + +;; The system command keymap should remain mounted as a prefix under C-; ! so +;; which-key can show the documented subcommands. + +;;; Code: + +(require 'ert) + +(defvar cj/custom-keymap (make-sparse-keymap) + "Stub custom keymap for system-commands tests.") + +(require 'system-commands) + +(ert-deftest test-system-commands-keymap-normal-prefix-mounted () + "Normal: C-; ! remains a prefix keymap, not a direct command." + (should (eq (keymap-lookup cj/custom-keymap "!") + cj/system-command-map))) + +(ert-deftest test-system-commands-keymap-normal-documented-subkeys () + "Normal: documented system command subkeys resolve under the prefix." + (dolist (binding '(("!" . cj/system-command-menu) + ("L" . cj/system-cmd-logout) + ("r" . cj/system-cmd-reboot) + ("s" . cj/system-cmd-shutdown) + ("S" . cj/system-cmd-suspend) + ("l" . cj/system-cmd-lock) + ("E" . cj/system-cmd-exit-emacs) + ("e" . cj/system-cmd-restart-emacs))) + (should (eq (keymap-lookup cj/system-command-map (car binding)) + (cdr binding))))) + +(provide 'test-system-commands-keymap) +;;; test-system-commands-keymap.el ends here |
