branch: elpa/aidermacs commit 9b6fc626265a21daf281cf76dba660aa495ad0cf Author: tninja <tni...@gmail.com> Commit: tninja <tni...@gmail.com>
update command and test --- aider.el | 7 +++++-- test_aider.el | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/aider.el b/aider.el index 01936b5c98..59631b8cfe 100644 --- a/aider.el +++ b/aider.el @@ -201,8 +201,11 @@ replacing all newline characters except for the one at the end." (defun aider-region-refactor-generate-command (region-text function-name user-command) "Generate the command string based on REGION-TEXT, FUNCTION-NAME, and USER-COMMAND." (let ((processed-region-text (replace-regexp-in-string "\n" "\\\\n" region-text))) - (format "/architect \"in function %s, for the following code block, %s: %s\"\n" - function-name user-command processed-region-text))) + (if function-name + (format "/architect \"in function %s, for the following code block, %s: %s\"\n" + function-name user-command processed-region-text) + (format "/architect \"for the following code block, %s: %s\"\n" + user-command processed-region-text)))) (defun aider-region-refactor () "Get a command from the user and send it to the corresponding aider comint buffer based on the selected region. diff --git a/test_aider.el b/test_aider.el index e0798d1c92..db4060bc2f 100644 --- a/test_aider.el +++ b/test_aider.el @@ -11,3 +11,13 @@ "*aider:~/git/repo/subdir*")) (should (equal (aider-buffer-name-from-git-repo-path "/home/username/git/repo/subdir" "/home/username") "*aider:~/git/repo/subdir*"))) + +(ert-deftest test-aider-region-refactor-generate-command () + "Test the aider-region-refactor-generate-command function." + (should (equal (aider-region-refactor-generate-command "some code" + "my-function" "refactor this") + "/architect \"in function my-function, for the following code block, refactor this: some code\"\n")) + (should (equal (aider-region-refactor-generate-command "some code" nil + "make it more functional") + "/architect \"for the following code block, make it more functional: some code\"\n")) + )