summaryrefslogtreecommitdiff
path: root/modules/ai-vterm.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-12 12:53:11 -0500
committerCraig Jennings <c@cjennings.net>2026-05-12 12:53:11 -0500
commitc72d4abc17ae7bed792fa610c0a67b917e191f4b (patch)
tree313988cafb0755a8116cebc499a3f60cbbee0d15 /modules/ai-vterm.el
parenta15c6b3e92b8d7be6be6dc4dd6802a18ccf52326 (diff)
downloaddotemacs-c72d4abc17ae7bed792fa610c0a67b917e191f4b.tar.gz
dotemacs-c72d4abc17ae7bed792fa610c0a67b917e191f4b.zip
fix(ai-vterm): make F9 toggle the agent from inside an agent buffer
vterm binds `<f1>`..`<f12>` to `vterm--self-insert`, so a plain `<f9>` typed while point is in an agent buffer goes to the terminal program instead of the global toggle. That's invisible most of the time — you press F9 from another window — but it bites when the agent buffer is the only window in the frame, because there's nowhere else to press it from. I re-bound the F9 family in `vterm-mode-map` (via `with-eval-after-load 'vterm`) so that `<f9>`, `C-<f9>`, and `M-<f9>` reach `cj/ai-vterm`, `cj/ai-vterm-pick-project`, and `cj/ai-vterm-pick-buffer` from there too. The C-/M- variants aren't actually in vterm's intercept set, but binding them keeps things uniform. New `tests/test-ai-vterm--f9-in-vterm.el`: 4 ERT tests over the `vterm-mode-map` and global bindings. F12's `cj/vterm-toggle` has the same shape of bug and isn't touched here.
Diffstat (limited to 'modules/ai-vterm.el')
-rw-r--r--modules/ai-vterm.el12
1 files changed, 12 insertions, 0 deletions
diff --git a/modules/ai-vterm.el b/modules/ai-vterm.el
index b0872b6b..ac246ee8 100644
--- a/modules/ai-vterm.el
+++ b/modules/ai-vterm.el
@@ -51,6 +51,7 @@
(declare-function vterm "vterm" (&optional buffer-name))
(declare-function vterm-send-string "vterm" (string &optional paste-p))
(declare-function vterm-send-return "vterm" ())
+(defvar vterm-mode-map)
(defgroup ai-vterm nil
"In-Emacs AI-agent launcher with vertical-split vterm."
@@ -696,6 +697,17 @@ AI-vterm buffers without touching the project list."
(keymap-global-set "C-<f9>" #'cj/ai-vterm-pick-project)
(keymap-global-set "M-<f9>" #'cj/ai-vterm-pick-buffer)
+;; vterm binds <f1>..<f12> to `vterm--self-insert', so a plain <f9> typed
+;; while point is inside an agent buffer gets sent to the terminal program
+;; instead of toggling the agent -- which bites hard when the agent buffer is
+;; the only window in the frame. Re-bind the F9 family in `vterm-mode-map' so
+;; the toggle reaches Emacs from there too. (C-<f9> / M-<f9> aren't in vterm's
+;; intercept set, but bind them here as well so the behaviour is uniform.)
+(with-eval-after-load 'vterm
+ (keymap-set vterm-mode-map "<f9>" #'cj/ai-vterm)
+ (keymap-set vterm-mode-map "C-<f9>" #'cj/ai-vterm-pick-project)
+ (keymap-set vterm-mode-map "M-<f9>" #'cj/ai-vterm-pick-buffer))
+
;; ---------- emacsclient: keep opened files off the agent vterm ----------
;;
;; `server-start' (in system-defaults.el) leaves `server-window' nil, so