emacs/config/completion.org

185 lines
5.8 KiB
Org Mode
Raw Normal View History

#+title: Completion
#+author: Evie Litherland-Smith
#+email: evie@xenia.me.uk
#+filetags: :emacs:config:org:
#+property: header-args:emacs-lisp :tangle yes :mkdirp yes :results output silent
* Vertico
#+begin_src emacs-lisp
(use-package vertico
:ensure t
:diminish
:custom
(vertico-cycle t)
:init
(vertico-mode)
:config
(require 'vertico-directory))
#+end_src
* Marginalia
#+begin_src emacs-lisp
(use-package marginalia
:ensure t
:diminish
:custom
(marginalia-annotators '(marginalia-annotators-heavy
marginalia-annotators-light
nil))
:config (marginalia-mode +1))
#+end_src
* Orderless
#+begin_src emacs-lisp
(use-package orderless
:ensure t
:diminish
:custom
(completion-styles '(orderless basic))
(completion-category-defaults nil)
(completion-category-overrides '((file (styles . (partial-completion)))
(eglot (styles . (styles orderless)))
(eglot-capf (styles . (styles orderless))))))
#+end_src
* Corfu and Cape
#+begin_src emacs-lisp
(use-package corfu
:ensure t
:diminish
:demand
:custom
(corfu-cycle t)
(corfu-auto t)
(corfu-auto-delay 0.2)
(corfu-auto-prefix 2)
(corfu-quit-no-match 'separator)
(corfu-quit-at-boundary 'separator)
(corfu-preview-current nil)
(corfu-preselect 'directory)
:bind ( :map corfu-map
("M-SPC" . corfu-insert-separator)
("RET" . nil)
("TAB" . corfu-insert)
([tab] . corfu-insert))
:init
(global-corfu-mode +1)
(corfu-history-mode +1)
:config
(when (require 'corfu-popupinfo nil :noerror)
2024-02-19 09:20:57 +00:00
(setq corfu-popupinfo-delay 0.3)
(corfu-popupinfo-mode +1)
(keymap-set corfu-map "M-p" #'corfu-popupinfo-scroll-down)
(keymap-set corfu-map "M-n" #'corfu-popupinfo-scroll-up)
(keymap-set corfu-map "M-d" #'corfu-popupinfo-toggle))
(defun corfu-enable-always-in-minibuffer ()
"Enable Corfu in the minibuffer if Vertico is not active."
(unless (or (bound-and-true-p vertico--input)
(eq (current-local-map) read-passwd-map))
(setq-local corfu-echo-delay nil ;; Disable automatic echo and popup
corfu-auto nil ;; Enable/disable auto completion
corfu-popupinfo-delay nil)
(corfu-mode +1)))
(add-hook 'minibuffer-setup-hook #'corfu-enable-always-in-minibuffer 1)
(defun my/local-corfu-no-auto () (setq-local corfu-auto nil))
(with-eval-after-load 'eshell (add-hook 'eshell-mode-hook 'my/local-corfu-no-auto))
(with-eval-after-load 'shell (add-hook 'shell-mode-hook 'my/local-corfu-no-auto))
(with-eval-after-load 'gud (add-hook 'gud-mode-hook 'my/local-corfu-no-auto)))
(require 'corfu)
(use-package cape
:ensure t
:diminish
:demand
:init
(add-to-list 'completion-at-point-functions #'cape-emoji)
(add-to-list 'completion-at-point-functions #'cape-file)
(add-to-list 'completion-at-point-functions #'cape-dabbrev)
:custom
(cape-dabbrev-min-length (+ corfu-auto-prefix 1)))
(require 'cape)
#+end_src
* Consult
#+begin_src emacs-lisp
(use-package consult
:ensure t
:diminish
:bind (("<remap> <imenu>" . consult-imenu)
("<remap> <switch-to-buffer>" . consult-buffer)
("<remap> <project-switch-to-buffer>" . consult-project-buffer)
("<remap> <org-goto>" . consult-org-heading)
("C-c s l" . consult-line)
("C-c s o" . consult-outline)
("C-c s f" . consult-fd)
("C-c s g" . consult-ripgrep)
("C-c s e" . consult-flymake)
("C-c s i" . consult-info)
:map minibuffer-local-map
("C-r" . consult-history))
:config (setq completion-in-region-function #'consult-completion-in-region))
(use-package consult-eglot
:ensure t
:diminish
:after (consult eglot)
:bind (("C-c s s" . consult-eglot-symbols)))
#+end_src
* Embark
#+begin_src emacs-lisp
(use-package embark
:ensure t
:diminish
:bind (("<remap> <describe-bindings>" . embark-bindings)
("C-." . embark-act))
:config (setq prefix-help-command #'embark-prefix-help-command))
(use-package embark-consult
:ensure t
:diminish
:after (embark consult)
:hook (embark-collect-mode . consult-preview-at-point-mode))
#+end_src
2024-02-21 06:40:57 +00:00
* Tempel Snippets
#+begin_src emacs-lisp
;; Configure Tempel
(use-package tempel
2024-02-21 07:07:13 +00:00
:ensure t
:diminish
2024-02-21 06:40:57 +00:00
;; Require trigger prefix before template name when completing.
;; :custom
;; (tempel-trigger-prefix "<")
:bind (("M-+" . tempel-complete) ;; Alternative tempel-expand
("M-*" . tempel-insert))
:init
;; Setup completion at point
(defun tempel-setup-capf ()
;; Add the Tempel Capf to `completion-at-point-functions'.
;; `tempel-expand' only triggers on exact matches. Alternatively use
;; `tempel-complete' if you want to see all matches, but then you
;; should also configure `tempel-trigger-prefix', such that Tempel
;; does not trigger too often when you don't expect it. NOTE: We add
;; `tempel-expand' *before* the main programming mode Capf, such
;; that it will be tried first.
(setq-local completion-at-point-functions
(cons #'tempel-expand
completion-at-point-functions)))
(add-hook 'conf-mode-hook 'tempel-setup-capf)
(add-hook 'prog-mode-hook 'tempel-setup-capf)
(add-hook 'text-mode-hook 'tempel-setup-capf)
;; Optionally make the Tempel templates available to Abbrev,
;; either locally or globally. `expand-abbrev' is bound to C-x '.
(add-hook 'prog-mode-hook #'tempel-abbrev-mode)
(global-tempel-abbrev-mode))
2024-02-21 06:40:57 +00:00
#+end_src