From 1d93e1a6569e4193c2b078a3d5df0bf47eeba9df Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 7 May 2026 22:09:15 -0500 Subject: fix(ai-vterm): direction-based display + per-project tmux session names Two post-ship issues blocked practical use of the new launcher. The display rule used `display-buffer-in-side-window` with `(dedicated . t)`. Side-window dedication caused `set-window-buffer` to error during `buffer-move` (C-M-arrows), which left a half-finished swap with both sides showing the claude buffer. Then `switch-to-buffer` on a non-claude buffer in that dedicated window split instead of replacing. I rewrote the rule as `display-buffer-reuse-window -> display-buffer-use-some-window -> display-buffer-in-direction (right)`. The resulting window is ordinary, not dedicated, so swap and replace work normally. I also narrowed `vterm-toggle`'s broad lambda (which matches any vterm-mode buffer) to exclude `claude [` buffers. Otherwise vterm-toggle's `:defer` made it install last and capture our buffers first with its own bottom-split + dedicated treatment. The tmux side: vterm's auto-launch hook ran a bare `tmux\n`, so each session got an auto-named one. After an Emacs crash the tmux session would survive but I couldn't find it. A second F9 just spawned another. The launcher now sends `tmux new-session -A -s -c '; exec bash'`. The `-A` reattaches to a same-named session if it already exists. The `exec bash` keeps the tmux window alive if claude itself exits. A `cj/--ai-vterm-suppress-tmux` flag tells the existing vterm hook to skip its bare tmux step so the named launch runs instead. 11 new tests across 2 files cover the session-name and launch-command helpers. I updated tests for show-or-create and the display rule. All 34 ai-vterm tests are green. --- modules/eshell-vterm-config.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'modules/eshell-vterm-config.el') diff --git a/modules/eshell-vterm-config.el b/modules/eshell-vterm-config.el index 4c22944b..31c3a96e 100644 --- a/modules/eshell-vterm-config.el +++ b/modules/eshell-vterm-config.el @@ -202,10 +202,16 @@ (display-line-numbers-mode -1)) (defun cj/vterm-launch-tmux () - "Automatically launch tmux in vterm if not already in a tmux session." + "Automatically launch tmux in vterm if not already in a tmux session. + +Skipped when `cj/--ai-vterm-suppress-tmux' is non-nil so the AI-vterm +flow can run its own project-named tmux session instead of a bare, +auto-named one. `bound-and-true-p' keeps this safe whether or not +ai-vterm.el is loaded." (let ((proc (get-buffer-process (current-buffer)))) (when (and proc - (not (getenv "TMUX"))) ; Check if not already in tmux + (not (getenv "TMUX")) ; Check if not already in tmux + (not (bound-and-true-p cj/--ai-vterm-suppress-tmux))) (vterm-send-string "tmux\n")))) :hook ((vterm-mode . cj/turn-off-chrome-for-vterm) -- cgit v1.2.3