diff options
| author | Craig Jennings <c@cjennings.net> | 2026-07-02 01:40:07 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-07-02 01:40:07 -0400 |
| commit | 8ef30e38c18c48da547d7c75735c20a2efcca777 (patch) | |
| tree | 66fbfc4ee818ee609a793ccf170c021414e9a70b | |
| parent | 6f659aa3b424c513979ba83ea4f15856f9491c01 (diff) | |
| download | dotemacs-8ef30e38c18c48da547d7c75735c20a2efcca777.tar.gz dotemacs-8ef30e38c18c48da547d7c75735c20a2efcca777.zip | |
fix(org-capture): block global popup keys while a capture is open
F1, F10, F11, F12, and M-SPC are global popup keys (dashboard sweep, music, dirvish-side, terminal, agent swap) and fired over an in-progress capture. org-capture-mode's keymap is active exactly for the capture's duration and shadows the global map, so those keys now hit a blocker there that names the way out (C-c C-c to finalize, C-c C-k to abort). The C-; a prefix stays unblocked: a deliberate two-chord sequence isn't a stray keypress.
| -rw-r--r-- | modules/org-capture-config.el | 17 | ||||
| -rw-r--r-- | tests/test-org-capture-config-fkey-guard.el | 42 |
2 files changed, 59 insertions, 0 deletions
diff --git a/modules/org-capture-config.el b/modules/org-capture-config.el index 14fb8e58..292e26a7 100644 --- a/modules/org-capture-config.el +++ b/modules/org-capture-config.el @@ -144,6 +144,23 @@ re-scanning large target files after the first successful lookup." (advice-add 'org-capture-set-target-location :around #'cj/org-capture--set-target-location-advice)) +;; --------------------------- Capture F-Key Guard ----------------------------- +;; The global popup keys (F1 dashboard sweep, F10 music, F11 dirvish-side, +;; F12 terminal, M-SPC agent swap) fire even while a capture is in progress +;; and pop their UI over the capture popup. org-capture-mode is a minor +;; mode active exactly for the capture's duration and its keymap shadows +;; the global map, so blocking the keys there scopes the guard precisely: +;; the moment the capture finalizes or aborts, the keys work again. + +(defun cj/--org-capture-blocked-key () + "Refuse a global popup key while a capture is in progress." + (interactive) + (user-error "Key disabled during capture -- finalize with C-c C-c or abort with C-c C-k")) + +(with-eval-after-load 'org-capture + (dolist (key '("<f1>" "<f10>" "<f11>" "<f12>" "M-SPC")) + (keymap-set org-capture-mode-map key #'cj/--org-capture-blocked-key))) + ;; ----------------------- Project-Aware Capture Target ------------------------ ;; C-c c t (Task) and C-c c b (Bug) file into the current projectile project's ;; todo.org under its "... Open Work" heading. Outside a project they fall back diff --git a/tests/test-org-capture-config-fkey-guard.el b/tests/test-org-capture-config-fkey-guard.el new file mode 100644 index 00000000..b288ce4f --- /dev/null +++ b/tests/test-org-capture-config-fkey-guard.el @@ -0,0 +1,42 @@ +;;; test-org-capture-config-fkey-guard.el --- capture F-key guard -*- lexical-binding: t; -*- + +;;; Commentary: +;; While a capture is in progress, the global popup keys (F1 dashboard +;; sweep, F10 music, F11 dirvish-side, F12 terminal, M-SPC agent swap) +;; must not fire and pop UI over the capture. org-capture-mode is a +;; minor mode active exactly for the capture's duration and its keymap +;; shadows the global map, so the guard binds those keys there to a +;; blocker that signals a `user-error' naming the way out. + +;;; Code: + +(require 'ert) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) + +;; Load org-capture first so the module's with-eval-after-load fires +;; synchronously. +(require 'org-capture) +(require 'org-capture-config) + +(ert-deftest test-org-capture-fkey-guard-keys-bound () + "Normal: every leaking popup key is bound to the blocker in capture mode." + (dolist (key '("<f1>" "<f10>" "<f11>" "<f12>" "M-SPC")) + (should (eq (keymap-lookup org-capture-mode-map key) + #'cj/--org-capture-blocked-key)))) + +(ert-deftest test-org-capture-fkey-guard-blocker-signals-user-error () + "Error: the blocker signals a user-error rather than doing nothing." + (should-error (cj/--org-capture-blocked-key) :type 'user-error)) + +(ert-deftest test-org-capture-fkey-guard-shadows-global () + "Normal: with org-capture-mode active, the minor-mode binding wins." + (with-temp-buffer + (org-capture-mode 1) + (unwind-protect + (should (eq (key-binding (kbd "<f12>")) + #'cj/--org-capture-blocked-key)) + (org-capture-mode -1)))) + +(provide 'test-org-capture-config-fkey-guard) +;;; test-org-capture-config-fkey-guard.el ends here |
