branch: elpa/aidermacs commit 51a4e839876823330518036b482e2a282964ede0 Author: Mingde (Matthew) Zeng <matthew...@posteo.net> Commit: Mingde (Matthew) Zeng <matthew...@posteo.net>
Ensure aidermacs--send-command runs with a running aider session Signed-off-by: Mingde (Matthew) Zeng <matthew...@posteo.net> --- aidermacs-models.el | 9 --------- aidermacs.el | 11 ++++++++--- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/aidermacs-models.el b/aidermacs-models.el index f60a1274da..ec24e2c730 100644 --- a/aidermacs-models.el +++ b/aidermacs-models.el @@ -224,19 +224,10 @@ This is useful when available models have changed." (setq aidermacs--cached-models nil) (message "Model cache cleared")) -;;;###autoload (defun aidermacs-change-model (&optional arg) "Interactively select and change AI model in current aidermacs session. With prefix ARG, only allow setting the weak model." (interactive "P") - ;; Ensure a session is running and initialized - (let ((buffer-name (aidermacs-get-buffer-name))) - (unless (and (get-buffer buffer-name) - (process-live-p (get-buffer-process buffer-name))) - (aidermacs-run) - ;; Wait briefly for the prompt to appear - (sit-for 1))) - (unless aidermacs--cached-models (aidermacs--get-available-models)) (aidermacs--select-model arg)) diff --git a/aidermacs.el b/aidermacs.el index e684c04877..b4f02faebd 100644 --- a/aidermacs.el +++ b/aidermacs.el @@ -348,9 +348,14 @@ If USE-EXISTING is non-nil, use an existing buffer instead of creating new. If REDIRECT is non-nil it redirects the output (hidden) for comint backend. If CALLBACK is non-nil it will be called after the command finishes." (let* ((buffer-name (aidermacs-get-buffer-name use-existing)) - (buffer (or (get-buffer buffer-name) - (progn (aidermacs-run) - (get-buffer buffer-name)))) + (buffer (if (and (get-buffer buffer-name) + (process-live-p (get-buffer-process buffer-name))) + (get-buffer buffer-name) + (when (get-buffer buffer-name) + (kill-buffer buffer-name)) + (aidermacs-run) + (sit-for 1) + (get-buffer buffer-name))) (processed-command (aidermacs--process-message-if-multi-line command))) ;; Check if command may edit files and prepare accordingly (with-current-buffer buffer