Enhance your coding experience with code generation, rewriting, and interactive discussions.
- Generate code at the cursor with instructions
- Rewrite the selected region with instructions
- Discuss selected code
- AI understands the full context displayed on the screen
- AI sees the visible part of the current buffer, not just the selected region
- Inspect the raw conversation in the
*ancilla-chat*
buffer
- Review diffs before applying rewrites (can be disabled with the
ancilla-show-confirmation
customization) - Asynchronous requests (can be disabled with the
ancilla-async
customization) - Shortcut functions mimic intellij github copilot menu
- simplify / fix code
- generate doc, unit-test
- explain code
- review diff (can be used with magit revision / diff buffer)
- A transient menu for easy access to all commands
The architecture is designed to support any AI backends. Currently, only the chat
adaptor is implemented, which utilizes OpenAI’s chat completion (ChatGPT and GPT4 supported).
(use-package ancilla
:straight (:host github :repo "shouya/ancilla.el")
;; ancilla-generate-or-rewrite calls ancilla-generate or
;; ancilla-rewrite depending on whether there is an active
;; selection.
:bind ("C-x C-r" . ancilla-generate-or-rewrite)
:bind ("C-x C-m" . ancilla-transient-menu) ;; provide shorts like intellij copilot plugins
:custom
;; Defaults to gpt-3.5-turbo, you can opt to use gpt-4o-mini or other.
;; (ancilla-adaptor-chat-model "gpt-4o-mini")
;; Set your API key
(ancilla-adaptor-chat-openai-api-key "sk-XXXXXXXXXXXXXXXX"))
For most of the cases, you only need to invoke ancilla-generate-or-rewrite
. It will call ancilla-rewrite
when there is an active region, and call ancilla-generate otherwise
.
Inspect the *ancilla-chat*
buffer for the full conversation sent to OpenAI.
Transient menu (ancilla-transient-menu
)
Set the ancilla-show-confirmation
variable to nil
:
(setq ancilla-show-confirmation nil)
Ancilla.el generally sends the visible portion of the buffer to OpenAI. You can inspect the content sent to OpenAI in the *ancilla-chat*
buffer.
To control the content sent to OpenAI, you need to manage what is displayed on the screen. Here are some helpful tips:
- Use
recenter-top-bottom
(usually bound toC-l
) to control the position of the current line on the screen. - Use
text-scale-adjust
(usually bound toC-+
andC--
) to resize the text, allowing more or less text to be displayed on the screen. - Use narrowing to precisely control what is displayed.
To use ChatGPT by default and GPT-4 occasionally, you can define a function that overrides the ancilla-adaptor-chat-model
. Here’s an example:
(defun my/ancilla-generate-or-rewrite (arg)
(interactive "P")
(let ((ancilla-adaptor-chat-model (if arg "gpt-4" "gpt-3.5-turbo")))
(ancilla-generate-or-rewrite)))
Bind this function to a hotkey, such as C-x C-r
. To summon GPT-4, use C-u C-x C-r
.
- The “select-instruct” way of interaction is inspired by https://github.com/debanjum/codex-completion.
- The “diff before applying rewrite” interaction is inspired by https://www.cursor.so.