branch: elpa/aidermacs commit 555d5fdbf7e36b50ed6a773a45a75eaf38155cb1 Author: Kang Tu <tni...@gmail.com> Commit: GitHub <nore...@github.com>
Feat: text send to aider buffer use bold text, to make it easier to read (#37) * feat(aider): add explain-symbol-under-point command * feat: add function to explain function under cursor * feat(aider): add support for Gemini model and function explanation command * docs(readme): reorganize and expand code explanation features * refactor: remove unused syntax table code in buffer setup * feat: add function to add files with same suffix under current dir * feat: Add function to add same-type files under a directory to Aider * feat: Add command to add files of same type under current directory * refactor: Use helper function for adding/reading current file in aider.el * refactor: Comment out unused functions in aider-main-menu-map * refactor: move git repository functions to separate file * refactor: Combine region and function explain commands into one * feat: Add function to refactor region or function based on selection * feat: Add function to refactor function or region based on selection * refactor(ui): simplify code change menu options * refactor(doom): update menu itemsc * feat: append region text to question in `aider-ask-question` * fix: Escape newlines in region text for `aider-ask-question` * refactor: Extract string escaping logic into dedicated function This commit refactors the string escaping logic in `aider.el` into a dedicated function, `aider--escape-string-for-aider`. This improves code readability, maintainability, and reusability by centralizing the escaping logic in one place. The function replaces newline characters with escaped newlines, and is now used in `aider-ask-question`, `aider-debug-exception`, `aider-region-refactor-generate-command`, and `aider-region-explain`. The `aider-plain-read-string` function no longer per [...] * refactor: Centralize newline escaping in `aider--send-command` * fix: Remove extra parenthesis in message call in aider--send-command * bug fix * refactor: Remove unnecessary parentheses in `aider-send-command` * refactor: Refactor aider-send-paragraph to send lines individually * refactor: Use dash library for list manipulation * bug fix * fix: improve `aider-send-paragraph` to handle newlines correctly * fix: Send whole buffer content when no files are added to chat * ``` refactor: Only send non-empty lines in `aider-send-paragraph` ``` * refactor: Send non-empty lines to aider in `aider-send-current-test` * refactor: Improve `aider-send-paragraph` to send whole paragraph to aider * refactor: remove dash.el dependency * feat(menu): add toggle for file read-only status in transient menu refactor: Rename gptel-menu to aider-menu in comments and docstrings refactor: Simplify aider--add-file-type and read-only infix definition refactor: Update transient menu key from `:shortarg` to `:key` refactor: Update aider file type class and read-only infix to use transient-lisp-variable fix: Update transient format specifier from %s to %v in aider--add-file-type style(ui): improve readability of file mode toggle in transient menu * refactor: Simplify add file transient menu and remove redundant option * refactor: Modify file-adding functions to respect read-only flag * docs: update docstring for aider-current-file-read-only function * docs: update transient menu screenshot * typodocs: fix typo in README by removing duplicate 'of' * docs: Improve README.org language and clarity * docs: Improve wording for aider-minor-mode description in README * feat: Add bold highlighting for commands sent to aider buffer * Revert "feat: Add bold highlighting for commands sent to aider buffer" This reverts commit 45238185b59d2a68315a2dfe36692d32e328011a. * feat: Add text highlighting for commands sent to aider buffer * refactor: Improve text highlighting and buffer insertion in comint send function * refactor: Improve text highlighting in comint buffer using comint-output-filter * docs: Translate Chinese comments to English in aider.el function * docs: update file operation mode toggle documentation in README --------- Co-authored-by: Kang Tu <kang...@apple.com> --- README.org | 23 ++++++++++++----------- aider.el | 31 ++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/README.org b/README.org index 2563d1d6df..78bd006add 100644 --- a/README.org +++ b/README.org @@ -2,7 +2,7 @@ * Introduction -- Do you like the AI features of the [[https://www.cursor.com/][Cursor AI Code Editor]] but prefer to stay within Emacs? +- Do you enjoy the AI features of the [[https://www.cursor.com/][Cursor AI Code Editor]] but prefer working within Emacs? - [[https://github.com/paul-gauthier/aider][Aider]] is a well-known and highly effective AI pair programming tool for the terminal. @@ -15,17 +15,17 @@ [[file:./transient_menu.png]] -- Following command integrated to aider menu +- The following commands are integrated into the aider menu: *** Aider session management: - - (`aider-run-aider`): Create a comint-based, *git repo specific aider session* for interactive conversation. - - Git repository identification is based on the file path of of the current file - - Multiple Aider sessions can exist for different Git repositories + - (`aider-run-aider`): Creates a comint-based, *git repo-specific Aider session* for interactive conversation. + - Git repository identification is based on the current file's path + - Multiple Aider sessions can run simultaneously for different Git repositories - (`aider-switch-to-buffer`): Switch to the Aider buffer. *** More ways to add files to the Aider buffer: + - use "=" in the menu to toggle add file between read-write mode and read-only mode - (`aider-add-current-file`): Add the current buffer file. - - (`aider-current-file-read-only`): Add the current buffer file as read-only. - (`aider-add-files-in-current-window`): Add all buffers in the current window. - (`aider-add-same-type-files-under-dir`): Add all files with the same suffix as the current file under the current directory to Aider. - (`aider-batch-add-dired-marked-files`): Add multiple Dired marked files to the Aider buffer. @@ -40,7 +40,8 @@ *** Support for Test Driven Development: - (`aider-fix-failing-test-under-cursor`): Place cursor on a failing test function and ask Aider to analyze and fix the code to make tests pass. -*** And More: Add your own Elisp functions to support your use case. You can certainly ask Aider / `aider.el` to do that. +*** And More: +You can add your own Elisp functions to support your specific use cases. Feel free to ask Aider/`aider.el` to help you create them. * Installation @@ -122,9 +123,9 @@ You can enable Helm-based completion in two ways: *** Aider script interactive mode: aider-minor-mode -- If you enjoy writing aider command in a separate file and send them to aider session, just like working on python or R script and send code block into REPL, you might want to try aider-minor-mode. It by default bind C-c C-n to send current line to aider session, and C-c C-c to send current region to aider session. +- If you prefer writing Aider commands in a separate file and sending them to an Aider session (similar to working with Python or R scripts and sending code blocks to a REPL), you might want to try aider-minor-mode. It by default bind C-c C-n to send current line to aider session, and C-c C-c to send current region to aider session. - Enable aider-minor-mode for your editing buffer - - To automatically enable aider-minor-mode to any file with aider inside filename + - To automatically enable aider-minor-mode for any file with "aider" in its filename: #+BEGIN_SRC emacs-lisp (add-hook 'find-file-hook @@ -138,8 +139,8 @@ You can enable Helm-based completion in two ways: [[file:./screenshot.png]] -- In the above screenshot, aider was asked to generate an aider-help function and add the corresponding entry to the menu (top right window). -- aider received the command and generated the commit for it (bottom left). +- The screenshot above shows Aider being asked to generate an aider-help function and add its corresponding entry to the menu (top right window). +- Aider successfully received the command and generated the appropriate commit (bottom left). * [[./examples][Example Application Written with aider.el]] diff --git a/aider.el b/aider.el index f0238408c0..e64984a73b 100644 --- a/aider.el +++ b/aider.el @@ -37,6 +37,11 @@ "Face for command separator in aider." :group 'aider) +(defface aider-command-text + '((t :inherit bold)) + "Face for commands sent to aider buffer." + :group 'aider) + (defvar aider-font-lock-keywords '(("^\x2500+\n?" 0 '(face aider-command-separator) t) ("^\x2500+" 0 '(face nil display (space :width 2)))) "Font lock keywords for aider buffer.") @@ -210,17 +215,29 @@ If not in a git repository, an error is raised." ;; Function to send large text (> 1024 chars) to the Aider buffer (defun aider--comint-send-large-string (buffer text) - "Send large TEXT to the comint buffer in chunks of 1000 characters." + "Send large TEXT to the comint buffer in chunks of 1000 characters. +Ensure proper highlighting of the text in the buffer." (let ((chunk-size 1000) (pos 0) (process (get-buffer-process buffer))) (while (< pos (length text)) - (process-send-string - process - (substring text pos (min (+ pos chunk-size) (length text)))) - (sleep-for 0.1) - (message "Sent command to aider buffer: %s" (substring text pos (min (+ pos chunk-size) (length text)))) - (setq pos (+ pos chunk-size))))) + (let* ((end-pos (min (+ pos chunk-size) (length text))) + (chunk (substring text pos end-pos))) + ;; Insert text into buffer and ensure highlighting + (with-current-buffer buffer + (let ((inhibit-read-only t) + (current-point (process-mark process))) + (goto-char current-point) + ;; Use comint-output-filter to ensure proper text property handling + (comint-output-filter process (propertize chunk + 'face 'aider-command-text + 'font-lock-face 'aider-command-text + 'rear-nonsticky t)))) + ;; Send raw text to process + (process-send-string process chunk) + (sleep-for 0.1) + (message "Sent command to aider buffer: %s" chunk) + (setq pos end-pos))))) ;; Shared helper function to send commands to corresponding aider buffer (defun aider--send-command (command &optional switch-to-buffer)