The following code (mostly coming from here) creates a company-mode back-end and binds
TAB to it:
(require 'company) (defconst sample-completions '("procedural" "functional" "high-level" "low-level" "statically-scoped" "dynamically-scoped")) (defun company-sample-backend (command &optional arg &rest ignored) (interactive (list 'interactive)) (let ((my-completions (copy-sequence sample-completions))) (case command (interactive (company-begin-backend 'company-sample-backend)) (prefix (and (eq major-mode 'fundamental-mode) (company-grab-symbol))) (candidates (remove-if-not (lambda (c) (string-prefix-p arg c)) my-completions))))) (add-to-list 'company-backends 'company-sample-backend) (define-key company-mode-map (kbd "TAB") 'company-sample-backend)
I have checked that the above works. That is, when I put a regular buffer (such as
company mode, I can invoke completion by pressing
TAB and the
sample-completions collection is used for completion.
Now I am trying to read a string from mini-buffer with auto-completion. To make sure that the mini-buffer is in
company mode, I evaluate:
(defun my-minibuffer-mode () (company-mode 1)) (add-hook 'minibuffer-setup-hook 'my-minibuffer-mode)
Now I try:
(read-from-minibuffer "Prompt: ")
However, what I get is completion from the English dictionary and not from my
sample-completions collection. How do I fix this?