How to display autocomplete options in emacs?

I am working on implementing autocomplete in emacs for the haxe programming language.

I already understood how to get the list of autocomplete that I want to submit. The list is in the format:

'((name1 type1 desc1) (name2 type2 desc2) ... 

I want to display a list of users containing text in the format "name1 type1" after the cursor position (for example, in autocomplete mode) and desc for the currently selected item in the minibuffer. The user should be able to choose completion or submit, as in auto-complete mode.

When the user selects something, name1 should be inserted at the cursor position.

What is the best / easiest way to do this? Is there any standard emacs way for this, or should I write something myself?

EDIT: I have functions to get a list of buffer-based autocomplete candidates. Now I'm trying to integrate this into autocomplete mode. Since get-completes is a tough operation, I would like to call it only if the cursor is on. character.

Here is the code I have.

 (defun get-completes-from-haxe (hxml-file file pos) (let* ((completion-buffer (get-buffer-create "*haxe-completions*")) (cmd (concat "cd " (file-name-directory hxml-file) "; haxe " hxml-file " --display " file "@" (number-to-string pos)))) (ignore-errors (shell-command cmd completion-buffer) (let ((clist (xml-parse-region 1 (buffer-size completion-buffer) completion-buffer)) (completes nil)) (dolist (s (cddar clist)) (when (listp s) (let* ((item (cdr s)) (name (cdaar item)) (type (car (cddadr item))) (desc (cdddr item))) (setf completes (cons name completes))))) completes)))) (defun file-find-upwards (buffer file-name) ;; Chase links in the source file and search in the dir where it points. (setq dir-name (or (and (buffer-file-name buffer) (file-name-directory (file-chase-links (buffer-file-name buffer)))) default-directory)) ;; Chase links before visiting the file. This makes it easier to ;; use a single file for several related directories. (setq dir-name (file-chase-links dir-name)) (setq dir-name (expand-file-name dir-name)) ;; Move up in the dir hierarchy till we find a change log file. (let ((file1 (concat dir-name file-name)) parent-dir) (while (and (not (file-exists-p file1)) (progn (setq parent-dir (file-name-directory (directory-file-name (file-name-directory file1)))) ;; Give up if we are already at the root dir. (not (string= (file-name-directory file1) parent-dir)))) ;; Move up to the parent dir and try again. (setq file1 (expand-file-name file-name parent-dir))) ;; If we found the file in a parent dir, use that. Otherwise, ;; return nil (if (or (get-file-buffer file1) (file-exists-p file1)) file1 nil))) (defun get-candidate-list (buffer pos) (get-completes-from-haxe (file-find-upwards buffer "compile.hxml") (buffer-file-name buffer) pos)) 
+7
autocomplete emacs elisp haxe
source share
5 answers

I would suggest an excellent AutoComplete package: http://www.emacswiki.org/emacs/AutoComplete

You can define custom sources for autocomplete, and it looks pretty straightforward.

+7
source share

Why reinvent the wheels? company mode supports multiple languages

+3
source share

Ido-completion-reading from ido.el is another way to do this.

A useful feature of this is that you can use regular expressions to filter candidates, and you can turn this feature on and off on the fly. See Ido.el for more details.

+1
source share

The ido package has a handy completion functionality called "ido-completeting-read". For example, here is a simple setup that allows you to display lists in turn:

 (defun x-ido-completing-read (prompt choices &optional predicate require-match initial-input hist def) (let* ((indent (concat "\n" (make-string (length prompt) ? ))) (ido-decorations `("" "" ,indent ,(concat indent "...") "[" "]" " [No match]" " [Matched]" " [Not readable]" " [Too big]"))) (ido-completing-read prompt choices predicate require-match initial-input hist def))) 
+1
source share

Inside the yasnippet code, accessible from google code, they use the "dropdown-list.el" from Jaeyoun Chung to display possible snippets that could be used at the point. This gives a pop-up menu (in the form of a hint) at the cursor position, which you can select with the arrow keys and enter or you can select by number.

http://www.emacswiki.org/emacs/dropdown-list.el

+1
source share

All Articles