2021-07-09 20:16:11 +03:00
|
|
|
;;; completion/vertico/config.el -*- lexical-binding: t; -*-
|
2021-01-16 03:04:18 +08:00
|
|
|
|
2021-06-30 17:36:08 +03:00
|
|
|
(use-package! vertico
|
|
|
|
:hook (doom-first-input . vertico-mode)
|
|
|
|
:init
|
|
|
|
(setq vertico-resize nil
|
|
|
|
vertico-count 17
|
|
|
|
vertico-cycle t)
|
2021-07-07 01:35:28 +03:00
|
|
|
(add-hook 'vertico-mode-hook (lambda ()
|
|
|
|
(setq completion-in-region-function
|
|
|
|
(if vertico-mode
|
|
|
|
#'consult-completion-in-region
|
|
|
|
#'completion--in-region))))
|
2021-06-30 17:36:08 +03:00
|
|
|
:config
|
2021-07-18 21:27:44 +03:00
|
|
|
(add-hook 'rfn-eshadow-update-overlay-hook #'vertico-directory-tidy)
|
2021-06-30 17:36:08 +03:00
|
|
|
(map! :map vertico-map
|
2021-07-09 20:28:40 +03:00
|
|
|
[backspace] #'+vertico/backward-updir))
|
2021-06-30 17:36:08 +03:00
|
|
|
|
2021-01-16 20:21:50 +08:00
|
|
|
(use-package! orderless
|
|
|
|
:config
|
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-05-16 03:18:13 +03:00
|
|
|
;; Ensure that $ works with Consult commands, which add disambiguation suffixes
|
2021-05-04 16:16:36 +03: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)))
|
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-05-01 14:44:29 +03:00
|
|
|
(setq completion-styles '(orderless)
|
2021-05-04 16:16:36 +03:00
|
|
|
completion-category-defaults nil
|
|
|
|
;; note that despite override in the name orderless can still be used in find-file etc.
|
2021-06-30 17:36:08 +03:00
|
|
|
completion-category-overrides '((file (styles . (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 "[ &]")
|
|
|
|
;; 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-01-16 03:04:18 +08:00
|
|
|
(use-package! consult
|
|
|
|
:defer t
|
|
|
|
:init
|
2021-01-16 20:21:50 +08:00
|
|
|
(fset 'multi-occur #'consult-multi-occur)
|
2021-01-16 03:04:18 +08:00
|
|
|
(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
|
|
|
|
[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] #'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
|
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-01-16 20:21:50 +08:00
|
|
|
:config
|
2021-04-25 21:08:13 +03:00
|
|
|
(recentf-mode)
|
2021-05-16 02:29:48 +03:00
|
|
|
(setq consult-project-root-function #'doom-project-root
|
|
|
|
consult-narrow-key "<"
|
2021-06-29 20:03:26 +03:00
|
|
|
consult-line-numbers-widen t)
|
2021-05-26 02:33:13 +03:00
|
|
|
(consult-customize
|
|
|
|
consult-ripgrep consult-git-grep consult-grep
|
|
|
|
consult-bookmark consult-recent-file
|
|
|
|
+default/search-project +default/search-project-for-symbol-at-point
|
2021-07-09 20:28:40 +03:00
|
|
|
+default/search-other-project +vertico/search-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-07-02 02:59:47 +03:00
|
|
|
: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")
|
2021-07-13 15:33:27 +03:00
|
|
|
: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)))))
|
|
|
|
(add-to-list 'consult-buffer-sources '+vertico--consult-org-source 'append)))
|
2021-01-16 03:04:18 +08: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
|
|
|
|
|
|
|
(use-package! embark
|
|
|
|
:init
|
2021-02-16 16:46:35 -06:00
|
|
|
(setq embark-action-indicator
|
2021-05-17 00:14:55 +03:00
|
|
|
(lambda (map _target)
|
2021-02-16 16:46:35 -06:00
|
|
|
(which-key--show-keymap "Embark" map nil nil 'no-paging)
|
|
|
|
#'which-key--hide-popup-ignore-command)
|
2021-04-27 02:49:47 +03:00
|
|
|
embark-become-indicator embark-action-indicator)
|
2021-05-29 16:02:02 +03:00
|
|
|
(map! "C-;" #'embark-act ; to be moved to :config default if accepted
|
|
|
|
:leader
|
|
|
|
:desc "Actions" "a" #'embark-act) ; to be moved to :config default if accepted
|
|
|
|
(map! :map minibuffer-local-map
|
|
|
|
"C-;" #'embark-act
|
|
|
|
"C-c C-;" #'embark-export
|
|
|
|
:desc "Export to writable buffer"
|
2021-07-09 20:28:40 +03:00
|
|
|
"C-c C-e" #'+vertico/embark-export-write)
|
2021-05-29 16:02:02 +03:00
|
|
|
(define-key!
|
|
|
|
[remap describe-bindings] #'embark-bindings)
|
2021-07-09 20:28:40 +03:00
|
|
|
(defun +vertico--embark-target-package! ()
|
2021-05-31 16:27:27 +03:00
|
|
|
"Targets Doom's package! statements and returns the package name"
|
|
|
|
(when (or (derived-mode-p 'emacs-lisp-mode) (derived-mode-p 'org-mode))
|
|
|
|
(save-excursion
|
|
|
|
(search-backward "(")
|
|
|
|
(when (looking-at "(\\s-*package!\\s-*\\(\\(\\sw\\|\\s_\\)+\\)\\s-*")
|
|
|
|
(let ((pkg (match-string 1)))
|
|
|
|
(set-text-properties 0 (length pkg) nil pkg)
|
|
|
|
`(package . ,pkg))))))
|
2021-04-27 02:49:47 +03:00
|
|
|
:config
|
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-09 20:28:40 +03:00
|
|
|
'+vertico--embark-target-package!
|
2021-06-01 18:10:03 +03:00
|
|
|
(nthcdr pos embark-target-finders)))
|
2021-04-29 12:32:04 +03:00
|
|
|
(map!
|
|
|
|
:map embark-file-map
|
2021-06-08 03:58:15 +03:00
|
|
|
:desc "Open target with sudo" "s" #'doom/sudo-find-file
|
2021-07-09 20:28:40 +03:00
|
|
|
:desc "Open in new workspace" "TAB" #'+vertico-embark-open-in-new-workspace)
|
2021-05-31 16:40:36 +03:00
|
|
|
(setq embark-package-map (make-sparse-keymap))
|
|
|
|
(map! :map embark-package-map
|
|
|
|
"h" #'doom/help-packages
|
|
|
|
"b" #'doom/bump-package
|
|
|
|
"c" #'doom/help-package-config
|
2021-07-01 00:11:46 +03:00
|
|
|
"u" #'doom/help-package-homepage))
|
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
|
2021-07-04 04:15:58 +03:00
|
|
|
(when (featurep! +icons)
|
2021-07-18 17:33:52 +03:00
|
|
|
(add-hook 'marginalia-mode-hook #'all-the-icons-completion-marginalia-setup))
|
2021-05-29 16:02:02 +03:00
|
|
|
(map! :map minibuffer-local-map
|
|
|
|
:desc "Cycle marginalia views"
|
|
|
|
"M-A" #'marginalia-cycle)
|
2021-04-11 00:48:39 +03:00
|
|
|
:config
|
2021-06-02 15:16:25 +03:00
|
|
|
(nconc marginalia-command-categories
|
|
|
|
'((persp-switch-to-buffer . buffer)
|
|
|
|
(projectile-find-file . project-file)
|
2021-07-09 16:45:00 +03:00
|
|
|
(doom/describe-active-minor-mode . minor-mode)
|
|
|
|
(flycheck-error-list-set-filter . builtin))))
|
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
|
|
|
|
|
|
|
(use-package! wgrep
|
|
|
|
:commands wgrep-change-to-wgrep-mode
|
|
|
|
:config (setq wgrep-auto-save-buffer t))
|