Skip to content

tninja/aider.el

Repository files navigation

aider.el : aider (AI Pair Programming) Inside Emacs

Introduction

  • Do you like the AI features of Cursor AI Code Editor, but prefer to stay within Emacs?
  • Aider is 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.

Why Use aider.el in Emacs?

  • Pop-up Menu: No need to remember commands. (aider-transient-menu)

./transient_menu.png

  • 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.
  • Batch add files from dired buffer (aider-batch-add-dired-marked-files): Add multiple Dired marked files to the Aider buffer. These files can be searched from repo with aider-repo-find-name-dired command
  • Region-Based Refactor Support (aider-region-refactor): You can select a region (e.g., a code block) in a file and ask aider to refactor it.
  • And More: Add your own Elisp functions to support your use case. You can certainly ask aider / aider.el to do that.

Installation

  • 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
  (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))

Optional

  • Maybe you might want to try helm-aider.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))))

(provide 'aider)

Screenshot

./screenshot.png

  • 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).

Other Emacs AI coding tool

  • 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