2021-07-09 20:16:11 +03:00
|
|
|
;;; completion/vertico/config.el -*- lexical-binding: t; -*-
|
2021-01-16 03:04:18 +08:00
|
|
|
|
2021-07-24 17:21:55 +03: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.")
|
|
|
|
|
2021-09-15 01:07:06 +03:00
|
|
|
(defvar +vertico-consult-fd-args nil
|
|
|
|
"Shell command and arguments the vertico module uses for fd.")
|
2021-07-25 15:46:27 -04:00
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Packages
|
2021-07-24 17:21:55 +03:00
|
|
|
|
2021-06-30 17:36:08 +03:00
|
|
|
(use-package! vertico
|
|
|
|
:hook (doom-first-input . vertico-mode)
|
2021-07-24 15:00:46 +03:00
|
|
|
:config
|
2021-06-30 17:36:08 +03:00
|
|
|
(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)
|
2021-11-11 01:45:10 +02:00
|
|
|
(add-hook 'minibuffer-setup-hook #'vertico-repeat-save)
|
2021-08-22 15:22:28 +03:00
|
|
|
(map! :map vertico-map [backspace] #'vertico-directory-delete-char))
|
2021-07-25 15:46:27 -04:00
|
|
|
|
2021-06-30 17:36:08 +03:00
|
|
|
|
2021-01-16 20:21:50 +08:00
|
|
|
(use-package! orderless
|
2021-07-24 15:49:57 +03:00
|
|
|
:after-call doom-first-input-hook
|
2021-01-16 20:21:50 +08:00
|
|
|
:config
|
2021-10-17 14:12:41 +03:00
|
|
|
(defadvice! +vertico--company-capf--candidates-a (fn &rest args)
|
|
|
|
"Highlight company matches correctly, and try default completion styles before
|
|
|
|
orderless."
|
|
|
|
:around #'company-capf--candidates
|
|
|
|
(let ((orderless-match-faces [completions-common-part])
|
|
|
|
(completion-styles +vertico-company-completion-styles))
|
|
|
|
(apply fn args)))
|
|
|
|
|
2021-07-09 20:28:40 +03:00
|
|
|
(defun +vertico-orderless-dispatch (pattern _index _total)
|
2021-05-04 16:16:36 +03:00
|
|
|
(cond
|
2021-08-04 01:31:48 -04:00
|
|
|
;; Ensure $ 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]*$")))
|
2021-05-04 16:16:36 +03:00
|
|
|
;; Ignore single !
|
|
|
|
((string= "!" pattern) `(orderless-literal . ""))
|
|
|
|
;; Without literal
|
|
|
|
((string-prefix-p "!" pattern) `(orderless-without-literal . ,(substring pattern 1)))
|
2021-08-10 17:51:00 +03:00
|
|
|
;; Character folding
|
|
|
|
((string-prefix-p "%" pattern) `(char-fold-to-regexp . ,(substring pattern 1)))
|
|
|
|
((string-suffix-p "%" pattern) `(char-fold-to-regexp . ,(substring pattern 0 -1)))
|
2021-05-16 03:18:13 +03:00
|
|
|
;; 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)))
|
2021-05-04 16:16:36 +03:00
|
|
|
((string-suffix-p "=" pattern) `(orderless-literal . ,(substring pattern 0 -1)))
|
|
|
|
;; Flex matching
|
2021-05-16 03:18:13 +03:00
|
|
|
((string-prefix-p "~" pattern) `(orderless-flex . ,(substring pattern 1)))
|
2021-05-04 16:16:36 +03:00
|
|
|
((string-suffix-p "~" pattern) `(orderless-flex . ,(substring pattern 0 -1)))))
|
2021-08-13 00:26:10 +03:00
|
|
|
(add-to-list
|
|
|
|
'completion-styles-alist
|
|
|
|
'(+vertico-basic-remote
|
|
|
|
+vertico-basic-remote-try-completion
|
|
|
|
+vertico-basic-remote-all-completions
|
|
|
|
"Use basic completion on remote files only"))
|
2021-05-01 14:44:29 +03:00
|
|
|
(setq completion-styles '(orderless)
|
2021-05-04 16:16:36 +03:00
|
|
|
completion-category-defaults nil
|
2021-08-04 01:31:48 -04:00
|
|
|
;; note that despite override in the name orderless can still be used in
|
|
|
|
;; find-file etc.
|
2021-08-13 00:26:10 +03:00
|
|
|
completion-category-overrides '((file (styles +vertico-basic-remote orderless partial-completion)))
|
2021-07-09 20:28:40 +03:00
|
|
|
orderless-style-dispatchers '(+vertico-orderless-dispatch)
|
2021-06-30 17:36:08 +03:00
|
|
|
orderless-component-separator "[ &]")
|
2021-08-04 01:31:48 -04:00
|
|
|
;; ...otherwise find-file gets different highlighting than other commands
|
2021-07-09 19:59:44 +03:00
|
|
|
(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!
|
2021-02-18 22:06:00 -06:00
|
|
|
[remap apropos] #'consult-apropos
|
|
|
|
[remap bookmark-jump] #'consult-bookmark
|
|
|
|
[remap evil-show-marks] #'consult-mark
|
2021-07-28 13:02:46 -04:00
|
|
|
[remap evil-show-jumps] #'+vertico/jump-list
|
2021-02-18 22:06:00 -06:00
|
|
|
[remap goto-line] #'consult-goto-line
|
|
|
|
[remap imenu] #'consult-imenu
|
|
|
|
[remap locate] #'consult-locate
|
|
|
|
[remap load-theme] #'consult-theme
|
|
|
|
[remap man] #'consult-man
|
2021-07-31 10:47:00 +03:00
|
|
|
[remap recentf-open-files] #'consult-recent-file
|
2021-02-18 22:06:00 -06:00
|
|
|
[remap switch-to-buffer] #'consult-buffer
|
2021-01-16 03:04:18 +08:00
|
|
|
[remap switch-to-buffer-other-window] #'consult-buffer-other-window
|
2021-02-18 22:06:00 -06:00
|
|
|
[remap switch-to-buffer-other-frame] #'consult-buffer-other-frame
|
2021-04-29 12:32:04 +03:00
|
|
|
[remap yank-pop] #'consult-yank-pop
|
2021-07-09 20:28:40 +03:00
|
|
|
[remap persp-switch-to-buffer] #'+vertico/switch-workspace-buffer)
|
2021-07-09 16:41:12 +03:00
|
|
|
(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
|
2021-10-17 14:12:41 +03:00
|
|
|
(defadvice! +vertico--consult-recent-file-a (&rest _args)
|
|
|
|
"`consult-recent-file' needs to have `recentf-mode' on to work correctly"
|
|
|
|
:before #'consult-recent-file
|
|
|
|
(recentf-mode +1))
|
|
|
|
|
2021-05-16 02:29:48 +03:00
|
|
|
(setq consult-project-root-function #'doom-project-root
|
|
|
|
consult-narrow-key "<"
|
2021-07-26 02:55:20 -04:00
|
|
|
consult-line-numbers-widen t
|
2021-07-26 03:00:40 -04:00
|
|
|
consult-async-min-input 2
|
|
|
|
consult-async-refresh-delay 0.15
|
|
|
|
consult-async-input-throttle 0.2
|
|
|
|
consult-async-input-debounce 0.1)
|
2021-09-15 01:07:06 +03:00
|
|
|
(unless +vertico-consult-fd-args
|
|
|
|
(setq +vertico-consult-fd-args
|
|
|
|
(if doom-projectile-fd-binary
|
|
|
|
(format "%s --color=never -i -H -E .git --regex %s"
|
|
|
|
doom-projectile-fd-binary
|
|
|
|
(if IS-WINDOWS "--path-separator=/" ""))
|
|
|
|
consult-find-args)))
|
2021-07-25 18:02:46 -04:00
|
|
|
|
2021-05-26 02:33:13 +03:00
|
|
|
(consult-customize
|
|
|
|
consult-ripgrep consult-git-grep consult-grep
|
|
|
|
consult-bookmark consult-recent-file
|
2021-10-30 19:46:16 +03:00
|
|
|
+default/search-project +default/search-other-project
|
|
|
|
+default/search-project-for-symbol-at-point
|
2021-05-26 02:33:13 +03:00
|
|
|
+default/search-cwd +default/search-other-cwd
|
|
|
|
+default/search-notes-for-symbol-at-point
|
|
|
|
consult--source-file consult--source-project-file consult--source-bookmark
|
2021-09-15 01:14:49 +03:00
|
|
|
:preview-key (kbd "C-SPC"))
|
2021-07-02 02:59:47 +03:00
|
|
|
(consult-customize
|
|
|
|
consult-theme
|
2021-09-15 01:14:49 +03:00
|
|
|
:preview-key (list (kbd "C-SPC") :debounce 0.5 'any))
|
2021-07-13 15:33:27 +03:00
|
|
|
(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-11-01 13:49:28 +02:00
|
|
|
(use-package! consult-dir
|
|
|
|
:bind (([remap list-directory] . consult-dir)
|
|
|
|
:map vertico-map
|
|
|
|
("C-x C-d" . consult-dir)
|
|
|
|
("C-x C-j" . consult-dir-jump-file)))
|
|
|
|
|
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
|
2021-07-24 15:49:57 +03:00
|
|
|
:defer t
|
2021-01-16 03:04:18 +08:00
|
|
|
:init
|
2021-08-07 02:17:02 +03:00
|
|
|
(setq which-key-use-C-h-commands nil
|
|
|
|
prefix-help-command #'embark-prefix-help-command)
|
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
|
2021-04-27 02:49:47 +03:00
|
|
|
:config
|
2021-07-25 15:37:36 -04:00
|
|
|
(set-popup-rule! "^\\*Embark Export Grep" :size 0.35 :ttl 0 :quit nil)
|
2021-10-17 14:34:38 +03:00
|
|
|
|
|
|
|
(defadvice! +vertico--embark-which-key-prompt-a (fn &rest args)
|
|
|
|
"Hide the which-key indicator immediately when using the completing-read prompter."
|
|
|
|
:around #'embark-completing-read-prompter
|
|
|
|
(which-key--hide-popup-ignore-command)
|
|
|
|
(let ((embark-indicators
|
|
|
|
(remq #'embark-which-key-indicator embark-indicators)))
|
|
|
|
(apply fn args)))
|
2021-08-10 17:52:00 +03:00
|
|
|
(cl-nsubstitute #'+vertico-embark-which-key-indicator #'embark-mixed-indicator embark-indicators)
|
2021-08-10 17:50:00 +03:00
|
|
|
(add-to-list 'embark-indicators #'+vertico-embark-vertico-indicator)
|
2021-06-01 18:10:03 +03:00
|
|
|
;; 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
|
2021-07-28 11:51:19 -04:00
|
|
|
'+vertico-embark-target-package-fn
|
2021-06-01 18:10:03 +03:00
|
|
|
(nthcdr pos embark-target-finders)))
|
2021-08-22 00:37:57 +03:00
|
|
|
(embark-define-keymap +vertico/embark-doom-package-map
|
|
|
|
"Keymap for Embark package actions for packages installed by Doom."
|
|
|
|
("h" doom/help-packages)
|
|
|
|
("b" doom/bump-package)
|
|
|
|
("c" doom/help-package-config)
|
|
|
|
("u" doom/help-package-homepage))
|
|
|
|
(setf (alist-get 'package embark-keymap-alist) #'+vertico/embark-doom-package-map)
|
2021-07-25 15:46:27 -04:00
|
|
|
(map! (:map embark-file-map
|
2021-08-17 21:59:14 +03:00
|
|
|
:desc "Open target with sudo" "s" #'doom/sudo-find-file
|
2021-08-17 22:04:38 +03:00
|
|
|
(:when (featurep! :tools magit)
|
|
|
|
:desc "Open magit-status of target" "g" #'+vertico/embark-magit-status)
|
2021-08-17 21:59:14 +03:00
|
|
|
(:when (featurep! :ui workspaces)
|
2021-08-22 00:37:57 +03:00
|
|
|
:desc "Open in new workspace" "TAB" #'+vertico/embark-open-in-new-workspace))))
|
2021-07-25 15:46:27 -04:00
|
|
|
|
2021-01-16 03:04:18 +08:00
|
|
|
|
|
|
|
(use-package! marginalia
|
|
|
|
:hook (doom-first-input . marginalia-mode)
|
2021-05-29 16:02:02 +03:00
|
|
|
:init
|
|
|
|
(map! :map minibuffer-local-map
|
2021-07-25 15:46:27 -04:00
|
|
|
:desc "Cycle marginalia views" "M-A" #'marginalia-cycle)
|
2021-04-11 00:48:39 +03:00
|
|
|
:config
|
2021-07-24 15:00:46 +03:00
|
|
|
(when (featurep! +icons)
|
|
|
|
(add-hook 'marginalia-mode-hook #'all-the-icons-completion-marginalia-setup))
|
2021-07-31 10:46:00 +03:00
|
|
|
(advice-add #'marginalia--project-root :override #'doom-project-root)
|
2021-07-25 15:46:27 -04:00
|
|
|
(pushnew! marginalia-command-categories
|
2021-10-10 10:47:14 +03:00
|
|
|
'(+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)
|
2021-07-31 10:46:00 +03:00
|
|
|
'(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)
|
2021-07-31 10:46:00 +03:00
|
|
|
'(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)
|
2021-07-13 13:55:15 +03:00
|
|
|
: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))
|