It's not exactly what I wanted before, but it's not too far away. The idea is to use recursive minibuffer and to run ido-completing-read
with the good parameters each time the user type TAB
. So you won't use exactly the keystrokes above, but it won't be too far since you will hit "tab" when you want to see what IDO can give you, and then you hit "Enter" when you are happy with the IDO proposition. If someone has another solution, please let me know! Note that by default I chosed to autocomplete if only one solution is available and if this solution does not need to "fuzzy-match".
Demo:
Code:
(setq xyz-keywords
'( "touch"
"touch_start"
"touch_end"
"for"
"foreach"
"forall"
"chocolate"
"banana"
))
(defun in-buffer-ido-replace (choices &optional even-if-one-solution)
"Choices must be a list of string that can be chosen.
Set 'even-if-one-solution' to 't' if you want to run ido even when only one solution is available."
(interactive)
(let*
((choices_ (cons "" choices))
(enable-recursive-minibuffers t)
(bds (or (bounds-of-thing-at-point 'symbol) (cons (point) (point))))
(start (car bds))
(end (point))
(beginword (buffer-substring start end))
(textbefore (buffer-substring 1 start))
(classic-completions (all-completions beginword choices_)))
;; Complete directly if one solution
(if (and (not even-if-one-solution) (eq (length classic-completions) 1))
(insert (car classic-completions))
(insert (ido-completing-read
(concat textbefore "")
choices_ nil nil beginword)))
(delete-region start end)
))
(setq my-mode-map (copy-keymap minibuffer-local-map))
(define-key my-mode-map (kbd "TAB") (lambda () (interactive) (in-buffer-ido-replace xyz-keywords)))
(let ((minibuffer-setup-hook (lambda () (add-hook 'completion-at-point-functions 'xyz-completion-at-point nil 'local))))
(read-from-minibuffer "Prompt: " nil my-mode-map))