branch: elpa/aidermacs commit 7f3601920b9f457cb3784fdf1300dce8ebb7918e Author: Kang Tu <tni...@gmail.com> Commit: GitHub <nore...@github.com>
Feat: Add two code reading helper functions (#30) * 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 --- README.org | 13 +++++++++---- aider.el | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/README.org b/README.org index b028e6b288..bcd32d62ab 100644 --- a/README.org +++ b/README.org @@ -22,12 +22,14 @@ - Add all buffers in the current window: (`aider-add-files-in-current-window`) - Batch add files from the Dired buffer: (`aider-batch-add-dired-marked-files`) Add multiple Dired marked files to the Aider buffer. -- Refactor function under the cursor: +- Refactor region / function: + - (`aider-region-refactor`): Ask Aider to refactor it given your input instruction. - (`aider-function-refactor`): Ask Aider to refactor the function under the cursor given your instruction. -- Region-Based Explain / Refactor Support: - - Explain: (`aider-region-explain`): Select a region (e.g., a code block) in a file and ask Aider to explain it. - - Refactor: (`aider-region-refactor`): Ask Aider to refactor it given your input instruction. +- Explain code + - (`aider-region-explain`): Select a region (e.g., a code block) in a file and ask Aider to explain it. + - (`aider-function-explain`): Place the cursor on a function and ask Aider to explain it. + - (`aider-explain-symbol-under-point`): Ask Aider to explain the symbol under cursor, given the line as context. - Support for Test Driven Development: - Fix Tests: (`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. @@ -51,6 +53,9 @@ ;; Or use chatgpt model since it is most well known ;; (setq aider-args '("--model" "gpt-4o-mini")) ;; (setenv "OPENAI_API_KEY" <your-openai-api-key>) + ;; Or use gemini v2 model since it is very good and free + ;; (setq aider-args '("--model" "gemini/gemini-exp-1206")) + ;; (setenv "GEMINI_API_KEY" <your-gemini-api-key>) ;; ;; Optional: Set a key binding for the transient menu (global-set-key (kbd "C-c a") 'aider-transient-menu)) diff --git a/aider.el b/aider.el index 56c49a8861..e102472626 100644 --- a/aider.el +++ b/aider.el @@ -86,6 +86,8 @@ This function can be customized or redefined by the user." ["Discussion" ("q" "Ask Question" aider-ask-question) ("e" "Explain Code in Selected Region" aider-region-explain) + ("E" "Explain Function Under Cursor" aider-function-explain) + ("p" "Explain Symbol Under Cursor" aider-explain-symbol-under-point) ("d" "Debug Exception" aider-debug-exception) ] ["Other" @@ -385,6 +387,31 @@ The command will be formatted as \"/ask \" followed by the text from the selecte (aider--send-command command t)) (message "No region selected."))) +;; New function to ask Aider to explain the function under the cursor +;;;###autoload +(defun aider-function-explain () + "Ask Aider to explain the function under the cursor." + (interactive) + (if-let ((function-name (which-function))) + (let ((command (format "/ask Please explain the function: %s" function-name))) + (aider-add-current-file) + (aider--send-command command t)) + (message "No function found at cursor position."))) + +;; New function to explain the symbol at line +;;;###autoload +(defun aider-explain-symbol-under-point () + "Ask Aider to explain symbol under point, given the code line as background info." + (interactive) + (let* ((symbol (thing-at-point 'symbol)) + (line (buffer-substring-no-properties + (line-beginning-position) + (line-end-position))) + (prompt (format "/ask Please explain what '%s' means in the context of this code line: %s" + symbol line))) + (aider-add-current-file) + (aider--send-command prompt t))) + (defun aider-send-command-with-prefix (prefix command) "Send COMMAND to the Aider buffer prefixed with PREFIX." (aider-add-current-file)