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?

Thank you.

(setq xyz-keywords

(defun xyz-completion-at-point ()
  "This is the function to be used for the hook `completion-at-point-functions'."
  (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))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.