CLOVER🍀

That was when it all began.

EmacsでGitHub Copilot/GitHub Copilot Chatを使う

これは、なにをしたくて書いたもの?

EmacsGitHub Copilot、GitHub Copilot Chatを導入してみようかなということで。

使用するのはCopilot.elとCopilot Chat for Emacs

環境

今回の環境はこちら。

$ emacs --version
GNU Emacs 29.3
Copyright (C) 2024 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

Copilot.el

Copilot.elは、GitHub CopilotのEmacs用のプラグインです。GitHub提供ではありません。

GitHub - copilot-emacs/copilot.el: An unofficial Copilot plugin for Emacs.

パッケージ一覧上での名前はcopilotです。

GitHub CopilotのLanguage Serverはこちらのものを使います。Node.js 22以降が必要です。

GitHub - github/copilot-language-server-release: Feedback for the GitHub Copilot Language Server

ドキュメントに書いてあるようにM-x copilot-install-serverでインストールできます。

その後にM-x copilot-loginすると、GitHubでの認証を求められます。デバイスコードも表示されるので、認証しましょう。

あとはM-x copilot-modeを実行するか、以下のように設定しておくとプログラミング向けのモードになった時に自動的に
GitHub Copilotを有効にしてくれます。

(use-package copilot)
(add-hook 'prog-mode-hook 'copilot-mode)
(define-key copilot-completion-map (kbd "<tab>") 'copilot-accept-completion)
(define-key copilot-completion-map (kbd "TAB") 'copilot-accept-completion)

最後の2つは、タブで補完候補の確定する設定です。

Copilot Chat for Emacs

Copilot Chat for Emacsは、Emacs上でGitHub Copilot Chatが使えるようになるプラグインです。

GitHub - chep/copilot-chat.el: Chat with Github copilot in Emacs !

パッケージ一覧上での名前はcopilot-chatです。

設定。

(use-package copilot-chat)

M-x copilot-chat(もしくはM-x copilot-chat-displayを実行するとディレクトリーを求められ(デフォルトは
カレントディレクトリー)、チャットが入力できるようになります。

あとはプロンプトを入力して、C-c C-cでプロンプトを送信します。

初回の場合は、GitHubへのログインを求められます。

キーバインディングはこちら。

Copilot Chat for Emacs / Key bindings

関数はこちら。

Copilot Chat for Emacs / Functions

最低限ですが、これでEmacs上でGitHub CopilotおよびGitHub Copilot Chatが使えるようになりました。