[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/aidermacs c3a9520da7 301/466: Use redirection for sending
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/aidermacs c3a9520da7 301/466: Use redirection for sending commands to aider |
Date: |
Sat, 15 Mar 2025 19:16:45 -0400 (EDT) |
branch: elpa/aidermacs
commit c3a9520da788f098fe40354eb834869a0f18250e
Author: Troy Hinckley <t.macman@gmail.com>
Commit: Troy Hinckley <t.macman@gmail.com>
Use redirection for sending commands to aider
I changed to use redirection for drop files. However I don't know if I
fully understand all the
systems at play, so please double check.
Added ./ to the start of the dropped file to distinguish files that have
the same
suffix. (i.e. foo.py and test_foo.py would both drop if you run `/drop
foo.py`).
Also, the ls command will list what files are in the repo but not in the
chat. We should be able to
parse that and create a command to easily add new files from the list.
---
aidermacs-backend-comint.el | 32 ++++++++++++++++++--------------
aidermacs-backends.el | 20 ++++++++++++++------
aidermacs.el | 34 +++++++++++++++++++++-------------
3 files changed, 53 insertions(+), 33 deletions(-)
diff --git a/aidermacs-backend-comint.el b/aidermacs-backend-comint.el
index cfa098b5dd..bc2d259368 100644
--- a/aidermacs-backend-comint.el
+++ b/aidermacs-backend-comint.el
@@ -221,24 +221,11 @@ This allows for multi-line input without sending the
command."
(when (bufferp aidermacs--syntax-work-buffer)
(kill-buffer aidermacs--syntax-work-buffer)))
-(defvar-local aidermacs--comint-output-temp ""
- "Temporary output variable storing the raw output string.")
-
(defun aidermacs-input-sender (proc string)
"Reset font-lock state before executing a command."
(aidermacs-reset-font-lock-state)
(comint-simple-send proc (aidermacs--process-message-if-multi-line string)))
-(defun aidermacs--comint-output-filter (output)
- "Accumulate OUTPUT string until a prompt is detected, then store it."
- (unless (string-empty-p output)
- (setq aidermacs--comint-output-temp
- (concat aidermacs--comint-output-temp (substring-no-properties
output)))
- ;; Check if the output contains a prompt
- (when (string-match-p "\n[^[:space:]]*>[[:space:]]$"
aidermacs--comint-output-temp)
- (aidermacs--store-output aidermacs--comint-output-temp)
- (setq aidermacs--comint-output-temp ""))))
-
(defun aidermacs-run-comint (program args buffer-name)
"Create a comint-based buffer and run aidermacs PROGRAM with ARGS in
BUFFER-NAME."
(let ((comint-terminfo-terminal "eterm-color")
@@ -247,12 +234,12 @@ This allows for multi-line input without sending the
command."
(apply 'make-comint-in-buffer "aidermacs" buffer-name program nil args)
(with-current-buffer buffer-name
(comint-mode)
+ (setq-local comint-prompt-regexp "^> $")
(setq-local comint-input-sender 'aidermacs-input-sender)
(setq aidermacs--syntax-work-buffer
(get-buffer-create (concat " *aidermacs-syntax" buffer-name)))
(add-hook 'kill-buffer-hook #'aidermacs-kill-buffer nil t)
(add-hook 'comint-output-filter-functions #'aidermacs-fontify-blocks
100 t)
- (add-hook 'comint-output-filter-functions
#'aidermacs--comint-output-filter)
(let ((local-map (make-sparse-keymap)))
(set-keymap-parent local-map comint-mode-map)
(define-key local-map (kbd aidermacs-comint-multiline-newline-key)
#'comint-accumulate)
@@ -273,6 +260,23 @@ This allows for multi-line input without sending the
command."
(set-marker (process-mark process) (point))
(comint-send-string process (concat command "\n")))))
+(defun aidermacs--redirect-send-command-comint (buffer command)
+ "Send COMMAND to the aidermacs comint BUFFER and collect result into
OUTPUT-BUFFER."
+ (with-current-buffer buffer
+ (let ((process (get-buffer-process buffer))
+ (output-buffer (get-buffer-create " *aider-redirect-buffer*")))
+ (with-current-buffer output-buffer
+ (erase-buffer))
+ (goto-char (process-mark process))
+ (comint-redirect-send-command command output-buffer nil t)
+ (unwind-protect
+ (while (or quit-flag (null comint-redirect-completed))
+ (accept-process-output nil 0.1))
+ (unless comint-redirect-completed
+ (comint-redirect-cleanup)))
+ (aidermacs--store-output (with-current-buffer output-buffer
+ (buffer-string))))))
+
(provide 'aidermacs-backend-comint)
;;; aidermacs-backend-comint.el ends here
diff --git a/aidermacs-backends.el b/aidermacs-backends.el
index 88667c5612..e2e6a1952c 100644
--- a/aidermacs-backends.el
+++ b/aidermacs-backends.el
@@ -92,17 +92,25 @@ and BUFFER-NAME is the name for the aidermacs buffer."
(t
(aidermacs-run-comint program args buffer-name))))
-(defun aidermacs--send-command-backend (buffer command &optional callback)
+(defun aidermacs--send-command-backend (buffer command)
+ "Send COMMAND to BUFFER using the appropriate backend.
+CALLBACK if provided will be called with the command output when available."
+ (setq aidermacs--last-command command
+ aidermacs--current-output nil
+ aidermacs--current-callback nil)
+ (if (eq aidermacs-backend 'vterm)
+ (aidermacs--send-command-vterm buffer command)
+ (aidermacs--send-command-comint buffer command)))
+
+(defun aidermacs--redirect-send-command-backend (buffer command &optional
callback)
"Send COMMAND to BUFFER using the appropriate backend.
CALLBACK if provided will be called with the command output when available."
(setq aidermacs--last-command command
aidermacs--current-output nil
aidermacs--current-callback callback)
- (cond
- ((eq aidermacs-backend 'vterm)
- (aidermacs--send-command-vterm buffer command))
- (t
- (aidermacs--send-command-comint buffer command))))
+ (if (eq aidermacs-backend 'vterm)
+ (aidermacs--send-command-vterm buffer command)
+ (aidermacs--redirect-send-command-comint buffer command)))
(provide 'aidermacs-backends)
diff --git a/aidermacs.el b/aidermacs.el
index 00828920b0..6157bb6b1a 100644
--- a/aidermacs.el
+++ b/aidermacs.el
@@ -263,19 +263,28 @@ This is useful for working in monorepos where you want to
limit aider's scope."
(default-directory (file-truename default-directory)))
(aidermacs-run nil)))
-(defun aidermacs--send-command (command &optional switch-to-buffer callback)
+(defun aidermacs--send-command (command &optional switch-to-buffer)
"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 SWITCH-TO-BUFFER is non-nil, switch to the aidermacs buffer."
(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)
+ (aidermacs--send-command-backend buffer processed-command)
(when (and switch-to-buffer (not (string= (buffer-name) buffer-name)))
(aidermacs-switch-to-buffer))))
+(defun aidermacs--redirect-send-command (command callback)
+ "Send COMMAND to the corresponding aidermacs process in the background.
+CALLBACK will be called with the command output when available."
+ (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--redirect-send-command-backend buffer processed-command
callback)))
+
;; Function to switch to the aidermacs buffer
;;;###autoload
@@ -434,8 +443,8 @@ Returns a deduplicated list of such file names."
"List all files currently added to the chat session.
Sends the \"/ls\" command and returns the list of files via callback."
(interactive)
- (aidermacs--send-command
- "/ls" t
+ (aidermacs--redirect-send-command
+ "/ls"
(lambda (output)
(let ((files (aidermacs--parse-ls-output output)))
(message "%s" (prin1-to-string files))
@@ -445,14 +454,13 @@ Sends the \"/ls\" command and returns the list of files
via callback."
(defun aidermacs-drop-file ()
"Drop a file from the chat session by selecting from currently added files."
(interactive)
- (aidermacs--send-command
- "/ls" t
+ (aidermacs--redirect-send-command
+ "/ls"
(lambda (output)
- (with-local-quit
- (if-let* ((files (aidermacs--parse-ls-output output))
- (file (completing-read "Select file to drop: " files nil t)))
- (aidermacs--send-command (format "/drop %s" file))
- (message "No files available to drop"))))))
+ (if-let* ((files (aidermacs--parse-ls-output output))
+ (file (completing-read "Select file to drop: " files nil t)))
+ (aidermacs--send-command (format "/drop ./%s" file))
+ (message "No files available to drop")))))
;;;###autoload
- [nongnu] elpa/aidermacs 7ebdb2925f 267/466: docs: Update README with new transient menu and file management features, (continued)
- [nongnu] elpa/aidermacs 7ebdb2925f 267/466: docs: Update README with new transient menu and file management features, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs 80169ffd21 274/466: Update README, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs f54aa4088c 275/466: Update README, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs 002a47e89e 285/466: Use aider command to get supported models, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs c3ec966f0a 286/466: Refactor to use aidermacs--send-command callback effectively, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs 142a154b5f 295/466: Prepend aidermacs-- to fetch-openai-compatible-models, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs 791cb45315 292/466: Refactor aidermacs--get-context-command, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs 34fecf9703 284/466: fix: use aidermacs-read-string instead of aidermacs-plain-read-string in aidermacs-debug, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs d5ccb2d10c 291/466: Disable auto-commits by default in aidermacs, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs d230cd5f95 297/466: Merge pull request #19 from CeleritasCelery/dumb-text, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs c3a9520da7 301/466: Use redirection for sending commands to aider,
ELPA Syncer <=
- [nongnu] elpa/aidermacs 4fad406c4d 302/466: Rename to aidermacs--send-command-redirect-comint, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs 93340e76f9 306/466: Add aidermacs-default-model and aidermacs-args options, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs 4e14215119 310/466: Fix #16 handle read-only files in ls, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs e06f47cea7 331/466: Merge pull request #29 from jfeser/main, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs 090eebdbf5 334/466: Fix more lintings, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs fb59e9bc87 338/466: Update README, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs 5e167323b8 352/466: Fix README, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs ea47980ed7 361/466: fix: Fix string formatting in message function, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs 6ae6becbfb 374/466: Simplify UI to ask question and explain this code, ELPA Syncer, 2025/03/15
- [nongnu] elpa/aidermacs 3a7e313ce0 317/466: Fix comint-prompt-regexp, ELPA Syncer, 2025/03/15