replace gh copilot with codeium

Amolith created

Change summary

dot_config/doom/config.el.tmpl | 49 ++++++++++++++++++++++++++++++-----
dot_config/doom/packages.el    |  7 +++-
2 files changed, 47 insertions(+), 9 deletions(-)

Detailed changes

dot_config/doom/config.el.tmpl 🔗

@@ -155,13 +155,13 @@
 
 (map! :leader :desc "Push upstream" "g p" #'magit-push-current-to-upstream)
 
-(use-package! copilot
-  :hook (prog-mode . copilot-mode)
-  :bind (("C-TAB" . 'copilot-accept-completion-by-word)
-         ("C-<tab>" . 'copilot-accept-completion-by-word)
-         :map copilot-completion-map
-         ("<tab>" . 'copilot-accept-completion)
-         ("TAB" . 'copilot-accept-completion)))
+;;(use-package! copilot
+;;  :hook (prog-mode . copilot-mode)
+;;  :bind (("C-TAB" . 'copilot-accept-completion-by-word)
+;;         ("C-<tab>" . 'copilot-accept-completion-by-word)
+;;         :map copilot-completion-map
+;;         ("<tab>" . 'copilot-accept-completion)
+;;         ("TAB" . 'copilot-accept-completion)))
 
 (add-hook 'evil-local-mode-hook 'turn-on-undo-tree-mode)
 
@@ -183,3 +183,38 @@
                   (minibuffer . t)
                   (menu-bar-lines . t)
                   (window-system . x))))
+
+(use-package codeium
+    :init
+  (add-to-list 'completion-at-point-functions #'codeium-completion-at-point)
+  (add-hook 'emacs-startup-hook
+            (lambda () (run-with-timer 0.1 nil #'codeium-init)))
+
+  :config
+  ;; (setq use-dialog-box nil) ;; do not use popup boxes
+
+  ;; if you don't want to use customize to save the api-key
+  ;; (setq codeium/metadata/api_key "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
+
+  ;; get codeium status in the modeline
+  (setq codeium-mode-line-enable
+        (lambda (api) (not (memq api '(CancelRequest Heartbeat AcceptCompletion)))))
+  (add-to-list 'mode-line-format '(:eval (car-safe codeium-mode-line)) t)
+  ;; alternatively for a more extensive mode-line
+  ;; (add-to-list 'mode-line-format '(-50 "" codeium-mode-line) t)
+
+  (setq codeium-api-enabled
+        (lambda (api)
+          (memq api '(GetCompletions Heartbeat CancelRequest GetAuthToken RegisterUser auth-redirect AcceptCompletion))))
+
+  ;; You can overwrite all the codeium configs!
+  ;; for example, we recommend limiting the string sent to codeium for better performance
+  (defun my-codeium/document/text ()
+    (buffer-substring-no-properties (max (- (point) 3000) (point-min)) (min (+ (point) 1000) (point-max))))
+  ;; if you change the text, you should also change the cursor_offset
+  ;; warning: this is measured by UTF-8 encoded bytes
+  (defun my-codeium/document/cursor_offset ()
+    (codeium-utf8-byte-length
+     (buffer-substring-no-properties (max (- (point) 3000) (point-min)) (point))))
+  (setq codeium/document/text 'my-codeium/document/text)
+  (setq codeium/document/cursor_offset 'my-codeium/document/cursor_offset))

dot_config/doom/packages.el 🔗

@@ -45,8 +45,8 @@
 (package! org-ref
   :recipe (:host github :repo "jkitchin/org-ref"))
 
-(package! copilot
-  :recipe (:host github :repo "zerolfx/copilot.el" :files ("*.el" "dist")))
+;;(package! copilot
+;;  :recipe (:host github :repo "zerolfx/copilot.el" :files ("*.el" "dist")))
 
 (package! magit-gitflow
   :recipe (:host github :repo "jtatarik/magit-gitflow"))
@@ -55,6 +55,9 @@
 (package! evil-collection
   :recipe (:repo "emacs-evil/evil-collection" :branch "master"))
 
+(package! codeium
+  :recipe (:host github :repo "Exafunction/codeium.el"))
+
 ;; If the package you are trying to install does not contain a PACKAGENAME.el
 ;; file, or is located in a subdirectory of the repo, you'll need to specify
 ;; `:files' in the `:recipe':