feat(vertico): bind C-h/C-l to enter-or-preview/move up
Close: #7001 Ref: #6853
This commit is contained in:
parent
1a01620705
commit
890f200b41
2 changed files with 28 additions and 3 deletions
|
@ -112,9 +112,28 @@ Supports exporting consult-grep to wgrep, file to wdeired, and consult-location
|
||||||
"Previews candidate in vertico buffer, unless it's a consult command"
|
"Previews candidate in vertico buffer, unless it's a consult command"
|
||||||
(interactive)
|
(interactive)
|
||||||
(unless (bound-and-true-p consult--preview-function)
|
(unless (bound-and-true-p consult--preview-function)
|
||||||
|
(if (fboundp 'embark-dwim)
|
||||||
(save-selected-window
|
(save-selected-window
|
||||||
(let ((embark-quit-after-action nil))
|
(let (embark-quit-after-action)
|
||||||
(embark-dwim)))))
|
(embark-dwim)))
|
||||||
|
(user-error "Embark not installed, aborting..."))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +vertico/enter-or-preview ()
|
||||||
|
"Enter directory or embark preview on current candidate."
|
||||||
|
(interactive)
|
||||||
|
(when (> 0 vertico--index)
|
||||||
|
(user-error "No vertico session is currently active"))
|
||||||
|
(if (and (let ((cand (vertico--candidate)))
|
||||||
|
(or (string-suffix-p "/" cand)
|
||||||
|
(and (vertico--remote-p cand)
|
||||||
|
(string-suffix-p ":" cand))))
|
||||||
|
(not (equal vertico--base ""))
|
||||||
|
(eq 'file (vertico--metadata-get 'category)))
|
||||||
|
(vertico-insert)
|
||||||
|
(condition-case _
|
||||||
|
(+vertico/embark-preview)
|
||||||
|
(user-error (vertico-directory-enter)))))
|
||||||
|
|
||||||
(defvar +vertico/find-file-in--history nil)
|
(defvar +vertico/find-file-in--history nil)
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
|
|
@ -34,6 +34,12 @@ overrides `completion-styles' during company completion sessions.")
|
||||||
#'consult-completion-in-region
|
#'consult-completion-in-region
|
||||||
#'completion--in-region)
|
#'completion--in-region)
|
||||||
args)))
|
args)))
|
||||||
|
|
||||||
|
(map! :when (modulep! :editor evil +everywhere)
|
||||||
|
:map vertico-map
|
||||||
|
"C-h" (cmds! (eq 'file (vertico--metadata-get 'category)) #'vertico-directory-up)
|
||||||
|
"C-l" (cmds! (eq 'file (vertico--metadata-get 'category)) #'+vertico/enter-or-preview))
|
||||||
|
|
||||||
;; Cleans up path when moving directories with shadowed paths syntax, e.g.
|
;; Cleans up path when moving directories with shadowed paths syntax, e.g.
|
||||||
;; cleans ~/foo/bar/// to /, and ~/foo/bar/~/ to ~/.
|
;; cleans ~/foo/bar/// to /, and ~/foo/bar/~/ to ~/.
|
||||||
(add-hook 'rfn-eshadow-update-overlay-hook #'vertico-directory-tidy)
|
(add-hook 'rfn-eshadow-update-overlay-hook #'vertico-directory-tidy)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue