Skip to content

Commit ee41fbc

Browse files
committed
[copilot] Add chat interface support and fine tune keybindings
1 parent 6246b92 commit ee41fbc

File tree

5 files changed

+76
-32
lines changed

5 files changed

+76
-32
lines changed

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

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
- [[#install][Install]]
99
- [[#configuratiom][Configuratiom]]
1010
- [[#key-bindings][Key bindings]]
11+
- [[#general][General]]
12+
- [[#in-chat][In Chat]]
1113

1214
* Description
13-
This layer enables usage of [[https://github.com/features/copilot][GitHub Copilot]] in Spacemacs using [[https://github.com/copilot-emacs/copilot.el][copilot.el]].
15+
This layer enables usage of [[https://github.com/features/copilot][GitHub Copilot]] in Spacemacs.
1416

1517
** Features:
16-
- Provide access to ai powered code completions powered by [[https://github.com/features/copilot][GitHub Copilot]]
18+
- Ai powered code completions using [[https://github.com/copilot-emacs/copilot.el][copilot.el]]
19+
- Ai chat interactions using [[https://github.com/chep/copilot-chat.el][copilot-chat.el]]
20+
- Automatic generation of git commit messages using [[https://github.com/chep/copilot-chat.el][copilot-chat.el]]
1721

1822
* Install
1923
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
@@ -38,14 +42,31 @@ but can be rebound.
3842
In order to work properly =SPC SPC copilot login= must be have been run once on the device
3943
especially if a commercial license is available.
4044

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]].
45+
The mode itself tries to defer the language from the major mode however if this fails it may
46+
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]].
47+
48+
For the chat interface a separate login procedure will be necessary once a chat is started.
4349

4450
* Key bindings
4551

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) |
52+
** General
53+
54+
| Key binding | Description |
55+
|---------------------+-------------------------------------------------------------------------|
56+
| ~C-M-<return>~ | accept the current completion suggestion |
57+
| ~C-M-S-<return>~ | accept the current completion suggestion word by word |
58+
| ~C-M-<tab>~ | show the next github copilot completion (and refresh completions) |
59+
| ~C-M-<iso-lefttab>~ | show the previous github copilot completion (and refresh completions) |
60+
| ~SPC $ c~ | Start a transient state to interact with Github Copilots chat interface |
61+
62+
** In Chat
63+
64+
| Key binding | Description |
65+
|----------------+----------------------------------|
66+
| ~,,~ | sent the current text to copilot |
67+
| ~,a~ | kill a chat process |
68+
| ~,k~ | kill a chat process |
69+
| ~C-c-<return>~ | sent the current text to copilot |
70+
| ~C-c-C-c~ | sent the current text to copilot |
71+
| ~C-c-C-a~ | kill a chat process |
72+
| ~C-c-C-k~ | kill a chat process |

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,19 @@ In `holy-mode', we enable `evil-emacs-state' permanently, hence this workaround.
2727
(or (not (bound-and-true-p evil-local-mode))
2828
(bound-and-true-p holy-mode)
2929
(evil-insert-state-p)))
30+
31+
(defun spacemacs/github-copilot-next-completion ()
32+
"Move to the next completion in the Copilot completion menu.
33+
This function will make sure to show the next completion,
34+
if necessary triggering a `copilot-complete' command beforehand."
35+
(interactive)
36+
(copilot-complete)
37+
(copilot-next-completion))
38+
39+
(defun spacemacs/github-copilot-previous-completion ()
40+
"Move to the previous completion in the Copilot completion menu.
41+
This function will make sure to show the previous completion,
42+
if necessary triggering a `copilot-complete' command beforehand."
43+
(interactive)
44+
(copilot-complete)
45+
(copilot-previous-completion))
Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; packages.el --- Large GitHub Copilot Client for Spacemacs -*- lexical-binding: nil; -*-
1+
;;; packages.el --- Large GitHub Copilot Client for Spacemacs -*- lexical-binding: t; -*-
22
;;
33
;; Copyright (c) 2012-2025 Sylvain Benner & Contributors
44
;;
@@ -22,34 +22,39 @@
2222

2323

2424
(defconst github-copilot-packages
25-
'((copilot)))
25+
'((copilot)
26+
(copilot-chat)))
2627

2728
(defun github-copilot/init-copilot ()
29+
"Initialize the `copilot' package and set up keybindings."
2830
(use-package copilot
29-
:hook '(prog-mode-hook . copilot-mode)
31+
:hook (prog-mode . copilot-mode)
3032
:custom
3133
(copilot-enable-predicates '(spacemacs//copilot-enable-predicate
3234
copilot--buffer-changed))
3335
:defer t
3436
: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))))
37+
(define-key copilot-completion-map (kbd "C-M-<tab>") 'spacemacs/github-copilot-next-completion)
38+
(define-key copilot-completion-map (kbd "C-M-<iso-lefttab>") 'spacemacs/github-copilot-previous-completion)
39+
(define-key copilot-completion-map (kbd "C-M-<return>") 'copilot-accept-completion)
40+
(define-key copilot-completion-map (kbd "C-M-S-<return>") 'copilot-accept-completion-by-word)))
4041

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))
42+
(defun github-copilot/init-copilot-chat ()
43+
"Initialize the `copilot-chat' package and set up keybindings."
44+
(use-package copilot-chat
45+
:hook (git-commit-setup . copilot-chat-insert-commit-message)
46+
:defer t
47+
:init
48+
;; Provide our transient state in the AI menu
49+
(spacemacs/declare-prefix "$" "AI")
50+
(spacemacs/set-leader-keys "$c" 'copilot-chat-transient)
51+
:config
52+
;; Make sure that standard ,, works as confirm in the chat window
53+
(evil-define-key 'normal copilot-chat-prompt-mode-map ",," #'copilot-chat-prompt-send)
54+
(evil-define-key 'normal copilot-chat-prompt-mode-map ",a" #'copilot-chat-kill-instance)
55+
(evil-define-key 'normal copilot-chat-prompt-mode-map ",k" #'copilot-chat-kill-instance)
4856

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))
57+
;; And don't forget to provide an alternative for holy mode users
58+
(define-key copilot-chat-prompt-mode-map (kbd "C-c C-c") #'copilot-chat-prompt-send)
59+
(define-key copilot-chat-prompt-mode-map (kbd "C-c C-a") #'copilot-chat-kill-instance)
60+
(define-key copilot-chat-prompt-mode-map (kbd "C-c C-k") #'copilot-chat-kill-instance)))

layers/+web-services/llm-client/packages.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
:defer t
3535
:ensure t
3636
:init
37+
(spacemacs/declare-prefix "$" "AI")
3738
(spacemacs/declare-prefix "$e" "Ellama")
3839
(spacemacs/set-leader-keys "$e" 'ellama-transient-main-menu)))
3940

layers/+web-services/whisper/packages.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
(use-package whisper
3030
:defer t
3131
:init
32+
(spacemacs/declare-prefix "$" "AI")
3233
(spacemacs/declare-prefix "$w" "Whisper")
3334
(spacemacs/set-leader-keys
3435
"$wr" 'whisper-run ; Start recording and transcribe/translate audio

0 commit comments

Comments
 (0)