I have written code that returns lists of symbols representing modules and exported functions of a programming language. How do I integrate it with some autocompletion in Emacs?
I looked at company and completion-at-point-functions. I managed to run simple example successfully, and then I realised that all these examples use a predefined list of completion candidates.
Last code sample on the following page is a good example http://sixty-north.com/blog/writing-the-simplest-emacs-company-mode-backend
I do not know what the completion candidates will be at this point. How do I create a dynamic list of candidates generated when I run M-x company-sample-backend?
Actually, the example at sixty-north.com can be easily modified to use dynamic completion. The problem lies elsewhere.
(defconst sample-completions '("alan" "john" "ada" "don"))
with a function returning strings with random content and calling that function at the bottom of the backend function works.
In the end I have settled on following code:
(require 'company) (defun company-lfe-backend (command &optional arg &rest ignored) (interactive (list 'interactive)) (case command (interactive (company-begin-backend 'company-lfe-backend)) ;; unfinished code related to major modes (prefix (and (or t (eq major-mode 'fundamental-mode)) (company-grab-symbol))) (candidates (-map 'symbol-name (-flatten ;; following function returns the structure containing possible ;; auto completions (lfedoc-sexp-autocompletion-at-point)))))) (add-to-list 'company-backends 'company-lfe-backend)