Skip to content

Commit 6246b92

Browse files
committed
[copilot] Add keybindings and proper config instructions
1 parent b02934d commit 6246b92

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

layers/+web-services/github-copilot/README.org

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
- [[#description][Description]]
77
- [[#features][Features:]]
88
- [[#install][Install]]
9+
- [[#configuratiom][Configuratiom]]
10+
- [[#key-bindings][Key bindings]]
911

1012
* Description
1113
This layer enables usage of [[https://github.com/features/copilot][GitHub Copilot]] in Spacemacs using [[https://github.com/copilot-emacs/copilot.el][copilot.el]].
@@ -17,3 +19,33 @@ This layer enables usage of [[https://github.com/features/copilot][GitHub Copilo
1719
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
1820
add =github-copilot= to the existing =dotspacemacs-configuration-layers= list in this
1921
file.
22+
23+
In addition the github/copilot-language-server must be installed either manually with:
24+
#+BEGIN_SRC sh
25+
$ npm install -g @github/copilot-language-server
26+
#+END_SRC
27+
28+
or via elisp by pressing:
29+
#+BEGIN_SRC elisp
30+
SPC SPC copilot-install-server
31+
#+END_SRC
32+
33+
** Configuratiom
34+
Per default the service will run for every mode derived from prog mode. It will do
35+
automatic code suggestions. Key bindings for accepting an advice are bound automatically
36+
but can be rebound.
37+
38+
In order to work properly =SPC SPC copilot login= must be have been run once on the device
39+
especially if a commercial license is available.
40+
41+
The mode itself tries to defer the language from the major mode however if this fails it may
42+
be necessary to add the new binding manually. Details for this can be found [[https://github.com/copilot-emacs/copilot.el?tab=readme-ov-file#programming-language-detection][here]].
43+
44+
* Key bindings
45+
46+
| Key binding | Description |
47+
|---------------------+-----------------------------------------------------------------------|
48+
| ~C-M-<return>~ | accept the current completion suggestion |
49+
| ~C-M-S-<return>~ | accept the current completion suggestion word by word |
50+
| ~C-<iso-lefttab>~ | show the next github copilot completion (and refresh completions) |
51+
| ~C-M-<iso-lefttab>~ | show the previous github copilot completion (and refresh completions) |

layers/+web-services/github-copilot/packages.el

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,30 @@
2626

2727
(defun github-copilot/init-copilot ()
2828
(use-package copilot
29+
:hook '(prog-mode-hook . copilot-mode)
2930
:custom
3031
(copilot-enable-predicates '(spacemacs//copilot-enable-predicate
3132
copilot--buffer-changed))
32-
:defer t))
33+
:defer t
34+
:config
35+
(with-eval-after-load 'company
36+
(define-key copilot-completion-map (kbd "C-<iso-lefttab>") 'github-copilot/next-completion)
37+
(define-key copilot-completion-map (kbd "C-M-<iso-lefttab>") 'github-copilot/previous-completion)
38+
(define-key copilot-completion-map (kbd "C-M-<return>") 'copilot-accept-completion)
39+
(define-key copilot-completion-map (kbd "C-M-S-<return>") 'copilot-accept-completion-by-word))))
40+
41+
(defun github-copilot/next-completion ()
42+
"Move to the next completion in the Copilot completion menu.
43+
This function will make sure to show the next completion,
44+
if necessary triggering a `copilot-complete' command beforehand."
45+
(interactive)
46+
(copilot-complete)
47+
(copilot-next-completion))
48+
49+
(defun github-copilot/previous-completion ()
50+
"Move to the previous completion in the Copilot completion menu.
51+
This function will make sure to show the previous completion,
52+
if necessary triggering a `copilot-complete' command beforehand."
53+
(interactive)
54+
(copilot-complete)
55+
(copilot-previous-completion))

0 commit comments

Comments
 (0)