From 110440b6b3632b9bf0a9e5cf0838c9891f61e17a Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Wed, 1 Jul 2026 21:59:34 -0400 Subject: feat(ai-term): say so when M-SPC has no other agent to switch to With a single agent open and focused, the rotation wrapped back to the same agent and echoed a misleading "Agent: " as if it had swapped. Now it says there are no other ai-terms to switch to. A sole agent that is displayed but not selected still gets selected, and the no-agents picker fallback is unchanged. --- modules/ai-term.el | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'modules') diff --git a/modules/ai-term.el b/modules/ai-term.el index 6dfb669a..ecc2842b 100644 --- a/modules/ai-term.el +++ b/modules/ai-term.el @@ -1007,7 +1007,8 @@ its terminal, which reattaches the session). When an agent window is on screen, swap it to the next agent (wrapping after the last) and select it. When no agent is displayed but agents exist, show the first. When none are open, open the project picker to launch the first agent rather than -erroring. +erroring. When the sole agent is already focused, echo that there are +no other ai-terms to switch to instead of swapping to itself. Bound to M-SPC. Unlike C-; a a (toggle the most-recent agent on/off), this is the \"switch among existing agents\" surface; C-; a s opens the project @@ -1021,10 +1022,20 @@ picker and C-; a k closes an agent." (equal (cj/--ai-term-buffer-name d) current-name)) dirs))) (next-dir (cj/--ai-term-next-agent-dir current-dir dirs))) - (if (not next-dir) - ;; No agents open: launch the first via the project picker instead of - ;; erroring, so the swap key doubles as a "start an agent" key. - (cj/ai-term-pick-project) + (cond + ((not next-dir) + ;; No agents open: launch the first via the project picker instead of + ;; erroring, so the swap key doubles as a "start an agent" key. + (cj/ai-term-pick-project)) + ;; Sole agent, already focused: the rotation wraps back to the same + ;; agent, so a swap would be a no-op with a misleading "Agent:" echo. + ;; Say there's nowhere to go instead. A sole agent that is displayed + ;; but not selected still falls through and gets selected. + ((and current-dir + (equal next-dir current-dir) + (eq win (selected-window))) + (message "No other ai-terms to switch to")) + (t (let* ((name (cj/--ai-term-buffer-name next-dir)) (existing (get-buffer name))) ;; Live agent and an agent window is up: swap it into that window in @@ -1035,7 +1046,7 @@ picker and C-; a k closes an agent." (cj/--ai-term-show-or-create next-dir name) (let ((w (get-buffer-window name))) (when w (select-window w)))) - (message "Agent: %s" name))))) + (message "Agent: %s" name)))))) ;; ai-term lives under the C-; a prefix (vacated when gptel was archived). ;; The frequent "swap to the next agent" also gets M-SPC for a fast chord. -- cgit v1.2.3