I'm trying to write a function for complete in minibuffer with history.
(Terminal equivalent of "\e[5~": history-search-backward
in ~/.inputrc
)
With the below function I can get the last command that start with the prefix in the minibuffer. I want to validate this candidate or search the next candidate.
(defun history-search-forward ()
(interactive)
(setq prefix (minibuffer-contents))
(loop for elt in extended-command-history
do
;; history starts with word-at-point
(and (string-match (rx-to-string `(: bos ,prefix) t)
elt)
(progn
(delete-region (point) (line-beginning-position))
(insert elt)
;; here a want to launch the command if <Enter>
;; or continue looping if <prior>
(return)))))
(define-key minibuffer-local-completion-map (kbd "<prior>") 'history-search-forward)
How can I wait for user input at that point in the loop?
(ido-completing-read "Command: " extended-command-history)
will likely do exactly what you want. Also the minibuffer already has completion history. Just useM-n
andM-p
to scroll through the history. – Jordon Biondo Jul 8 '15 at 14:00ido-mode
, and also install and activateido-ubiquitous
,ido-flx
, andsmex
. I also recommendido-vertical-mode
. – Jordon Biondo Jul 8 '15 at 14:04