branch: elpa/aidermacs commit 99fbe5a37c517d4dedbdc39205fb50eb61e583fd Author: Your Name (aider) <y...@example.com> Commit: Your Name (aider) <y...@example.com>
refactor: extract buffer name logic to `aider-buffer-name-from-git-repo-path` --- aider.el | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/aider.el b/aider.el index 61d1bda7ea..cf44e71029 100644 --- a/aider.el +++ b/aider.el @@ -62,6 +62,13 @@ This function can be customized or redefined by the user." ;; Removed the default key binding ;; (global-set-key (kbd "C-c a") 'aider-transient-menu) +(defun aider-buffer-name-from-git-repo-path (git-repo-path) + "Generate the Aider buffer name based on the GIT-REPO-PATH. +If not in a git repository, an error is raised." + (let* ((home-path (expand-file-name "~")) + (relative-path (substring git-repo-path (length home-path)))) + (format "*aider:%s*" (concat "~" (replace-regexp-in-string "\n" "" relative-path))))) + (defun aider-buffer-name () "Generate the Aider buffer name based on the path from the home folder to the git repo of the current active buffer using a git command. If not in a git repository, an error is raised." @@ -69,9 +76,7 @@ If not in a git repository, an error is raised." (git-repo-path (shell-command-to-string "git rev-parse --show-toplevel"))) (if (string-match-p "fatal" git-repo-path) (error "Not in a git repository") - (let* ((home-path (expand-file-name "~")) - (relative-path (substring git-repo-path (length home-path)))) - (format "*aider:%s*" (concat "~" (replace-regexp-in-string "\n" "" relative-path))))))) + (aider-buffer-name-from-git-repo-path git-repo-path)))) (defun aider-run-aider () "Create a comint-based buffer and run 'aider' for interactive conversation."