emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

History completion


From: Juri Linkov
Subject: History completion
Date: Wed, 08 Dec 2021 20:54:40 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

Wouldn't it be nice to allow completion on previous input
in the minibuffer.

There are two unbound commands ‘previous-complete-history-element’ and
‘next-complete-history-element’ but their completion is limited
only to the beginnings of history items.

So tried to set the minibuffer completion table to the history list:

#+begin_src emacs-lisp
(defun minibuffer-setup-history-completions ()
  (unless (or minibuffer-completion-table minibuffer-completion-predicate)
    (setq-local minibuffer-completion-table (symbol-value 
minibuffer-history-variable))))
(add-hook 'minibuffer-setup-hook 'minibuffer-setup-history-completions)
#+end_src

It works nicely with ‘icomplete-mode’ and ‘fido-vertical-mode’
by automatically displaying completions from the history
depending on input in the minibuffer.  But this also has drawbacks:
while typing a completely new command that doesn't exist in the history,
it permanently says at the end of the minibuffer: [No matches]

So instead of this, tried to show history completions only after
typing a special key.  TAB can't be reused because in some minibuffers
such as ‘M-!’ (shell-command), TAB completes the command/file names.

There is ‘C-tab’ bound to file-cache-minibuffer-complete.
When file-cache is not used, then ‘C-tab’ could be rebound
to a command that completes on the minibuffer history:

#+begin_src emacs-lisp
;; Adapted from ‘minibuffer-complete’:
(defun minibuffer-complete-history ()
  (interactive)
  (completion-in-region (minibuffer--completion-prompt-end) (point-max)
                        (symbol-value minibuffer-history-variable)
                        nil))
(define-key minibuffer-local-map [C-tab] 'minibuffer-complete-history)
#+end_src



reply via email to

[Prev in Thread] Current Thread [Next in Thread]