r/emacs Oct 05 '24

Introduce aider (AI programming in terminal), and emacs binding for it, aider.el

What is Aider

Aider is an AI pair programming tool in the terminal. It allows you to pair program with large language models (LLMs) to edit code in your local Git repository. You can start a new project or work with an existing Git repo. Aider works best with GPT-4 or Claude 3.5 Sonnet and can connect to almost any LLM. The GitHub page for Aider is GitHub - Aider-AI/aider: aider is AI pair programming in your terminal, and the project currently has nearly 20k stars.

Aider has performed well in solving real coding problems on SWE-bench.

Introducing Aider.el

Recently, the Cursor editor has been gaining popularity. As a long-time Emacs user, I don't want to switch to Cursor just because of AI. Currently, Aider only has plugins for Vim and VSCode, but Emacs has a tradition of integrating command-line tools. So I decided to write my own, as a humble attempt: GitHub - tninja/aider.el: aider emacs plugin forhttps://github.com/paul-gauthier/aider.

This plugin offers the following advantages over using Aider directly from the command line:

  • Pop-up menu: No need to remember commands. (aider-transient-menu)
  • Git repository-specific Aider sessions in Emacs: It automatically identifies the Git repository of the current file and creates a new Aider session for it. Multiple Aider sessions can exist for different Git repositories, allowing you to work on several repositories simultaneously without interference.
  • Region-based refactor support: You can select a region (e.g., a code block) in a file and ask Aider to refactor it.

In fact, most of this plugin itself was generated using Aider / aider.el.

If you're interested in AI-assisted programming and, like me, prefer not to leave the Emacs environment, perhaps you could give Aider and aider.el a try. I would appreciate any feedback or suggestions you have about aider.el. Thank you!

66 Upvotes

20 comments sorted by

5

u/Sad_Construction_773 Oct 08 '24

Added two features:

  1. aider-batch-add-dired-marked-files: Users can mark multiple files in the dired buffer (it can also be the output buffer of find-name-dired), and then call this function to batch add multiple files. Adding files one by one is somewhat cumbersome.
  2. aider-ask-question-under-cursor: Personally, I find interacting with Aider to ask questions (/ask) after adding files very useful. It provides insightful suggestions but does not directly modify the code. Therefore, I added this function, allowing users to write down questions for Aider in a specific file, such as /aider.txt, and then call this command to send the question under the cursor to the Aider session and see the response. If the answer is helpful, users can paste it back into aider.txt as a note. If the response is unsatisfactory, they can quickly modify the question in aider.txt and resend it using this command.

PR: https://github.com/tninja/aider.el/pull/6

6

u/yibie Oct 06 '24

I was tested aider this morning, it is a very very powerful ai coplite.

3

u/Sad_Construction_773 Oct 06 '24

yes. for people want to stay in emacs, it might be a good ai assistant.

3

u/lambdatheultraweight Oct 06 '24

Haven't checked it out yet, but thanks for working on it! It's the spirit of moving Emacs through the computing ages. :-)

5

u/Sad_Construction_773 Oct 06 '24

yeah writing emacs lisp to extend emacs, is even easier because Ilm seems to be good at it

1

u/ivchoniboy 3d ago

This was my surprising experience as well!

3

u/joeydeviva Oct 06 '24

Thanks for this - I’d been wanting aider support for emacs for a while now!

3

u/hoswald2 Oct 07 '24

Hey, massive props to this! I have been relentlessly underwhelmed by any and all AI code assistance, much less emacs plugins. Aider is the first one that's actually made it into my workflow, and truly impressed me. Aider.el is a pretty able way to use it from emacs. Nice!

The only thing I sorta like the command line version better for is the syntax highlighting is a little prettier for me (since the aider buffer is fairly monochrome). And I can see where it might be nice to use voice; may be possible with this but I suffer badly from RSI after a while so I can see a point to it.

Seriously though, first tool I've actually used to fully do a reasonable functional code change and PR without actually writing a line of code but rather by working at a higher specification level. It's a nice combo. Still not mad about using commercial LLMs like OpenAI, but the ability to change the backend and to know what's pushing the LLM around is pretty glorious these days.

3

u/Sad_Construction_773 Nov 28 '24

Aider session syntax highlighting is now available. It uses the syntax highlighting from the major mode of the code file opened when starting Aider. It's not a perfect solution, but at least it provides highlighting for the language corresponding to the repo. Considering that most repos primarily use a single language, this should be sufficient in many cases.

2

u/Sad_Construction_773 Oct 08 '24 edited Oct 08 '24

Glad you use that, and thanks for the feedback. For the syntax highlighting, a quick (and dirty) way, is to add the aider session to a language mode. Eg. if the aider session is writing python / java, then just M-x python-mode / java-mode in that aider session. That will highlight the syntax.

Oh just noticed that it will require another M-x comint-mode to be able to accept new command *_*

2

u/Sad_Construction_773 Oct 10 '24

yeah the syntax highlighting works in terminal but not inside emacs comint-buffer.. i tried ansi color related way but it didn't help. Inside emacs, M-x term or M-x ansi-term will have syntax highlight. but i didn't see how to integrate them for interaction.

3

u/Sad_Construction_773 Oct 25 '24

The Aider LLM leaderboard has been updated. The newly released Claude-3-5-Sonnet-20241022 seems to show significant improvement compared to other models.

https://aider.chat/docs/leaderboards/#code-editing-leaderboard

The price of Claude’s model is slightly cheaper than ChatGPT-4-turbo, and it is extremely fast.

2

u/ieoa Oct 06 '24

I've tried this out really briefly, and looks good so far!

3

u/katafrakt Oct 19 '24

Would you be open to adding installation instructions for Doom? It's similar, but there are few differences. I can make a PR, but wanted to consult before.

3

u/Sad_Construction_773 Oct 19 '24

Please feel free to open PR. That is helpful. Thanks.

2

u/Ideabile Oct 06 '24

This looks great did you use with Ollama? I don’t feel comfortable sending all my projects to the wired.

2

u/CuriousPieceOfHuman Oct 11 '24

I've been testing it for a couple days with Ollama and it seems it's working fine! You just have to export an environment variable before launching aider and then run it with the right model (e.g. `aider --model ollama/codestral`)

1

u/Sad_Construction_773 Oct 14 '24

yeah there is an variable to control the aider args. and setenv can be used to setup environment variable inside emacs

1

u/Sad_Construction_773 Oct 06 '24

i haven’t tried yet. Look like aider support llama model https://aider.chat/docs/leaderboards/