diff options
author | David Morgan <djm_uk@protonmail.com> | 2024-09-26 17:02:03 +0100 |
---|---|---|
committer | David Morgan <djm_uk@protonmail.com> | 2024-09-26 17:02:03 +0100 |
commit | 38fe5a77794a530162ef451536e0907bf76c12d3 (patch) | |
tree | be5d72d7a3a9b7df08fefeefed1d911bd96304c3 | |
parent | fd03e29e94de46aefb11c14d580ae70a73023907 (diff) | |
download | dotfiles-38fe5a77794a530162ef451536e0907bf76c12d3.tar.gz |
Allow toggling sorting files with directories first
-rw-r--r-- | .emacs.d/lisp/init-minibuffer.el | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/.emacs.d/lisp/init-minibuffer.el b/.emacs.d/lisp/init-minibuffer.el index 2b38c81..1d5b212 100644 --- a/.emacs.d/lisp/init-minibuffer.el +++ b/.emacs.d/lisp/init-minibuffer.el @@ -74,12 +74,28 @@ (select-window (minibuffer-selected-window)) (select-window (active-minibuffer-window)))) + ;; https://github.com/minad/vertico/wiki#customize-sorting-based-on-completion-category + (defun sort-directories-first (files) + ;; Still sort by history position, length and alphabetically + (setq files (vertico-sort-history-length-alpha files)) + ;; But then move directories first + (nconc (seq-filter (lambda (x) (string-suffix-p "/" x)) files) + (seq-remove (lambda (x) (string-suffix-p "/" x)) files))) + (defun toggle-sort-directories-first () + (interactive) + (if (eq vertico-sort-function 'sort-directories-first) + (set (make-local-variable 'vertico-sort-function) 'vertico-sort-history-length-alpha) + (set (make-local-variable 'vertico-sort-function) 'sort-directories-first)) + (setq vertico--input t) + (vertico--update)) :bind (("C-M-<" . up-from-outside) ("C-M->" . down-from-outside) ("C-M-+" . preview-from-outside) ("M-X" . to-and-fro-minibuffer) - (:map vertico-map ("M-RET" . minibuffer-force-complete-and-exit)))) + (:map vertico-map + ("M-RET" . minibuffer-force-complete-and-exit) + ("M-D" . toggle-sort-directories-first)))) (use-extension vertico vertico-multiform :config |