- Do you like the AI features of Cursor AI Code Editor, but prefer to stay within Emacs?
- Aider is well-known, really good AI pair programming in the terminal.
- aider.el provides an interactive interface to communicate with Aider in emacs.
- Most of the Elisp code in this repository was generated by aider / aider.el.
- Pop-up Menu: No need to remember commands. (aider-transient-menu)
- Git Repository-Specific aider Sessions in Emacs: Automatically identify the Git repository of the current file and create a new aider session for it. Multiple aider sessions can exist for different Git repositories.
- More ways to add files to aider buffer
- Add current buffer file: (aider-add-current-file)
- Add all buffers in current window: (aider-add-files-in-current-window)
- Batch add files from dired buffer (aider-batch-add-dired-marked-files): Add multiple Dired marked files to the Aider buffer.
- Region-Based Explain / Refactor Support
- Explain: (aider-region-explain): You can 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
- And More: Add your own Elisp functions to support your use case. You can certainly ask aider / aider.el to do that.
- Install aider
- Install the dependency Transient using your package manager.
- Install aider.el with the following code:
(use-package aider
:straight (:host github :repo "tninja/aider.el" :files ("aider.el"))
:config
;; Use claude-3-5-sonnet cause it is best in aider benchmark
(setq aider-args '("--model" "anthropic/claude-3-5-sonnet-20241022"))
(setenv "ANTHROPIC_API_KEY" anthropic-api-key)
;; 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>)
;; ;;
Optional: Set a key binding for the transient menu
(global-set-key (kbd "C-c a") 'aider-transient-menu))
- Add the following code to your doom/packages.el
(package! aider :recipe (:host github :repo "tninja/aider.el" :files ("*.el")))
- Adjust and add the following code to your doom/config.el
(use-package aider
:config
(setq aider-args '("--model" "gpt-4o-mini")))
The aider prefix is “A”.
- Start and open the aider buffer:
[SPC] A o
- Add the current file with
[SPC] A a c
- You might want to try aider-helm.el. That file added support of command history and completion from helm.
- 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.
- To automatically enable aider-minor-mode to any file with aider inside filename
(add-hook 'find-file-hook
(lambda ()
(when (and (buffer-file-name)
(string-match-p "aider" (buffer-file-name)))
(aider-minor-mode 1))))
- 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).
- Inspired by, and Thanks to:
- ancilla.el: AI Coding Assistant support code generation / code rewrite / discussion
- chatgpt-shell: ChatGPT and DALL-E Emacs shells + Org Babel
- copilot.el: Emacs plugin for GitHub Copilot
- copilot-chat.el: Chat with GitHub Copilot in Emacs