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. --- tests/test-ai-vterm--tmux-session-name.el | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/test-ai-vterm--tmux-session-name.el (limited to 'tests/test-ai-vterm--tmux-session-name.el') diff --git a/tests/test-ai-vterm--tmux-session-name.el b/tests/test-ai-vterm--tmux-session-name.el new file mode 100644 index 000000000..9d56040ed --- /dev/null +++ b/tests/test-ai-vterm--tmux-session-name.el @@ -0,0 +1,43 @@ +;;; test-ai-vterm--tmux-session-name.el --- Tests for cj/--ai-vterm-tmux-session-name -*- lexical-binding: t; -*- + +;;; Commentary: +;; The tmux session name is derived from the project's basename so that +;; reopening Claude on the same project (e.g. after an Emacs crash) +;; reattaches to the same tmux session rather than spawning a new one. +;; Whitespace in the basename gets converted to hyphens so the name is +;; safe to pass on a tmux command line. + +;;; Code: + +(require 'ert) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'ai-vterm) + +(ert-deftest test-ai-vterm--tmux-session-name-normal-project () + "Normal: a typical project path yields its basename." + (should (equal (cj/--ai-vterm-tmux-session-name "/home/cjennings/projects/foo") + "foo"))) + +(ert-deftest test-ai-vterm--tmux-session-name-trailing-slash () + "Boundary: trailing slash collapses before basename extraction." + (should (equal (cj/--ai-vterm-tmux-session-name "/home/cjennings/projects/foo/") + "foo"))) + +(ert-deftest test-ai-vterm--tmux-session-name-dot-prefix-dir () + "Boundary: dot-prefix dirs preserve the dot (tmux accepts dots)." + (should (equal (cj/--ai-vterm-tmux-session-name "/home/cjennings/.emacs.d") + ".emacs.d"))) + +(ert-deftest test-ai-vterm--tmux-session-name-space-becomes-hyphen () + "Boundary: a space in the basename is replaced with a hyphen." + (should (equal (cj/--ai-vterm-tmux-session-name "/tmp/my work") + "my-work"))) + +(ert-deftest test-ai-vterm--tmux-session-name-multiple-spaces-collapse () + "Boundary: a run of whitespace collapses to a single hyphen." + (should (equal (cj/--ai-vterm-tmux-session-name "/tmp/a b\tc") + "a-b-c"))) + +(provide 'test-ai-vterm--tmux-session-name) +;;; test-ai-vterm--tmux-session-name.el ends here -- cgit v1.2.3