I'm trying to do more or less the same thing as
M-x eval that can autocomplete with tab each word. So here is the code I came up with, using partly this site. However, I don't know why but it works in major mode but not in minibuffer... Any idea why?
(setq xyz-keywords '("touch" "touch_start" "touch_end" "for" "foreach" "forall" )) (defun xyz-completion-at-point () "This is the function to be used for the hook `completion-at-point-functions'." (interactive) (let* ( (bds (bounds-of-thing-at-point 'symbol)) (start (car bds)) (end (cdr bds))) (list start end xyz-keywords . nil ))) (define-derived-mode xyz-mode c-mode "xyz" "Major mode for editing xyz lang code …" (add-hook 'completion-at-point-functions 'xyz-completion-at-point nil 'local)) ;; Works in mode (setq my-mode-map (copy-keymap minibuffer-local-map)) (define-key my-mode-map (kbd "TAB") 'completion-at-point) (let ( (minibuffer-setup-hook (copy-sequence minibuffer-setup-hook)) (completion-at-point-functions '(xyz-completion-at-point))) (read-from-minibuffer "Prompt: " nil my-mode-map))
-- EDIT --
I found this solution, but I've no idea if using this is a good idea:
(let ( (completion-at-point-functions '(xyz-completion-at-point)) (minibuffer-setup-hook (lambda () (add-hook 'completion-at-point-functions 'xyz-completion-at-point nil 'local)))) (read-from-minibuffer "Prompt: " nil my-mode-map))