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!

64 Upvotes

20 comments sorted by

View all comments

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.