Skip to content

Latest commit

 

History

History
205 lines (160 loc) · 5.92 KB

completion.org

File metadata and controls

205 lines (160 loc) · 5.92 KB

Completion

Completion UI

Primary Completion UI

Vertical completion UI using Vertico

(use-package vertico
  :init
  (vertico-mode)
  (vertico-multiform-mode)
  :bind (:map vertico-map
              ("<up>" . nil)
              ("<down>" . nil))
  :config
  (setq vertico-cycle nil)
  (setq vertico-multiform-commands
        '((consult-ripgrep buffer)
          (consult-org-roam-search buffer)))

  (setq vertico-multiform-categories
        '((org-roam-node buffer indexed))))

Completion Popup

Pop up a list of completion candidates using Corfu

(use-package corfu
  :init
  (global-corfu-mode)
  (corfu-popupinfo-mode)
  :bind (:map corfu-map ("M-m" . corfu-move-to-minibuffer))
  :config

  (defun corfu-move-to-minibuffer ()
    (interactive)
    (let ((completion-extra-properties corfu--extra)
          completion-cycle-threshold completion-cycling)
      (apply #'consult-completion-in-region completion-in-region--data)))

  (setq corfu-auto t
        tab-always-indent 'complete
        corfu-auto-prefix 2
        corfu-auto-delay 0.25
        corfu-max-width 78
        corfu-min-width corfu-max-width
        corfu-separator ?\s
        corfu-quit-no-match 'separator))

Annotations / Help

https://github.com/minad/marginalia

(use-package marginalia
  :bind ("M-A" . marginalia-cycle)
  :init
  (marginalia-mode)
  :config
  (setq marginalia-align 'left))

(use-package which-key :config (which-key-mode))

Icons

Add icons to completion in Corfu overlay and for completion candidates in the minibuffer

(if (display-graphic-p)
    (use-package kind-icon
      :after corfu
      :custom
      (kind-icon-default-face 'corfu-default)
      :config
      (add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter)

      ;; Set fonts and frame size after icons are loaded
      (mjr/set-font (mjr/appropriate-font-size))
      (toggle-frame-maximized)))

(use-package all-the-icons-completion
  :after all-the-icons
  :hook (marginalia-mode . all-the-icons-completion-marginalia-setup)
  :init
  (all-the-icons-completion-mode))

Completion Candidates

Packages to help with providing completion candidates from previous sessions and activity in this session

(use-package dabbrev)
(use-package savehist :init (savehist-mode))
(use-package recentf :init (recentf-mode))

Completion at Point Functions

Add extra completion at point functions using Cape. Adding too many of these clutters up the completions list but file paths and Dabbrev are both useful for general usage.

(use-package cape
  :bind (("C-c p p" . completion-at-point)
         ("C-c p d" . cape-dabbrev)
         ("C-c p f" . cape-file))
  :init
  (add-to-list 'completion-at-point-functions #'cape-file)
  (add-to-list 'completion-at-point-functions #'cape-dabbrev)
  (add-to-list 'completion-at-point-functions #'cape-dict))

Completion Style

https://github.com/oantolin/orderless

(use-package orderless
  :init
  (setq completion-styles '(orderless basic)
        completion-category-defaults nil
        completion-category-overrides '((file (styles partial-completion)))))

Completing Read Functions

https://github.com/minad/consult

(use-package consult
  :bind
  (("C-s" . consult-line)
   ("C-x C-r" . consult-ripgrep)
   ("C-x b" . consult-buffer)
   ("C-x 4 b" . consult-buffer-other-window)
   ("M-g o" . consult-outline))
  :config
  (setq consult-ripgrep-args "rg --hidden --null --line-buffered --color=never --max-columns=1000 --path-separator /   --smart-case --no-heading --line-number .")
  (if (eq system-type 'darwin) (setq consult-locate-args "mdfind -name")))
(use-package consult-dir
  :bind (("C-x d" . consult-dir)
         :map vertico-map
         ("C-x d" . consult-dir)
         ("C-x C-j" . consult-dir-jump-file)))

Templates

I mainly use templates to insert org source blocks which seems like ridiculous overkill to include a whole package for, but maybe one day I will expand my usage (heh).

(use-package tempel
  :bind (("M-+" . tempel-complete)
         ("M-*" . tempel-insert))
  :hook ((prog-mode . tempel-setup-capf)
         (text-mode . tempel-setup-capf))
  :init
  ;; Setup completion at point
  (defun tempel-setup-capf ()
    (setq-local completion-at-point-functions
                (cons #'tempel-expand completion-at-point-functions)))
  :config
  (setq tempel-trigger-prefix "<"))

(use-package tempel-collection)

Command Execution

https://github.com/oantolin/embark

(use-package embark
  :bind
  (("C-." . embark-act))
  :init
  (setq prefix-help-command #'embark-prefix-help-command))

(use-package embark-consult
  :after (embark consult)
  :demand t
  :hook
  (embark-collect-mode . consult-preview-at-point-mode))