Skip to content

Latest commit

 

History

History
228 lines (169 loc) · 10.5 KB

readme.org

File metadata and controls

228 lines (169 loc) · 10.5 KB

Copilot Chat for Emacs

Description

This plugin allows you to chat with GitHub copilot.

chat.gif

Feel free to contribute, report issues or discuss new features.

News

v2.0.0 is here in development.

The master branch is now v2 development branch. To get a stable release, use the v1.3.0 tag. A branch for bug fix may be created if needed.

In v2, only one buffer is used for chat, thanks to polymode. For the moment, org mode is more stable but markdown will follow. Anyway, you should use org since it is so powerful.

Shell-maker is back !

Bug reports and new ideas are very welcome.

Tips

Many of you won’t read this readme. And many of those who start to read won’t read more than a few lines. So I’ll write some tips here, at the beginning.

Yank

When using the org frontend, you can yank code blocks provided by Copilot just as you would use the kill ring. Here’s a simple configuration:

(use-package copilot-chat
  …
  :bind (:map global-map
            ("C-c C-y" . copilot-chat-yank)
            ("C-c M-y" . copilot-chat-yank-pop)
            ("C-c C-M-y" . (lambda () (interactive) (copilot-chat-yank-pop -1))))
  …)

Find input section

In copilot-chat buffer, you can use (or bind to a key) the interactive copilot-chat-goto-input function to place point at the beginning of the prompt area.

Installation

Melpa

Copilot-chat is available on melpa :

M-x package-install RET copilot-chat RET

With use-package :

(use-package copilot-chat)

Straight

(use-package copilot-chat
  :straight (:host github :repo "chep/copilot-chat.el" :files ("*.el"))
  :after (request org markdown-mode))

Manual

Clone repository and eval files in emacs.

Configuration

GitHub

You will need a GitHub account with access to copilot API. When sending the first prompt, you will need to authenticate to GitHub. Follow instructions and everything will be fine.

Backend

copilot-chat-backend can be set to 'curl (default) or 'request.

With curl, answers will be written token by token. Curl path can be set with `copilot-chat-curl-program` variable. With request library, the text is written when all data is read and this can be long.

Frontend

Several frontends are available. You can select your favorite one by setting the copilot-chat-frontend variable to 'org (default), 'markdown or 'shell-maker.

Try them and choose wisely.

Magit commits

You can use copilot to generate your commit messages :

(add-hook 'git-commit-setup-hook 'copilot-chat-insert-commit-message)

Or call manually (copilot-chat-insert-commit-message) when in the commit message buffer.

Proxy

The proxy can be configured with the curl backend. For the emacs-request backend, please refer to the emacs-request documentation if you need to configure a proxy.

Use the variables copilot-chat-curl-proxy, copilot-chat-curl-proxy-user-pass, and copilot-chat-curl-proxy-insecure to set up a proxy. Refer to the documentation for each variable to learn how to use them.

Proxies have not been thoroughly tested yet, so there may be bugs. Many options are missing for HTTPS proxies. Please open an issue if you need additional features.

Usage

Basic

Start chatting with (copilot-chat-display). Type your question in prompt, then press C-c C-c or C-c RET. You may need to authenticate to GitHub. Follow instructions.

You can select buffers that will be added as context in your prompt. Use copilot-chat-add-current-buffer and copilot-chat-del-current-buffer. You can also manage buffers by using (copilot-chat-list). In the list, selected buffer will be highlighted using copilot-chat-list-selected-buffer-face which inherit from font-lock-keyword-face.

Selected buffers will be sent with each prompt until you remove them.

Transient

You can call (copilot-chat-transient) to open transient menu. Almost all functions are accessible.

Functions

Basic functions

  • (copilot-chat-reset) reset everything including history, buffers and frontend.
  • (copilot-chat-display) display copilot chat buffers.
  • (copilot-chat-switch-to-buffer) switch to Copilot Chat buffer, side by side with the current code editing buffer.
  • (copilot-chat-set-model) Select AI model to use.

Prompt

  • copilot-chat-goto-input place point at the beginning of the prompt area.
  • (copilot-chat-custom-mini-buffer) ask for a prompt in minibuffer and send it to copilot.
  • (copilot-chat-custom-prompt-selection) ask for a prompt in minibuffer and pastes selection after it before sending it to copilot.
  • (copilot-chat-prompt-history-previous) insert previous prompt from history in prompt buffer.
  • (copilot-chat-prompt-history-next) insert next prompt from history in prompt buffer.
  • (copilot-chat-ask-and-insert) ask for a custom prompt and write answer in current buffer at point.

Answer manipulation

  • (copilot-chat-yank) yank the last code block at point (org frontend only).
  • (copilot-chat-yank-pop) Replace last yank with previous block, or use argument to choose the block. Acts like (yank-pop) (org frontend only).
  • (copilot-chat-send-to-buffer) send a code block to a chosen buffer. Replace selection if any (org and markdown frontends only).

Buffers

  • (copilot-chat-add-current-buffer) add current buffer to copilot chat. Its content will be sent with every request.
  • (copilot-chat-del-current-buffer) remove current buffer.
  • (copilot-chat-list) open buffer list.
  • (copilot-chat-add-buffers-in-current-window) add all buffers in current Emacs window to copilot chat.
  • (copilot-chat-add-files-under-dir) Add all files with same suffix as current file under current directory. If there are more than 40 files, refuse to add and show warning message.

Code helper functions

  • (copilot-chat-explain-symbol-at-line) ask Copilot to explain symbol under point.
  • (copilot-chat-explain) ask copilot to explain selected code.
  • (copilot-chat-review) ask copilot to review selected code.
  • (copilot-chat-doc) ask copilot to document selected code.
  • (copilot-chat-fix) ask copilot to fix selected code.
  • (copilot-chat-optimize) ask copilot to optimize selected code.
  • (copilot-chat-test) ask copilot to write tests for selected code.
  • (copilot-chat-explain-defun) ask copilot to explain current function under point.
  • (copilot-chat-custom-prompt-function) ask copilot to apply a custom prompt to the function body under point. Eg. instruct on how to refactor the function.
  • (copilot-chat-review-whole-buffer) ask copilot to review the current whole buffer. It can be used to review the full class, or, review the magit diff for my change, or other people’s change.

Magit

  • (copilot-chat-insert-commit-message) Insert in the current buffer a copilot generated commit message.

Transient

  • (copilot-chat-transient) display main transient menu to access all functions.
  • (copilot-chat-transient-buffers) display transient menu for buffer management.
  • (copilot-chat-transient-code) display transient menu for code helper functions.
  • (copilot-chat-transient-magit) display transient menu for magit functions.

Troubleshooting

  • (copilot-chat-clear-auth-cache) clears the auth cache for Copilot Chat. You will have to login again.

Customizable variables

All variables can be customized using M-x customize-group RET copilot-chat RET.

Backend

  • copilot-chat-backend - Backend to use for API calls. Can be 'curl (default) or 'request.
  • copilot-chat-curl-program - Path to curl executable when using curl backend.
  • copilot-chat-curl-proxy - Proxy configuration for curl backend. Supports HTTP/HTTPS/SOCKS protocols.
  • copilot-chat-curl-proxy-insecure - Skip SSL verification for proxy connections in curl backend.
  • copilot-chat-curl-proxy-user-pass - Proxy authentication credentials for curl backend.

Frontend

  • copilot-chat-frontend - Frontend interface to use. Can be 'org (default) or 'markdown.

Display

  • copilot-chat-list-added-buffers-only - By default, buffer list displays all buffers and uses faces to highlight added buffer. If set to t, only added buffer are displayed.
  • copilot-chat-follow - If t (default is nil), point follows answer in chat buffer.

Storage and cache

  • copilot-chat-github-token-file - File path to store GitHub authentication token.
  • copilot-chat-token-cache - File path to store session token cache.

Model settings

  • copilot-chat-model - AI model to use. It is better to use (copilot-chat-set-model) to set it.
  • copilot-chat-model-ignore-picker - If nil (default) add a filter to (copilot-chat-set-model) which will only show models with model_picker_enabled attribute.

Prompts

Default prompts used by various commands:

  • copilot-chat-org-prompt - Base org system prompt configuring Copilot’s behavior.
  • copilot-chat-markdown-prompt - Base markdown system prompt configuring Copilot’s behavior.
  • copilot-chat-prompt-explain - Prompt for explain command.
  • copilot-chat-prompt-review - Prompt for code review command.
  • copilot-chat-prompt-doc - Prompt for documentation command.
  • copilot-chat-prompt-fix - Prompt for fix command.
  • copilot-chat-prompt-optimize - Prompt for optimization command.
  • copilot-chat-prompt-test - Prompt for test generation command.
  • copilot-chat-commit-prompt - Prompt for generating commit messages.

Faces

You can customize the appearance of the buffer list by modifying these faces:

  • copilot-chat-list-default-face - Face used for unselected buffers in the buffer list.
  • copilot-chat-list-selected-buffer-face - Face used for selected buffers in the buffer list.

Key bindings

Prompt buffer

  • C-c C-c send prompt. Answer will be written in chat buffer.
  • C-c RET send prompt. Answer will be written in chat buffer.
  • M-p previous prompt.
  • M-n next prompt.
  • C-c C-l open buffer list.
  • C-c C-q bury buffer and delete window.
  • C-c C-t open transient menu.

Buffer list buffer

  • RET select or deselect buffer on point.
  • space select or deselect buffer on point.
  • C-c C-c clear buffer list.
  • g refresh list.
  • q bury buffer and delete window.

Notes

This plugin is unofficial and based on Copilot Chat for neovim repository: /~https://github.com/CopilotC-Nvim/CopilotChat.nvim

The prompt for git commit messages comes from gpt-commit.

For GitHub copilot code completion in emacs, checkout copilot.el