emacs/config/completion.org

5.7 KiB

Completion

Vertico

  (use-package vertico
    :ensure t
    :diminish
    :custom
    (vertico-cycle t)
    :init
    (vertico-mode)
    :config
    (require 'vertico-directory))

Marginalia

  (use-package marginalia
    :ensure t
    :diminish
    :custom
    (marginalia-annotators '(marginalia-annotators-heavy
                             marginalia-annotators-light
                             nil))
    :config (marginalia-mode +1))

Orderless

  (use-package orderless
    :ensure t
    :diminish
    :custom
    (completion-styles '(orderless basic))
    (completion-category-defaults nil)
    (completion-category-overrides '((file (styles . (partial-completion))))))

Corfu and Cape

  (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)
      (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)

Consult

  (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)))

Embark

  (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))

Tempel Snippets

  ;; Configure Tempel
  (use-package tempel
    ;; 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)
    )

  ;; Optional: Add tempel-collection.
  ;; The package is young and doesn't have comprehensive coverage.
  (use-package tempel-collection)