branch: elpa/aidermacs
commit 571f9ad495799c901b074bba300d81b92bd9d736
Merge: d230cd5f95 4b94390318
Author: Matthew Zeng <matthew...@posteo.net>
Commit: GitHub <nore...@github.com>

    Merge pull request #20 from CeleritasCelery/auto-start
    
    Run Aider automatically if it is not already running
---
 aidermacs.el | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/aidermacs.el b/aidermacs.el
index 1f18770790..00828920b0 100644
--- a/aidermacs.el
+++ b/aidermacs.el
@@ -267,14 +267,14 @@ This is useful for working in monorepos where you want to 
limit aider's scope."
   "Send COMMAND to the corresponding aidermacs process.
 If SWITCH-TO-BUFFER is non-nil, switch to the aidermacs buffer.
 If CALLBACK is provided, it will be called with the command output when 
available."
-  (if-let ((aidermacs-buffer (get-buffer (aidermacs-buffer-name))))
-      (let ((processed-command (aidermacs--process-message-if-multi-line 
command)))
-        (when (and switch-to-buffer aidermacs-buffer)
-          (aidermacs-switch-to-buffer))
-        (aidermacs--send-command-backend aidermacs-buffer processed-command 
callback)
-        (when (and switch-to-buffer (not (string= (buffer-name) 
(aidermacs-buffer-name))))
-          (aidermacs-switch-to-buffer)))
-    (message "Buffer %s does not exist. Please start aidermacs with 'M-x 
aidermacs-run'." aidermacs-buffer-name)))
+  (let* ((buffer-name (aidermacs-buffer-name))
+         (buffer (or (get-buffer buffer-name)
+                     (progn (aidermacs-run)
+                            (get-buffer buffer-name))))
+         (processed-command (aidermacs--process-message-if-multi-line 
command)))
+    (aidermacs--send-command-backend buffer processed-command callback)
+    (when (and switch-to-buffer (not (string= (buffer-name) buffer-name)))
+      (aidermacs-switch-to-buffer))))
 
 
 ;; Function to switch to the aidermacs buffer

Reply via email to