Fix and improve vertico-mode' completion with fido-mode'

This commit is contained in:
Gerard Vermeulen 2024-06-15 11:40:42 +02:00
parent 5dafaa31e2
commit 24929eab49

View File

@ -228,6 +228,7 @@ of [[info:emacs#Saving Customizations][saving customizations (info)]].
recentf-max-saved-items 100 recentf-max-saved-items 100
recentf-mode t recentf-mode t
save-place-mode t save-place-mode t
savehist-additional-variables '(kill-ring) ; BUG!
savehist-mode t savehist-mode t
scroll-bar-mode nil scroll-bar-mode nil
tab-always-indent 'complete tab-always-indent 'complete
@ -888,7 +889,6 @@ minibuffer completion]].
;; https://www.masteringemacs.org/article/understanding-minibuffer-completion ;; https://www.masteringemacs.org/article/understanding-minibuffer-completion
(setopt (setopt
completion-category-overrides '((file (styles basic substring))) completion-category-overrides '((file (styles basic substring)))
completion-ignore-case nil
completion-styles '(basic flex partial-completion substring))) completion-styles '(basic flex partial-completion substring)))
#+end_src #+end_src
@ -1267,32 +1267,28 @@ completion in any buffer.
:CUSTOM_ID: sec:vertico-configuration :CUSTOM_ID: sec:vertico-configuration
:END: :END:
Listing [[lst:enable-vertico-mode]] configures and enables =savehist-mode= and Listing [[lst:setup-vertico-mode]] sets up =fido-mode= and =vertico-mode=. Listing
enables =vertico-mode=. The src_emacs-lisp{(describe-function 'savehist-mode)} [[lst:prune-file-name-history]] allows to prune non-existing files from the file
name history. NOTE: The src_emacs-lisp{(describe-function 'savehist-mode)}
documentation explains why it is best to turn on =savehist-mode= in the documentation explains why it is best to turn on =savehist-mode= in the
=user-init-file=. Listing [[lst:prune-file-name-history]] allows to prune =user-init-file=. BUG: Adding ~kill-ring~ to ~savehist-additional-variables~
non-existing files from the file name history. BUG: Adding ~eww-history~ or does not save ~kill-ring~ from an Emacs session to the next session, contrary to
~register-alist~ to ~savehist-additional-variables~ fails to save the relevant the src_emacs-lisp{(describe-variable 'savehist-additional-variables)}
histories. documentation.
#+caption[Enable =savehist-mode= and =vertico-mode=]: #+caption[Enable =fido-mode= and =vertico-mode=]:
#+caption: Enable =savehist-mode= and =vertico-mode=. #+caption: Enable =fido-mode= and =vertico-mode=.
#+name: lst:enable-vertico-mode #+name: lst:setup-vertico-mode
#+begin_src emacs-lisp -n :results silent #+begin_src emacs-lisp -n :results silent
(with-eval-after-load 'savehist (when (ensure-package-installation 'vertico)
(setopt savehist-additional-variables ;; ChatGPT: Builtin `fido-mode' fixes `find-file' completion here.
'(command-history kill-ring regexp-search-ring search-ring))) (fido-mode +1)
(when (and (ensure-package-installation 'vertico)
(fboundp 'vertico-directory-delete-char)
(fboundp 'vertico-directory-delete-word)
(fboundp 'vertico-mode)
(fboundp 'vertico-directory-enter))
(vertico-mode +1) (vertico-mode +1)
(with-eval-after-load 'vertico ;; GOOD: Builtin `fido-mode' improves the feel of the completion.
(defvar vertico-map) ;; UGLY: Builtin `fido-mode' adds a visually superfluous extra line.
(keymap-set vertico-map "DEL" #'vertico-directory-delete-char) (keymap-set vertico-map "DEL" #'vertico-directory-delete-char)
(keymap-set vertico-map "M-DEL" #'vertico-directory-delete-word) (keymap-set vertico-map "M-DEL" #'vertico-directory-delete-word)
(keymap-set vertico-map "RET" #'vertico-directory-enter))) (keymap-set vertico-map "RET" #'vertico-directory-enter))
#+end_src #+end_src
#+caption[Prune non-existing files from =file-name-history=]: #+caption[Prune non-existing files from =file-name-history=]: