From 854aa53a96476ccaae0c93bd9af0493ef8431e4b Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Fri, 5 Jun 2026 05:43:43 -0500 Subject: fix(term): make F9 and F12 reach Emacs inside ghostel buffers F9 did nothing in an agent buffer: ghostel's semi-char mode forwards every key not in ghostel-keymap-exceptions to the pty, and ghostel-semi-char-mode-map outranks the major-mode map, so the F9-family and F12 bindings I'd put in ghostel-mode-map never fired. The keys went to Claude/the shell, which ignored them. I added the F9 family (in ai-term) and F12 plus C-; (in term-config) to ghostel-keymap-exceptions and rebuilt the semi-char map with ghostel--rebuild-semi-char-keymap. add-to-list updates the list but not the already-built map, so the rebuild is what actually lets the keys through. C-; had the same latent bug for the same reason. Two regression tests assert the keys are in the exceptions and that the rebuilt semi-char map no longer forwards them. I also corrected the spec note that claimed binding in ghostel-mode-map was enough (true for vterm, wrong for ghostel) and codified the gotcha. --- modules/ai-term.el | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'modules/ai-term.el') diff --git a/modules/ai-term.el b/modules/ai-term.el index 85b84a12e..1384f8124 100644 --- a/modules/ai-term.el +++ b/modules/ai-term.el @@ -74,6 +74,8 @@ (declare-function ghostel "ghostel" (&optional arg)) (declare-function ghostel-send-string "ghostel" (string)) +(declare-function ghostel--rebuild-semi-char-keymap "ghostel" ()) +(defvar ghostel-keymap-exceptions) (defvar ghostel-mode-map) (defvar ghostel-buffer-name) (defvar ghostel-buffer-name-function) @@ -923,7 +925,16 @@ interrupt work in progress. Bound to M- (primary) and C-S-." (keymap-set ghostel-mode-map "" #'cj/ai-term) (keymap-set ghostel-mode-map "C-" #'cj/ai-term-pick-project) (keymap-set ghostel-mode-map "M-" #'cj/ai-term-close) - (keymap-set ghostel-mode-map "C-S-" #'cj/ai-term-close)) + (keymap-set ghostel-mode-map "C-S-" #'cj/ai-term-close) + ;; The bindings above live in `ghostel-mode-map', but in semi-char mode + ;; ghostel's own `ghostel-semi-char-mode-map' forwards every key not in + ;; `ghostel-keymap-exceptions' to the pty -- and that map outranks the + ;; major-mode map, so it would swallow the F9 family before the bindings + ;; above fire. Add the family to the exceptions and rebuild the semi-char + ;; map so the keys fall through to `ghostel-mode-map' inside agent buffers. + (dolist (key '("" "C-" "M-" "C-S-")) + (add-to-list 'ghostel-keymap-exceptions key)) + (ghostel--rebuild-semi-char-keymap)) ;; ---------- emacsclient: keep opened files off the agent terminal ---------- ;; -- cgit v1.2.3