end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

install copilot.el (GitHub Copilot Free) to emacs ver.28 for win

$10/月だった GitHub CopilotにFreeプランが追加され、 2000回/月のコード補完を無料で利用できるようになりましたので、 emacs 28 for win に copilot.el をインストールすることで、 これを利用してみます。

参考url

step 1 - install node.js

copilot.elのdocumentによれば、Node.js v18以上が必要ですので、 node.js ver.18.20.5 をインストールしました

step 2 - install straight.el + use-package

copilot.el は、straight.el + use-package によりパッケージ管理されるようです。

GitHub - radian-software/straight.el: 🍀 Next-generation, purely functional package manager for the Emacs hacker. にある通り、 ~/.emacs.d/init.el に以下を追記後、emacsを再起動すると、 straight.el + use-package が自動的にインストールされます。

(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 6))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(straight-use-package 'use-package)

step 3 - install copilot.el

~/.emacs.d/init.el に以下を追記後、emacsを再起動すると、 copilot.el が自動的にインストールされます。

(use-package copilot
  :straight (:host github :repo "copilot-emacs/copilot.el" :files ("*.el"))
  :ensure t)

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

step 4 - install copilot-install-server

更に「M-x install copilot-install-server」により copilot server を ~/.emacs.d/.cache/copilot/node_modules/copilot-node-server へ インストールしてください。

【※】私の場合、copilot-node-server の調子が悪くなることがあり、 その場合、上記のdirを削除し、再度 「M-x install copilot-install-server」が必要となることがありました

step 5 - copilot.el 起動と、copilot への login

「M-x copilot-mode」後、「M-x copilot-login」により、 ミニバッファにワンタイムパスワードが表示されます。

更にENTERすると、ブラウザが起動しますので、 ワンタイムパスワードを貼り付けることで、ログイン完了です。

step 6 - copilot.el の利用

copilot-mode では自動的にコードが提案されますので、 この提案コードを採用する場合、TABで入力が確定します。