2021-08-28 13:41:35 +00:00
|
|
|
;;; init-minibuffer.el --- Minibuffer Completion Configuration File -*- lexical-binding: t -*-
|
|
|
|
;;; Commentary:
|
|
|
|
;; Config for completion etc in the minibuffer (vertico, embark, consult, etc)
|
|
|
|
;; Most of it is taken from the READMEs and wikis of those packages.
|
|
|
|
;; Relies on orderless config in init-completion.el
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(use-package emacs
|
|
|
|
:init
|
|
|
|
;; Do not allow the cursor in the minibuffer prompt
|
|
|
|
(setq minibuffer-prompt-properties
|
|
|
|
'(read-only t cursor-intangible t face minibuffer-prompt))
|
|
|
|
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
|
|
|
|
(setq enable-recursive-minibuffers t)
|
|
|
|
(minibuffer-depth-indicate-mode t))
|
|
|
|
|
|
|
|
(use-package vertico
|
|
|
|
:init
|
|
|
|
(vertico-mode)
|
|
|
|
(setq vertico-cycle t)
|
|
|
|
(advice-add #'vertico--format-candidate :around
|
2021-09-10 18:55:18 +00:00
|
|
|
(lambda (orig cand prefix suffix index start)
|
|
|
|
(setq cand (funcall orig cand prefix suffix index start))
|
2021-08-28 13:41:35 +00:00
|
|
|
(concat
|
|
|
|
(if (= vertico--index index)
|
|
|
|
(propertize "» " 'face 'vertico-current)
|
|
|
|
" ")
|
|
|
|
cand)))
|
|
|
|
:config
|
2021-09-08 05:51:17 +00:00
|
|
|
(defun define-vertico-key (key &rest defs)
|
|
|
|
"Define KEY conditionally in the vertico keymap.
|
|
|
|
DEFS is a plist associating completion categories to commands."
|
|
|
|
(let ((default-command (lookup-key vertico-map (kbd key))))
|
|
|
|
(define-key vertico-map (kbd key)
|
|
|
|
(list 'menu-item nil defs :filter
|
|
|
|
(lambda (d)
|
|
|
|
(or (plist-get d (completion-metadata-get
|
|
|
|
(completion-metadata (minibuffer-contents)
|
|
|
|
minibuffer-completion-table
|
|
|
|
minibuffer-completion-predicate)
|
|
|
|
'category))
|
|
|
|
default-command))))))
|
|
|
|
|
2021-08-28 13:41:35 +00:00
|
|
|
(defun down-from-outside ()
|
|
|
|
"Move to next candidate in minibuffer, even when minibuffer isn't selected."
|
|
|
|
(interactive)
|
|
|
|
(with-selected-window (active-minibuffer-window)
|
|
|
|
(execute-kbd-macro [down])))
|
|
|
|
|
|
|
|
(defun up-from-outside ()
|
|
|
|
"Move to previous candidate in minibuffer, even when minibuffer isn't selected."
|
|
|
|
(interactive)
|
|
|
|
(with-selected-window (active-minibuffer-window)
|
|
|
|
(execute-kbd-macro [up])))
|
|
|
|
|
|
|
|
(defun preview-from-outside ()
|
|
|
|
"Preview the selected candidate, even when minibuffer isn't selected."
|
|
|
|
(interactive)
|
|
|
|
(with-selected-window (active-minibuffer-window)
|
|
|
|
(execute-kbd-macro (kbd "M-."))))
|
|
|
|
|
|
|
|
(defun to-and-fro-minibuffer ()
|
|
|
|
"Go back and forth between minibuffer and other window."
|
|
|
|
(interactive)
|
|
|
|
(if (window-minibuffer-p (selected-window))
|
|
|
|
(select-window (minibuffer-selected-window))
|
|
|
|
(select-window (active-minibuffer-window))))
|
|
|
|
|
|
|
|
:bind (("C-M-<" . up-from-outside)
|
|
|
|
("C-M->" . down-from-outside)
|
|
|
|
("C-M-+" . preview-from-outside)
|
|
|
|
("M-X" . to-and-fro-minibuffer)
|
|
|
|
("C-M-S-g" . minibuffer-keyboard-quit)))
|
|
|
|
|
|
|
|
(use-package vertico-directory
|
2021-12-22 12:59:15 +00:00
|
|
|
:ensure nil
|
2021-09-08 05:51:17 +00:00
|
|
|
:after vertico
|
2021-08-28 13:41:35 +00:00
|
|
|
:init
|
|
|
|
(defvar switching-project nil)
|
2021-09-08 05:51:17 +00:00
|
|
|
(defun vertico-directory-enter-or-select-project ()
|
2022-05-17 14:51:57 +00:00
|
|
|
"vertico-directory-enter wrapper that plays nicely with selecting new projects."
|
2021-08-28 13:41:35 +00:00
|
|
|
(interactive)
|
2021-09-08 05:51:17 +00:00
|
|
|
;; When selecting a project, use this to return, instead of entering the directory
|
2021-08-28 13:41:35 +00:00
|
|
|
(if switching-project
|
|
|
|
(vertico-exit)
|
|
|
|
(vertico-directory-enter)))
|
2021-10-12 05:38:27 +00:00
|
|
|
(defun vertico-directory-slash ()
|
|
|
|
(interactive)
|
|
|
|
(if (and (>= vertico--index 0)
|
|
|
|
(string-suffix-p "/" (vertico--candidate))
|
|
|
|
(vertico-directory--completing-file-p))
|
|
|
|
(vertico-insert)
|
|
|
|
(insert "/")))
|
|
|
|
(defun vertico-directory-home ()
|
|
|
|
(interactive)
|
|
|
|
(if (and (string-suffix-p "/" (vertico--candidate))
|
|
|
|
(vertico-directory--completing-file-p))
|
|
|
|
(insert "~/")
|
|
|
|
(insert "~")))
|
2021-08-28 13:41:35 +00:00
|
|
|
(defun read-project (orig &rest args)
|
|
|
|
(let ((switching-project t))
|
|
|
|
(apply orig args)))
|
2021-09-01 15:28:44 +00:00
|
|
|
(advice-add 'project-prompt-project-dir :around
|
2021-08-28 13:41:35 +00:00
|
|
|
'read-project)
|
2021-09-08 05:51:17 +00:00
|
|
|
(define-vertico-key "/"
|
2021-09-09 15:45:49 +00:00
|
|
|
'file #'vertico-directory-slash
|
|
|
|
'project-file #'vertico-directory-slash)
|
2021-09-08 05:51:17 +00:00
|
|
|
(define-vertico-key "RET"
|
|
|
|
'file #'vertico-directory-enter-or-select-project
|
|
|
|
'project-file #'vertico-directory-enter)
|
|
|
|
(define-vertico-key "~"
|
|
|
|
'file #'vertico-directory-home)
|
|
|
|
(define-vertico-key "DEL"
|
|
|
|
'file #'vertico-directory-delete-char
|
|
|
|
'project-file #'vertico-directory-delete-char)
|
|
|
|
(define-vertico-key "M-DEL"
|
|
|
|
'file #'vertico-directory-delete-word
|
|
|
|
'project-file #'vertico-directory-delete-word)
|
2021-08-28 13:41:35 +00:00
|
|
|
:config
|
2021-10-12 05:38:27 +00:00
|
|
|
:commands (vertico-directory-enter vertico-directory-delete-word vertico-directory-delete-char)
|
2021-08-28 13:41:35 +00:00
|
|
|
;; Tidy shadowed file names
|
|
|
|
:hook (rfn-eshadow-update-overlay . vertico-directory-tidy))
|
|
|
|
|
|
|
|
(use-package vertico-repeat
|
2021-12-22 12:59:15 +00:00
|
|
|
:ensure nil
|
2021-08-28 13:41:35 +00:00
|
|
|
:bind ("M-P" . vertico-repeat))
|
|
|
|
|
|
|
|
(use-package consult
|
|
|
|
:bind (;; C-c bindings (mode-specific-map)
|
|
|
|
("C-c h" . consult-history)
|
|
|
|
("C-c m" . consult-mode-command)
|
|
|
|
("C-c b" . consult-bookmark)
|
|
|
|
("C-c k" . consult-kmacro)
|
|
|
|
;; C-x bindings (ctl-x-map)
|
|
|
|
("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command
|
|
|
|
("C-x b" . consult-buffer) ;; orig. switch-to-buffer
|
|
|
|
("C-x B" . consult-buffer-no-preview) ;; orig. switch-to-buffer
|
|
|
|
("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window
|
|
|
|
("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame
|
|
|
|
;; Custom M-# bindings for fast register access
|
|
|
|
("M-#" . consult-register-load)
|
|
|
|
("M-'" . consult-register-store) ;; orig. abbrev-prefix-mark (unrelated)
|
|
|
|
("C-M-#" . consult-register)
|
|
|
|
;; Other custom bindings
|
|
|
|
("C-S-s" . consult-line)
|
|
|
|
("M-*" . consult-line-symbol-at-point)
|
|
|
|
("C-c f" . consult-recent-file)
|
|
|
|
("C-c r" . consult-ripgrep)
|
2022-05-17 14:54:08 +00:00
|
|
|
;; TODO find an alternative to C-c c?
|
|
|
|
("C-c c r" . consult-ripgrep-auto-preview)
|
|
|
|
("C-c c s" . consult-ripgrep-case-sensitive)
|
|
|
|
("C-c c z" . consult-z-ripgrep)
|
2022-04-28 05:59:12 +00:00
|
|
|
("C-c C-*" . consult-ripgrep-symbol-at-point)
|
2021-08-28 13:41:35 +00:00
|
|
|
("M-y" . consult-yank-pop) ;; orig. yank-pop
|
|
|
|
("<help> a" . consult-apropos) ;; orig. apropos-command
|
|
|
|
;; M-g bindings (goto-map)
|
|
|
|
("M-g e" . consult-compile-error)
|
|
|
|
("M-g f" . consult-flycheck)
|
|
|
|
("M-g g" . consult-goto-line) ;; orig. goto-line
|
|
|
|
("M-g M-g" . consult-goto-line) ;; orig. goto-line
|
|
|
|
("M-g o" . consult-outline) ;; Alternative: consult-org-heading
|
|
|
|
("M-g m" . consult-mark)
|
|
|
|
("M-g k" . consult-global-mark)
|
|
|
|
("M-g i" . consult-imenu)
|
2021-09-14 19:09:14 +00:00
|
|
|
("M-g I" . consult-imenu-multi)
|
2021-08-28 13:41:35 +00:00
|
|
|
:map isearch-mode-map
|
2021-12-22 13:00:48 +00:00
|
|
|
("M-e" . consult-isearch-history) ;; orig. isearch-edit-string
|
|
|
|
("M-s e" . consult-isearch-history) ;; orig. isearch-edit-string
|
2021-09-07 18:23:56 +00:00
|
|
|
("M-s l" . consult-line) ;; needed by consult-line to detect isearch
|
|
|
|
(:map vertico-map
|
|
|
|
;; These are used for previewing with some consult commands (see consult-customize call below)
|
|
|
|
("C-S-p" . vertico-previous)
|
|
|
|
("C-S-n" . vertico-next)
|
|
|
|
;; Toggle preview on/off without changing preview-key
|
|
|
|
("M-P" . consult-toggle-preview)))
|
2021-08-28 13:41:35 +00:00
|
|
|
|
|
|
|
:init
|
|
|
|
|
|
|
|
;; Optionally configure the register formatting. This improves the register
|
|
|
|
;; preview for `consult-register', `consult-register-load',
|
|
|
|
;; `consult-register-store' and the Emacs built-ins.
|
|
|
|
(setq register-preview-delay 0
|
|
|
|
register-preview-function #'consult-register-format)
|
|
|
|
|
|
|
|
;; Optionally tweak the register preview window.
|
|
|
|
;; This adds thin lines, sorting and hides the mode line of the window.
|
|
|
|
(advice-add #'register-preview :override #'consult-register-window)
|
|
|
|
|
|
|
|
;; Optionally replace `completing-read-multiple' with an enhanced version.
|
|
|
|
(advice-add #'completing-read-multiple :override #'consult-completing-read-multiple)
|
|
|
|
|
|
|
|
;; Use Consult to select xref locations with preview
|
|
|
|
(setq xref-show-xrefs-function #'consult-xref
|
|
|
|
xref-show-definitions-function #'consult-xref)
|
|
|
|
|
|
|
|
:config
|
|
|
|
|
|
|
|
(defun consult-ripgrep-symbol-at-point (&optional dir initial)
|
|
|
|
(interactive
|
|
|
|
(list prefix-arg (when-let ((s (symbol-at-point)))
|
|
|
|
(symbol-name s))))
|
|
|
|
(consult-ripgrep dir initial))
|
|
|
|
(defun consult-ripgrep-auto-preview (&optional dir initial)
|
|
|
|
(interactive "P")
|
|
|
|
(consult-ripgrep dir initial))
|
|
|
|
(defun consult-ripgrep-unrestricted (&optional dir initial)
|
|
|
|
(interactive "P")
|
|
|
|
(let ((consult-ripgrep-args (replace-regexp-in-string "\\." "-uu ." consult-ripgrep-args)))
|
|
|
|
(consult-ripgrep dir initial)))
|
|
|
|
(defun consult-z-ripgrep (&optional dir initial)
|
|
|
|
(interactive "P")
|
|
|
|
(let ((consult-ripgrep-args (replace-regexp-in-string "\\." "-z ." consult-ripgrep-args)))
|
|
|
|
(consult-ripgrep dir initial)))
|
2022-05-17 14:54:08 +00:00
|
|
|
(defun consult-ripgrep-case-sensitive (&optional dir initial)
|
|
|
|
(interactive "P")
|
|
|
|
(let ((consult-ripgrep-args (replace-regexp-in-string "\\." "-s ." consult-ripgrep-args)))
|
|
|
|
(consult-ripgrep dir initial)))
|
2021-08-28 13:41:35 +00:00
|
|
|
(defun consult-buffer-no-preview ()
|
|
|
|
(interactive)
|
|
|
|
(consult-buffer))
|
|
|
|
(defun consult-line-symbol-at-point ()
|
|
|
|
(interactive)
|
|
|
|
(consult-line (thing-at-point 'symbol)))
|
2021-09-01 09:28:23 +00:00
|
|
|
(defvar consult--fd-command nil)
|
|
|
|
(defun consult--fd-builder (input)
|
|
|
|
(unless consult--fd-command
|
|
|
|
(setq consult--fd-command
|
|
|
|
(if (eq 0 (call-process-shell-command "fdfind"))
|
|
|
|
"fdfind"
|
|
|
|
"fd")))
|
|
|
|
(pcase-let* ((`(,arg . ,opts) (consult--command-split input))
|
|
|
|
(`(,re . ,hl) (funcall consult--regexp-compiler
|
|
|
|
arg 'extended)))
|
|
|
|
(when re
|
|
|
|
(list :command (append
|
|
|
|
(list consult--fd-command
|
|
|
|
"--color=never" "--full-path"
|
|
|
|
(consult--join-regexps re 'extended))
|
|
|
|
opts)
|
|
|
|
:highlight hl))))
|
|
|
|
|
|
|
|
(defun consult-fd (&optional dir initial)
|
|
|
|
(interactive "P")
|
|
|
|
(let* ((prompt-dir (consult--directory-prompt "Fd" dir))
|
|
|
|
(default-directory (cdr prompt-dir)))
|
|
|
|
(find-file (consult--find (car prompt-dir) #'consult--fd-builder initial))))
|
2021-08-28 13:41:35 +00:00
|
|
|
|
|
|
|
;; Add these here, as we have two bindings for search map (M-s and C-c s)
|
2021-09-01 09:28:23 +00:00
|
|
|
(define-key search-map "f" 'consult-fd)
|
|
|
|
(define-key search-map "F" 'consult-find)
|
|
|
|
(define-key search-map (kbd "M-f") 'consult-locate)
|
2021-08-28 13:41:35 +00:00
|
|
|
(define-key search-map "g" 'consult-grep)
|
|
|
|
(define-key search-map "G" 'consult-git-grep)
|
|
|
|
(define-key search-map "r" 'consult-ripgrep)
|
|
|
|
(define-key search-map "R" 'consult-ripgrep-auto-preview)
|
2021-09-01 09:28:23 +00:00
|
|
|
(define-key search-map (kbd "M-r") 'consult-ripgrep-unrestricted)
|
2021-08-28 13:41:35 +00:00
|
|
|
(define-key search-map "*" 'consult-ripgrep-symbol-at-point)
|
|
|
|
(define-key search-map "z" 'consult-z-ripgrep)
|
|
|
|
(define-key search-map "l" 'consult-line)
|
|
|
|
(define-key search-map "L" 'consult-line-multi)
|
|
|
|
(define-key search-map "m" 'consult-multi-occur)
|
|
|
|
(define-key search-map "k" 'consult-keep-lines)
|
|
|
|
(define-key search-map "u" 'consult-focus-lines)
|
|
|
|
(define-key search-map "e" 'consult-isearch)
|
|
|
|
|
|
|
|
(consult-customize
|
|
|
|
consult-theme
|
|
|
|
:preview-key '(:debounce 0.2 any)
|
2021-09-07 18:23:56 +00:00
|
|
|
;; For these commands we can use C-S/C-P to scoll and preview, or M-. to preview
|
2021-08-28 13:41:35 +00:00
|
|
|
consult-ripgrep consult-git-grep consult-grep
|
|
|
|
consult-ripgrep-unrestricted consult-ripgrep-symbol-at-point
|
|
|
|
consult-bookmark consult-recent-file consult-xref consult-buffer-no-preview
|
2022-02-28 11:39:13 +00:00
|
|
|
consult--source-recent-file consult--source-project-recent-file consult--source-bookmark
|
2021-09-07 18:23:56 +00:00
|
|
|
:preview-key (list (kbd "M-.") (kbd "C-S-n") (kbd "C-S-p")))
|
2021-08-28 13:41:35 +00:00
|
|
|
|
2021-09-09 15:49:51 +00:00
|
|
|
(defvar-local consult-toggle-preview-orig nil)
|
2021-09-07 18:23:56 +00:00
|
|
|
(defun consult-toggle-preview ()
|
|
|
|
"Command to enable/disable preview."
|
|
|
|
(interactive)
|
|
|
|
(if consult-toggle-preview-orig
|
|
|
|
(setq consult--preview-function consult-toggle-preview-orig
|
|
|
|
consult-toggle-preview-orig nil)
|
|
|
|
(setq consult-toggle-preview-orig consult--preview-function
|
|
|
|
consult--preview-function #'ignore)))
|
2021-08-28 13:41:35 +00:00
|
|
|
|
2021-09-07 18:23:56 +00:00
|
|
|
(setq consult-narrow-key "<")
|
2021-08-28 13:41:35 +00:00
|
|
|
|
2022-02-28 11:40:02 +00:00
|
|
|
(setq consult-project-function (lambda (_) (persp-current-project-root)))
|
2021-09-01 15:28:44 +00:00
|
|
|
|
2021-09-11 05:41:47 +00:00
|
|
|
;; Switches perspective if we select a buffer from another perspective, but note that previewing
|
|
|
|
;; a buffer adds it to the current perspective, so preview should be disabled before removing
|
|
|
|
;; perspective narrowing
|
|
|
|
(defun consult--persp-buffer-action (orig &rest args)
|
|
|
|
(when (not (cdr args)) ;; (cdr args) is norecord, which should distinguish preview/non-preview
|
|
|
|
(let ((buffer (window-normalize-buffer-to-switch-to (car args))))
|
|
|
|
(unless (persp-is-current-buffer buffer)
|
|
|
|
(let ((other-persp (persp-buffer-in-other-p buffer)))
|
|
|
|
(when (eq (car-safe other-persp) (selected-frame))
|
|
|
|
(persp-switch (cdr other-persp)))))))
|
|
|
|
(apply orig args))
|
|
|
|
(advice-add 'consult--buffer-action :around 'consult--persp-buffer-action)
|
2021-08-28 13:41:35 +00:00
|
|
|
|
|
|
|
(defvar consult-initial-narrow-config
|
2021-09-01 15:28:44 +00:00
|
|
|
'((consult-buffer . ?x)
|
2021-09-21 14:20:11 +00:00
|
|
|
(consult-buffer-no-preview . ?x)
|
|
|
|
(consult-buffer-other-window . ?x)))
|
2021-08-28 13:41:35 +00:00
|
|
|
;; Add initial narrowing hook
|
|
|
|
(defun consult-initial-narrow ()
|
|
|
|
(when-let (key (alist-get this-command consult-initial-narrow-config))
|
|
|
|
(setq unread-command-events (append unread-command-events (list key 32)))))
|
|
|
|
(add-hook 'minibuffer-setup-hook #'consult-initial-narrow)
|
|
|
|
|
2021-09-01 15:28:44 +00:00
|
|
|
(defvar consult--source-perspective-buffer
|
|
|
|
`(:name "Perspective Buffer"
|
|
|
|
:narrow (?x . "Perspective")
|
|
|
|
:hidden t
|
|
|
|
:category buffer
|
|
|
|
:face consult-buffer
|
|
|
|
:history buffer-name-history
|
|
|
|
:state ,#'consult--buffer-state
|
|
|
|
:enabled ,(lambda () persp-mode)
|
|
|
|
:items
|
|
|
|
,(lambda ()
|
|
|
|
(consult--buffer-query :sort 'visibility
|
|
|
|
:predicate #'persp-is-current-buffer
|
|
|
|
:as #'buffer-name)))
|
|
|
|
"Perspective buffer candidate source for `consult-buffer'.")
|
|
|
|
(add-to-list 'consult-buffer-sources 'consult--source-perspective-buffer t)
|
|
|
|
|
|
|
|
;; Copy of consult--source-project-file to use with perspective narrowing (identical except for narrowing key)
|
2021-09-03 06:35:31 +00:00
|
|
|
;; Put before consult--source-project-file so we get recentf behaviour here
|
2021-09-01 15:28:44 +00:00
|
|
|
(defvar consult--source-perspective-files
|
2021-12-22 13:00:48 +00:00
|
|
|
(plist-put (plist-put (copy-sequence consult--source-project-recent-file)
|
2021-09-07 18:24:48 +00:00
|
|
|
:name "Project File")
|
|
|
|
:narrow '(?x . "Perspective")))
|
2021-09-01 15:28:44 +00:00
|
|
|
(add-to-list 'consult-buffer-sources 'consult--source-perspective-files t)
|
|
|
|
|
|
|
|
;; Versions of consult--source-project-buffer and consult--source-project-file for use by consult-project-buffer
|
2021-09-17 15:37:43 +00:00
|
|
|
;; They allow narrowing with b, f and a (instead of p)
|
|
|
|
;; f is the recentf version provided by consult
|
|
|
|
;; a is an "all files" version based on fd (respecting .gitignore, hidden by default)
|
2021-09-01 15:28:44 +00:00
|
|
|
(defvar consult--project-source-project-buffer
|
|
|
|
(plist-put (plist-put (copy-sequence consult--source-project-buffer)
|
|
|
|
:hidden nil)
|
2021-09-07 18:24:48 +00:00
|
|
|
:narrow '(?b . "Buffer")))
|
2021-09-17 15:37:43 +00:00
|
|
|
(defvar consult--project-source-project-file-recentf
|
2021-12-22 13:00:48 +00:00
|
|
|
(plist-put (plist-put (copy-sequence consult--source-project-recent-file)
|
2021-09-17 15:37:43 +00:00
|
|
|
:hidden nil)
|
|
|
|
:narrow '(?f . "File (Recentf)")))
|
|
|
|
(defvar consult--project-source-project-file-all
|
2021-12-22 13:00:48 +00:00
|
|
|
(plist-put (plist-put (copy-sequence consult--source-project-recent-file)
|
2021-09-17 15:37:43 +00:00
|
|
|
:narrow '(?a . "File (All)"))
|
2021-09-06 12:41:50 +00:00
|
|
|
:items '(lambda ()
|
2021-09-17 15:37:43 +00:00
|
|
|
(when (eq 0 (call-process-shell-command "fd"))
|
|
|
|
(when-let (root (consult--project-root))
|
|
|
|
(let ((len (length root))
|
|
|
|
(inv-root (propertize root 'invisible t)))
|
|
|
|
(mapcar (lambda (x)
|
|
|
|
(concat inv-root (substring x len)))
|
|
|
|
(split-string
|
|
|
|
(shell-command-to-string
|
|
|
|
(format "fd --color never -t f -0 . %s" root))
|
|
|
|
"\0" t))))))))
|
2021-09-01 15:28:44 +00:00
|
|
|
|
|
|
|
(defun consult-project-buffer ()
|
|
|
|
(interactive)
|
|
|
|
(let ((consult-buffer-sources '(consult--project-source-project-buffer
|
2021-09-17 15:37:43 +00:00
|
|
|
consult--project-source-project-file-recentf
|
|
|
|
consult--project-source-project-file-all)))
|
2021-09-01 15:28:44 +00:00
|
|
|
(consult-buffer)))
|
2021-08-28 13:41:35 +00:00
|
|
|
|
|
|
|
(defun consult--orderless-regexp-compiler (input type)
|
|
|
|
(setq input (orderless-pattern-compiler input))
|
|
|
|
(cons
|
|
|
|
(mapcar (lambda (r) (consult--convert-regexp r type)) input)
|
|
|
|
(lambda (str) (orderless--highlight input str))))
|
|
|
|
(defun consult--with-orderless (&rest args)
|
|
|
|
(minibuffer-with-setup-hook
|
|
|
|
(lambda ()
|
|
|
|
(setq-local consult--regexp-compiler #'consult--orderless-regexp-compiler))
|
|
|
|
(apply args)))
|
|
|
|
(advice-add #'consult-ripgrep :around #'consult--with-orderless))
|
|
|
|
|
|
|
|
(use-package consult-flycheck)
|
|
|
|
|
|
|
|
(use-package consult-lsp
|
|
|
|
:bind (:map lsp-mode-map
|
|
|
|
([remap xref-find-apropos] . consult-lsp-symbols)))
|
|
|
|
|
|
|
|
(use-package consult-dir
|
|
|
|
:ensure t
|
|
|
|
:bind (("C-x C-d" . consult-dir)
|
2021-09-01 15:17:23 +00:00
|
|
|
:map vertico-map
|
2021-08-28 13:41:35 +00:00
|
|
|
("C-x C-d" . consult-dir)
|
|
|
|
("C-x C-j" . consult-dir-jump-file)))
|
|
|
|
|
|
|
|
(use-package marginalia
|
|
|
|
:init
|
2021-09-01 15:17:23 +00:00
|
|
|
(marginalia-mode))
|
2021-08-28 13:41:35 +00:00
|
|
|
|
|
|
|
(use-package embark
|
|
|
|
:bind
|
|
|
|
(("C-," . embark-act)
|
|
|
|
("C-." . embark-dwim)
|
2021-09-04 15:08:03 +00:00
|
|
|
("M-." . embark-dwim)
|
2021-08-28 13:41:35 +00:00
|
|
|
("C-c C-o" . embark-export)
|
|
|
|
("C-h b" . embark-bindings)
|
2021-09-01 09:34:46 +00:00
|
|
|
("C-h B" . describe-bindings)
|
|
|
|
(:map minibuffer-local-map
|
|
|
|
("M-." . embark-preview)))
|
2021-08-28 13:41:35 +00:00
|
|
|
:init
|
|
|
|
(setq prefix-help-command #'embark-prefix-help-command)
|
|
|
|
:config
|
2021-09-01 09:34:46 +00:00
|
|
|
(defun embark-preview ()
|
|
|
|
(interactive)
|
|
|
|
(unless (bound-and-true-p consult--preview-function) ;; Disable preview for Consult commands
|
|
|
|
(save-selected-window
|
|
|
|
(let ((embark-quit-after-action))
|
2021-09-06 20:00:01 +00:00
|
|
|
(embark-dwim)))))
|
2021-09-01 09:34:46 +00:00
|
|
|
|
2021-08-28 13:41:35 +00:00
|
|
|
;; Hide the mode line of the Embark live/completions buffers
|
|
|
|
(add-to-list 'display-buffer-alist
|
|
|
|
'("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
|
|
|
|
nil
|
|
|
|
(window-parameters (mode-line-format . none)))))
|
|
|
|
|
|
|
|
(use-package embark-consult
|
|
|
|
:after (embark consult)
|
|
|
|
:demand t ; only necessary if you have the hook below
|
|
|
|
;; if you want to have consult previews as you move around an
|
|
|
|
;; auto-updating embark collect buffer
|
|
|
|
:hook
|
|
|
|
(embark-collect-mode . consult-preview-at-point-mode))
|
|
|
|
|
|
|
|
(provide 'init-minibuffer)
|
|
|
|
;;; init-minibuffer.el ends here
|