doomemacs/modules/completion/vertico/config.el

200 lines
8.1 KiB
EmacsLisp
Raw Normal View History

;;; completion/vertico/config.el -*- lexical-binding: t; -*-
2021-01-16 03:04:18 +08:00
(defvar +vertico-company-completion-styles '(basic partial-completion orderless)
"Completion styles for company to use.
The completion/vertico module uses the orderless completion style by default,
2021-07-25 15:46:27 -04:00
but this returns too broad a candidate set for company completion. This variable
overrides `completion-styles' during company completion sessions.")
;;
;;; Packages
(use-package! vertico
:hook (doom-first-input . vertico-mode)
:config
(setq vertico-resize nil
vertico-count 17
2021-07-25 15:46:27 -04:00
vertico-cycle t
completion-in-region-function
(lambda (&rest args)
(apply (if vertico-mode
#'consult-completion-in-region
#'completion--in-region)
args)))
;; Cleans up path when moving directories with shadowed paths syntax, e.g.
;; cleans ~/foo/bar/// to /, and ~/foo/bar/~/ to ~/.
(add-hook 'rfn-eshadow-update-overlay-hook #'vertico-directory-tidy)
(map! :map vertico-map [backspace] #'+vertico/backward-updir))
2021-01-16 20:21:50 +08:00
(use-package! orderless
:after-call doom-first-input-hook
2021-01-16 20:21:50 +08:00
:config
(defun +vertico-orderless-dispatch (pattern _index _total)
(cond
;; Ensure that $ works with Consult commands, which add disambiguation suffixes
2021-07-25 15:46:27 -04:00
((string-suffix-p "$" pattern)
`(orderless-regexp . ,(concat (substring pattern 0 -1) "[\x100000-\x10FFFD]*$")))
;; Ignore single !
((string= "!" pattern) `(orderless-literal . ""))
;; Without literal
((string-prefix-p "!" pattern) `(orderless-without-literal . ,(substring pattern 1)))
;; Initialism matching
((string-prefix-p "`" pattern) `(orderless-initialism . ,(substring pattern 1)))
((string-suffix-p "`" pattern) `(orderless-initialism . ,(substring pattern 0 -1)))
;; Literal matching
((string-prefix-p "=" pattern) `(orderless-literal . ,(substring pattern 1)))
((string-suffix-p "=" pattern) `(orderless-literal . ,(substring pattern 0 -1)))
;; Flex matching
((string-prefix-p "~" pattern) `(orderless-flex . ,(substring pattern 1)))
((string-suffix-p "~" pattern) `(orderless-flex . ,(substring pattern 0 -1)))))
(setq completion-styles '(orderless)
completion-category-defaults nil
;; note that despite override in the name orderless can still be used in find-file etc.
completion-category-overrides '((file (styles . (orderless partial-completion))))
orderless-style-dispatchers '(+vertico-orderless-dispatch)
orderless-component-separator "[ &]")
;; otherwise find-file gets different highlighting than other commands
(set-face-attribute 'completions-first-difference nil :inherit nil))
2021-01-16 20:21:50 +08:00
2021-07-25 15:46:27 -04:00
2021-01-16 03:04:18 +08:00
(use-package! consult
:defer t
:init
(define-key!
[remap apropos] #'consult-apropos
[remap bookmark-jump] #'consult-bookmark
[remap evil-show-marks] #'consult-mark
[remap evil-show-jumps] #'+vertico/jump-list
[remap goto-line] #'consult-goto-line
[remap imenu] #'consult-imenu
[remap locate] #'consult-locate
[remap load-theme] #'consult-theme
[remap man] #'consult-man
[remap recentf-open-files] (cmd! (recentf-mode +1) (consult-recent-file))
[remap switch-to-buffer] #'consult-buffer
2021-01-16 03:04:18 +08:00
[remap switch-to-buffer-other-window] #'consult-buffer-other-window
[remap switch-to-buffer-other-frame] #'consult-buffer-other-frame
2021-04-29 12:32:04 +03:00
[remap yank-pop] #'consult-yank-pop
[remap persp-switch-to-buffer] #'+vertico/switch-workspace-buffer)
(advice-add #'completing-read-multiple :override #'consult-completing-read-multiple)
2021-07-25 15:46:27 -04:00
(advice-add #'multi-occur :override #'consult-multi-occur)
2021-01-16 20:21:50 +08:00
:config
(setq consult-project-root-function #'doom-project-root
consult-narrow-key "<"
consult-line-numbers-widen t
consult-async-min-input 2
consult-async-refresh-delay 0.15
consult-async-input-throttle 0.2
consult-async-input-debounce 0.1)
(when doom-projectile-fd-binary
(setq consult-find-command
(format "%s -i -H -E .git --regex %s ARG OPTS"
doom-projectile-fd-binary
(if IS-WINDOWS "--path-separator=/" ""))))
(consult-customize
consult-ripgrep consult-git-grep consult-grep
consult-bookmark consult-recent-file
+default/search-project +default/search-project-for-symbol-at-point
+default/search-other-project +vertico/search-symbol-at-point
+default/search-cwd +default/search-other-cwd
+default/search-notes-for-symbol-at-point
consult--source-file consult--source-project-file consult--source-bookmark
:preview-key (list (kbd "C-SPC") (kbd "C-M-j") (kbd "C-M-k")))
(consult-customize
consult-theme
:preview-key
(list (kbd "C-SPC") (kbd "C-M-j") (kbd "C-M-k")
:debounce 0.5 'any))
(after! org
(defvar +vertico--consult-org-source
`(:name "Org"
:narrow ?o
:hidden t
:category buffer
:state ,#'consult--buffer-state
:items ,(lambda () (mapcar #'buffer-name (org-buffer-list)))))
2021-07-31 10:43:00 +03:00
(add-to-list 'consult-buffer-sources '+vertico--consult-org-source 'append))
(map! :map consult-crm-map
:desc "Select candidate" "TAB" #'+vertico/crm-select
:desc "Enter candidates" "RET" #'+vertico/crm-exit))
2021-01-16 03:04:18 +08:00
2021-07-25 15:46:27 -04:00
2021-01-16 20:21:50 +08:00
(use-package! consult-flycheck
:when (featurep! :checkers syntax)
:after (consult flycheck))
2021-01-16 03:04:18 +08:00
2021-07-25 15:46:27 -04:00
2021-01-16 03:04:18 +08:00
(use-package! embark
:defer t
2021-01-16 03:04:18 +08:00
:init
2021-07-25 15:46:27 -04:00
(map! [remap describe-bindings] #'embark-bindings
"C-;" #'embark-act ; to be moved to :config default if accepted
(:map minibuffer-local-map
"C-;" #'embark-act
"C-c C-;" #'embark-export
:desc "Export to writable buffer" "C-c C-e" #'+vertico/embark-export-write)
(:leader
:desc "Actions" "a" #'embark-act)) ; to be moved to :config default if accepted
:config
2021-07-25 15:37:36 -04:00
(set-popup-rule! "^\\*Embark Export Grep" :size 0.35 :ttl 0 :quit nil)
(setq embark-indicator #'+vertico/embark-which-key-indicator)
;; add the package! target finder before the file target finder,
;; so we don't get a false positive match.
(let ((pos (or (cl-position
'embark-target-file-at-point
embark-target-finders)
(length embark-target-finders))))
(cl-callf2
cons
'+vertico-embark-target-package-fn
(nthcdr pos embark-target-finders)))
(setq embark-package-map (make-sparse-keymap))
2021-07-25 15:46:27 -04:00
(map! (:map embark-file-map
:desc "Open target with sudo" "s" #'doom/sudo-find-file
:desc "Open in new workspace" "TAB" #'+vertico/embark-open-in-new-workspace)
2021-07-25 15:46:27 -04:00
(:map embark-package-map
"h" #'doom/help-packages
"b" #'doom/bump-package
"c" #'doom/help-package-config
"u" #'doom/help-package-homepage)))
2021-01-16 03:04:18 +08:00
(use-package! marginalia
:hook (doom-first-input . marginalia-mode)
:init
(map! :map minibuffer-local-map
2021-07-25 15:46:27 -04:00
:desc "Cycle marginalia views" "M-A" #'marginalia-cycle)
:config
(when (featurep! +icons)
(add-hook 'marginalia-mode-hook #'all-the-icons-completion-marginalia-setup))
(advice-add #'marginalia--project-root :override #'doom-project-root)
2021-07-25 15:46:27 -04:00
(pushnew! marginalia-command-categories
'(+default/find-file-under-here. file)
'(doom/find-file-in-emacsd . project-file)
'(doom/find-file-in-other-project . project-file)
'(doom/find-file-in-private-config . file)
'(doom/describe-active-minor-mode . minor-mode)
'(flycheck-error-list-set-filter . builtin)
2021-07-25 15:46:27 -04:00
'(persp-switch-to-buffer . buffer)
'(projectile-find-file . project-file)
'(projectile-recentf . project-file)
'(projectile-switch-to-buffer . buffer)
'(projectile-switch-project . project-file)))
2021-07-25 15:46:27 -04:00
2021-01-16 03:04:18 +08:00
(use-package! embark-consult
:after (embark consult)
:config
(add-hook 'embark-collect-mode-hook #'consult-preview-at-point-mode))
2021-05-07 11:40:55 -05:00
2021-07-25 15:46:27 -04:00
2021-05-07 11:40:55 -05:00
(use-package! wgrep
:commands wgrep-change-to-wgrep-mode
:config (setq wgrep-auto-save-buffer t))