branch: elpa/aidermacs commit d76bc38c0b0bfc0b4fc6599254fb21ca2cd98370 Author: Mingde (Matthew) Zeng <matthew...@posteo.net> Commit: Mingde (Matthew) Zeng <matthew...@posteo.net>
Improve aidermacs--detect-edited-files --- aidermacs.el | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/aidermacs.el b/aidermacs.el index 34bbd7e0c8..cdf8f90e1c 100644 --- a/aidermacs.el +++ b/aidermacs.el @@ -378,24 +378,40 @@ the next file in the ediff queue if any remain." (add-hook 'ediff-quit-hook #'aidermacs--ediff-quit-handler)) (defun aidermacs--detect-edited-files () - "Detect files edited by Aider by comparing buffer contents. -Returns a list of files that have been modified compared to their -pre-edit state stored in temporary buffers." - (let ((edited-files nil)) - (dolist (file-pair aidermacs--pre-edit-file-buffers) - (let* ((filename (car file-pair)) - (pre-edit-buffer (cdr file-pair)) - (current-content (with-temp-buffer - (when (file-exists-p filename) - (insert-file-contents filename)) - (buffer-string))) - (original-content (with-current-buffer pre-edit-buffer - (buffer-string)))) - (unless (equal original-content current-content) - (push filename edited-files)))) - ;; Return the list of edited files - (nreverse edited-files))) - + "Parse current output to find files edited by Aider. +Returns a list of files that have been modified according to the output." + (let ((edited-files nil) + (output aidermacs--current-output)) + (message "Detecting edited files from output...") + (when output + (let ((lines (split-string output "\n")) + (last-line "")) + (dolist (line lines) + (cond + ;; Case 1: Look for "Applied edit to <filename>" pattern + ((string-match "Applied edit to \\(\\./\\)?\\(.+\\)" line) + (when-let ((file (match-string 2 line))) + (message "Found edited file (applied edit): %s" file) + (push file edited-files))) + + ;; Case 2: Look for a filename followed by triple backticks on next line + ((string-match "^```" line) + (let ((potential-file (string-trim last-line))) + (when (not (string-empty-p potential-file)) + (message "Found potential file (code block): %s" potential-file) + (push potential-file edited-files))))) + + (setq last-line line)))) + + ;; Filter the list to only include valid files + (let* ((project-root (aidermacs-project-root)) + (unique-files (delete-dups edited-files)) + (valid-files (cl-remove-if-not + (lambda (file) + (file-exists-p (expand-file-name file project-root))) + unique-files))) + (message "Detected valid edited files: %s" valid-files) + (nreverse valid-files)))) (defvar-local aidermacs--ediff-queue nil "Buffer-local queue of files waiting to be processed by ediff.")