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