diff options
author | David Morgan <djm_uk@protonmail.com> | 2021-09-08 06:51:17 +0100 |
---|---|---|
committer | David Morgan <djm_uk@protonmail.com> | 2021-09-08 06:51:17 +0100 |
commit | d113ddd1f319386ee7381fb062c2d664b75a9de6 (patch) | |
tree | 8d315d5e0dec32734e85cefb0baf1d013c3f5cfc /.emacs.d/lisp/init-minibuffer.el | |
parent | fd95242ad0c0685597e97395985d3a42028531b3 (diff) | |
download | dotfiles-d113ddd1f319386ee7381fb062c2d664b75a9de6.tar.gz |
Only use vertico-directory bindings when completing files
Diffstat (limited to '.emacs.d/lisp/init-minibuffer.el')
-rw-r--r-- | .emacs.d/lisp/init-minibuffer.el | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/.emacs.d/lisp/init-minibuffer.el b/.emacs.d/lisp/init-minibuffer.el index 541f249..1865921 100644 --- a/.emacs.d/lisp/init-minibuffer.el +++ b/.emacs.d/lisp/init-minibuffer.el @@ -27,6 +27,20 @@ " ") cand))) :config + (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)))))) + (defun down-from-outside () "Move to next candidate in minibuffer, even when minibuffer isn't selected." (interactive) @@ -61,11 +75,13 @@ ;; See init-packages.el for fetching of Vertico Extenions ;; Required extensions must be in the vertico-extensions var (use-package vertico-directory + :after vertico :init (defvar switching-project nil) - (defun vertico-directory-enter-or-switch-project () - "Wrapper around vertico-directory-enter that plays nicely with adding projects." + (defun vertico-directory-enter-or-select-project () + "Wrapper around vertico-directory-enter that plays nicely with selecting new projects." (interactive) + ;; When selecting a project, use this to return, instead of entering the directory (if switching-project (vertico-exit) (vertico-directory-enter))) @@ -74,14 +90,21 @@ (apply orig args))) (advice-add 'project-prompt-project-dir :around 'read-project) + (define-vertico-key "/" + 'file #'vertico-directory-enter + 'project-file #'vertico-directory-enter) + (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) :config - (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)) @@ -90,12 +113,6 @@ (insert "~"))) :load-path vertico-extensions-dir :commands vertico-directory-enter - :bind (:map vertico-map - ("RET" . vertico-directory-enter-or-switch-project) - ("/" . vertico-directory-slash) - ("~" . vertico-directory-home) - ("DEL" . vertico-directory-delete-char) - ("M-DEL" . vertico-directory-delete-word)) ;; Tidy shadowed file names :hook (rfn-eshadow-update-overlay . vertico-directory-tidy)) |