aboutsummaryrefslogtreecommitdiff
path: root/modules/ai-vterm.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-14 00:19:44 -0500
committerCraig Jennings <c@cjennings.net>2026-05-14 00:19:44 -0500
commit2498c57cb49e01f6a9bf20f76f500d0e2c8eb083 (patch)
treeba249190ae07a80fcd71c0764b2afb1d003048a5 /modules/ai-vterm.el
parentf93969660b58e96d1acc2bbc4a3bb38955ef0eee (diff)
downloaddotemacs-2498c57cb49e01f6a9bf20f76f500d0e2c8eb083.tar.gz
dotemacs-2498c57cb49e01f6a9bf20f76f500d0e2c8eb083.zip
fix(ai-vterm): force buffer swap after F9 toggle-off in lone window
The original fix (df2b59b) set a flag at toggle-off and let the next toggle-on detect it. The flag mechanism is right, but the toggle-off itself wasn't observable when bury-buffer couldn't switch the lone window onto a different buffer -- `bury-buffer' falls back to `switch-to-prev-buffer', which no-ops when the window's prev-buffer history contains only the agent itself (common right after a `C-x 1' that cleared the surrounding windows' histories). Without an observable swap, the second F9 found the agent still displayed and routed back through toggle-off, looping the user with no visible effect. Dispatcher now explicitly forces the window onto another buffer (`(other-buffer agent-buf t)`) when the lone window is still showing the agent after `bury-buffer'. The round-trip test now exercises the real `bury-buffer' path instead of simulating it; a new test asserts the lone window's buffer is non-agent after toggle-off.
Diffstat (limited to 'modules/ai-vterm.el')
-rw-r--r--modules/ai-vterm.el14
1 files changed, 13 insertions, 1 deletions
diff --git a/modules/ai-vterm.el b/modules/ai-vterm.el
index 1eae19f3a..975374f60 100644
--- a/modules/ai-vterm.el
+++ b/modules/ai-vterm.el
@@ -710,7 +710,19 @@ AI-vterm buffers without touching the project list."
(cond
((one-window-p)
(setq cj/--ai-vterm-last-was-bury t)
- (bury-buffer (window-buffer win)))
+ (bury-buffer (window-buffer win))
+ ;; `bury-buffer' calls `switch-to-prev-buffer' to swap the
+ ;; lone window onto another buffer, but that no-ops when the
+ ;; window's `window-prev-buffers' list only contains the
+ ;; agent itself (common right after a `C-x 1' that cleared
+ ;; the other windows' histories). Without an observable swap
+ ;; the toggle-off appears to do nothing -- a subsequent F9
+ ;; finds the agent still displayed and just buries again.
+ ;; Force the switch when bury's own swap didn't take.
+ (when (and (window-live-p win)
+ (cj/--ai-vterm-buffer-p (window-buffer win)))
+ (with-selected-window win
+ (switch-to-buffer (other-buffer (window-buffer win) t)))))
(t
(setq cj/--ai-vterm-last-was-bury nil)
(delete-window win)))