Created
March 19, 2023 06:53
-
-
Save apmanol/6ab0bb12174d3f1fc9b7b2ff1e4fa909 to your computer and use it in GitHub Desktop.
.emacs + codeium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-package company | |
:defer 10 | |
:diminish company-mode | |
:hook (c++-mode . company-mode) | |
:bind (:map company-active-map | |
("M-j" . company-select-next) | |
("M-k" . company-select-previous)) | |
:preface | |
;; enable yasnippet everywhere | |
(defvar company-mode/enable-yas t | |
"Enable yasnippet for all backends.") | |
(defun company-mode/backend-with-yas (backend) | |
(if (or | |
(not company-mode/enable-yas) | |
(and (listp backend) (member 'company-yasnippet backend))) | |
backend | |
(append (if (consp backend) backend (list backend)) | |
'(:with company-yasnippet)))) | |
:init (global-company-mode t) | |
:config | |
;; no delay no autocomplete | |
(validate-setq | |
company-idle-delay 0.15 | |
company-minimum-prefix-length 2 | |
company-tooltip-limit 20) | |
(setq company-backends (delete 'company-semantic company-backends)) | |
(setq company-backends (delete 'company-eclim company-backends)) | |
(setq company-backends (delete 'company-xcode company-backends)) | |
(setq company-backends (delete 'company-clang company-backends)) | |
;; (setq company-backends (delete 'company-bbdb company-backends)) | |
(setq company-backends (delete 'company-oddmuse company-backends)) | |
(validate-setq company-backends | |
(mapcar #'company-mode/backend-with-yas company-backends)) | |
(when my:use-ycmd | |
(add-to-list 'company-backends (company-mode/backend-with-yas 'company-ycmd)) | |
) | |
) | |
(use-package lsp-mode | |
:commands lsp | |
:if *is-app* | |
:custom | |
(lsp-auto-guess-root nil) | |
(lsp-prefer-flymake nil) ; Prefer using lsp-ui (flycheck) over flymake. | |
(lsp-file-watch-threshold 2000) | |
(read-process-output-max (* 1024 1024)) | |
(lsp-rust-analyzer-cargo-watch-command "clippy") | |
(lsp-eldoc-render-all t) | |
(lsp-idle-delay 0.6) | |
(lsp-rust-analyzer-server-display-inlay-hints t) | |
:hook (((python-mode rust-mode objc-mode) . lsp) | |
(lsp-mode . lsp-enable-which-key-integration) | |
) | |
:init | |
;; Disable yasnippet. We re-enable when yasnippet is loaded. | |
(defvar lsp-enable-snippet nil) | |
;; use c++ lsp only on my:use-cpp-lsp | |
(when my:use-cpp-lsp | |
(add-hook 'c-mode-common-hook #'lsp) | |
) | |
(message "loading lsp-mode") | |
:config | |
(setq lsp-clients-clangd-args '("-j=10" "-background-index" "--log=error" "--clang-tidy" "--enable-config")) | |
;; Set GC threshold to 25MB since LSP mode is very memory hungry and | |
;; produces a lot of garbage | |
(setq gc-cons-threshold 25000000) | |
(setq lsp-enable-on-type-formatting nil) | |
(lsp-register-client | |
(make-lsp-client | |
:new-connection (lsp-tramp-connection "clangd") | |
:major-modes '(c++-mode c-mode) | |
:ignore-messages nil | |
:remote? t | |
:server-id 'c++-remote | |
)) | |
) | |
(use-package company-lsp | |
:defer | |
:requires company | |
:commands (company-lsp) | |
:custom | |
(company-lsp-async t) | |
:config | |
(push 'company-lsp company-backends)) | |
;; we recommend using use-package to organize your init.el | |
(use-package codeium | |
;; if you use straight | |
;; :straight '(:type git :host github :repo "Exafunction/codeium.el") | |
;; otherwise, make sure that the codeium.el file is on load-path | |
:quelpa (codeium :fetcher github :repo "Exafunction/codeium.el" | |
:files ("codeium.el")) | |
:init | |
;; use globally | |
(add-to-list 'completion-at-point-functions #'codeium-completion-at-point) | |
;; or on a hook | |
;; (add-hook 'python-mode-hook | |
;; (lambda () | |
;; (setq-local completion-at-point-functions '(codeium-completion-at-point)))) | |
;; if you want multiple completion backends, use cape (https://github.com/minad/cape): | |
;; (add-hook 'python-mode-hook | |
;; (lambda () | |
;; (setq-local completion-at-point-functions | |
;; (list (cape-super-capf #'codeium-completion-at-point #'lsp-completion-at-point))))) | |
;; an async company-backend is coming soon! | |
;; codeium-completion-at-point is autoloaded, but you can | |
;; optionally set a timer, which might speed up things as the | |
;; codeium local language server takes ~0.2s to start up | |
;; (add-hook 'emacs-startup-hook | |
;; (lambda () (run-with-timer 0.1 nil #'codeium-init))) | |
;; :defer t ;; lazy loading, if you want | |
: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) | |
;; use M-x codeium-diagnose to see apis/fields that would be sent to the local language server | |
(setq codeium-api-enabled | |
(lambda (api) | |
(memq api '(GetCompletions Heartbeat CancelRequest GetAuthToken RegisterUser auth-redirect AcceptCompletion)))) | |
;; you can also set a config for a single buffer like this: | |
;; (add-hook 'python-mode-hook | |
;; (lambda () | |
;; (setq-local codeium/editor_options/tab_size 4))) | |
;; 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)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment