-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig-llm.el-orig
194 lines (159 loc) · 6.84 KB
/
config-llm.el-orig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
;;; package --- Summary
;;; Commentary:
;;; Code:
;; https://robert.kra.hn/posts/2023-02-22-copilot-emacs-setup/
(load-relative "./copilot-balancer")
(load-relative "./copilot")
;; -*-no-byte-compile: t; -*-
;; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
(require 'package)
(require 'cl)
(setq user-init-file (or load-file-name (buffer-file-name)))
(setq user-emacs-directory (file-name-directory user-init-file))
(setq package-user-dir (expand-file-name "elpa/" user-emacs-directory))
(setq ;; debug-on-error t
no-byte-compile t
byte-compile-warnings nil
warning-suppress-types '((comp))
inhibit-startup-screen t
package-archives '(("melpa" . "https://melpa.org/packages/")
("gnu" . "https://elpa.gnu.org/packages/"))
custom-file (expand-file-name "custom.el" user-emacs-directory))
;; install dependencies
(let ((pkg-list '(use-package
s
dash
editorconfig
company)))
(package-initialize)
(when-let ((to-install (map-filter (lambda (pkg _) (not (package-installed-p pkg))) pkg-list)))
(package-refresh-contents)
(mapc (lambda (pkg) (package-install pkg)) pkg-list)))
(require 'use-package)
;; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
(defun rk/copilot-tab ()
"Tab command that will complet with copilot if a completion is
available. Otherwise will try company, yasnippet or normal
tab-indent."
(interactive)
(or (copilot-accept-completion)
(company-yasnippet-or-completion)
(indent-for-tab-command)))
(defun rk/copilot-complete-or-accept ()
"Command that either triggers a completion or accepts one if one
is available. Useful if you tend to hammer your keys like I do."
(interactive)
(if (copilot--overlay-visible)
(progn
(copilot-accept-completion)
(open-line 1)
(next-line))
(copilot-complete)))
(defun rk/copilot-quit ()
"Run `copilot-clear-overlay' or `keyboard-quit'. If copilot is
cleared, make sure the overlay doesn't come back too soon."
(interactive)
(condition-case err
(when copilot--overlay
(lexical-let ((pre-copilot-disable-predicates copilot-disable-predicates))
(setq copilot-disable-predicates (list (lambda () t)))
(copilot-clear-overlay)
(run-with-idle-timer
1.0
nil
(lambda ()
(setq copilot-disable-predicates pre-copilot-disable-predicates)))))
(error handler)))
(defun rk/copilot-complete-if-active (next-func n)
(let ((completed (when copilot-mode (copilot-accept-completion))))
(unless completed (funcall next-func n))))
(defun rk/no-copilot-mode ()
"Helper for `rk/no-copilot-modes'."
(copilot-mode -1))
(defvar rk/no-copilot-modes '(shell-mode
inferior-python-mode
eshell-mode
term-mode
vterm-mode
comint-mode
compilation-mode
debugger-mode
dired-mode-hook
compilation-mode-hook
flutter-mode-hook
minibuffer-mode-hook)
"Modes in which copilot is inconvenient.")
(defvar rk/copilot-manual-mode nil
"When `t' will only show completions when manually triggered, e.g. via M-C-<return>.")
(defvar rk/copilot-enable-for-org nil
"Should copilot be enabled for org-mode buffers?")
(defun rk/copilot-enable-predicate ()
""
(and
(eq (get-buffer-window) (selected-window))))
(defun rk/copilot-disable-predicate ()
"When copilot should not automatically show completions."
(or rk/copilot-manual-mode
(member major-mode rk/no-copilot-modes)
(and (not rk/copilot-enable-for-org) (eq major-mode 'org-mode))
(company--active-p)))
(defun rk/copilot-change-activation ()
"Switch between three activation modes:
- automatic: copilot will automatically overlay completions
- manual: you need to press a key (M-C-<return>) to trigger completions
- off: copilot is completely disabled."
(interactive)
(if (and copilot-mode rk/copilot-manual-mode)
(progn
(message "deactivating copilot")
(global-copilot-mode -1)
(setq rk/copilot-manual-mode nil))
(if copilot-mode
(progn
(message "activating copilot manual mode")
(setq rk/copilot-manual-mode t))
(message "activating copilot mode")
(global-copilot-mode))))
(defun rk/copilot-toggle-for-org ()
"Toggle copilot activation in org mode. It can sometimes be
annoying, sometimes be useful, that's why this can be handly."
(interactive)
(setq rk/copilot-enable-for-org (not rk/copilot-enable-for-org))
(message "copilot for org is %s" (if rk/copilot-enable-for-org "enabled" "disabled")))
;; load the copilot package
(use-package copilot
:load-path (lambda () (expand-file-name "copilot.el" user-emacs-directory))
:diminish ;; don't show in mode line (we don't wanna get caught cheating, right? ;)
:config
(add-to-list 'copilot-indentation-alist '(prog-mode 2))
(add-to-list 'copilot-indentation-alist '(org-mode 2))
(add-to-list 'copilot-indentation-alist '(text-mode 2))
(add-to-list 'copilot-indentation-alist '(closure-mode 2))
(add-to-list 'copilot-indentation-alist '(emacs-lisp-mode 2))
(add-to-list 'copilot-indentation-alist '(c++-mode 4))
;; keybindings that are active when copilot shows completions
(define-key copilot-mode-map (kbd "M-C-<next>") #'copilot-next-completion)
(define-key copilot-mode-map (kbd "M-C-<prior>") #'copilot-previous-completion)
(define-key copilot-mode-map (kbd "M-C-<right>") #'copilot-accept-completion-by-word)
(define-key copilot-mode-map (kbd "M-C-<down>") #'copilot-accept-completion-by-line)
;; global keybindings
(define-key global-map (kbd "M-C-<return>") #'rk/copilot-complete-or-accept)
(define-key global-map (kbd "M-C-<escape>") #'rk/copilot-change-activation)
;; Do copilot-quit when pressing C-g
(advice-add 'keyboard-quit :before #'rk/copilot-quit)
;; complete by pressing right or tab but only when copilot completions are
;; shown. This means we leave the normal functionality intact.
(advice-add 'right-char :around #'rk/copilot-complete-if-active)
(advice-add 'indent-for-tab-command :around #'rk/copilot-complete-if-active)
;; deactivate copilot for certain modes
(add-to-list 'copilot-enable-predicates #'rk/copilot-enable-predicate)
(add-to-list 'copilot-disable-predicates #'rk/copilot-disable-predicate))
(eval-after-load 'copilot
'(progn
;; Note company is optional but given we use some company commands above
;; we'll require it here. If you don't use it, you can remove all company
;; related code from this file, copilot does not need it.
(require 'company)
(global-copilot-mode)))
(copilot-login)
;;; config-llm ends here