Auto completion with popup menu.

Downloads and full documentation are found at the following page:





Lisp:auto-complete-extension.el is some enhancement by AndyStewart.

Clang source for Auto Complete

Another Clang source for auto Complete

Another clang autocompletion source

Clang based package for C & C++ completion, on-the-fly syntax checking and more

Readline completion for shell-mode

Auto Complete on nXML-mode

Auto Complete for Perl

Auto Complete for Typescript

Auto Complete for VBA

Auto Complete for org-mode

ac-tex-ref.el – for LaTeX \ref and \cite names

Other extensions are found in AutoCompleteSources.

Development Version Notes

If you are using the current development version of AutoComplete (0.20 at the time of this edit) be aware that ac-source-semantic is now included in the package. Furthermore, if you are using the semantic source, make sure that you have required semantic-ia in your init file. If you do not then it falls back to a method of gathering the tags that appears to not check the semantic cache slowing the whole thing up rather tremendously (especially with omnicompletion).

[I’m pretty sure this is horribly outdated! (current version 1.4)] Speaking of omnicompletion, the way it functions was changed recently. Since it is not documented yet here is an example of how it works:

  (add-hook 'c-mode-common-hook '(lambda ()

          ;; ac-omni-completion-sources is made buffer local so
          ;; you need to add it to a mode hook to activate on 
          ;; whatever buffer you want to use it with.  This
          ;; example uses C mode (as you probably surmised).

          ;; auto-complete.el expects ac-omni-completion-sources to be
          ;; a list of cons cells where each cell's car is a regex
          ;; that describes the syntactical bits you want AutoComplete
          ;; to be aware of. The cdr of each cell is the source that will
          ;; supply the completion data.  The following tells autocomplete
          ;; to begin completion when you type in a . or a ->

          (add-to-list 'ac-omni-completion-sources
                       (cons "\\." '(ac-source-semantic)))
          (add-to-list 'ac-omni-completion-sources
                       (cons "->" '(ac-source-semantic)))

          ;; ac-sources was also made buffer local in new versions of
          ;; autocomplete.  In my case, I want AutoComplete to use 
          ;; semantic and yasnippet (order matters, if reversed snippets
          ;; will appear before semantic tag completions).

          (setq ac-sources '(ac-source-semantic ac-source-yasnippet))

Not terribly difficult but it took me a bit to puzzle out what needed to be done so I thought I would share my results. AndyStewart has included the omnicompletion bits into his init file.


External links

auto-complete bug tracker on GitHub

Integrating Rope and Yasnippet with Auto Complete.

Integrating for Haskell (experimentally, for the Haskell compiler GHC 6.10.1)

Use company backend for Auto-Complete

Questions and Feedback

I’d like ‘return’ to trigger the completion. I’ve been trying this: (ac-set-trigger-key “RET”)

However, this stops ‘return’ from creating newlines.

Non lisp-hacker here. How can I add my own completions, and make auto-complete-mode start automatically for any opened file? Thanks.

For the second part of the question here is what i currently use to bypass ac-modes list:

;; dirty fix for having AC everywhere
(define-globalized-minor-mode real-global-auto-complete-mode
  auto-complete-mode (lambda ()
                       (if (not (minibufferp (current-buffer)))
                         (auto-complete-mode 1))
(real-global-auto-complete-mode t)

How does this compare with CompletionUI and CompanyMode? --TobyCubitt

CompletionUI use tooltip as completion UI, AutoComplete and CompanyMode implement by Overlay.
Tooltip just can use in X, and overlay can use both X and console.
Tooltip is slower than overlay when finger is very fast. 😊
But overlay have align render bug with multi-byte language (such as CJK), and tooltip haven’t this problem.
About different between AutoComplete and CompanyMode, in fact they’re very similar, but CompanyMode have more bug. – AndyStewart
CompanyMode is more feature-rich, actually. For example, as long as the source supports that, it can show a documentation or a definition buffer without quitting the completion interface.
Try hitting ‘f1’ or ‘C-w’ when completing something in an EmacsLisp buffer.
And it has a separate notion of metadata, which it shows in the echo area, that can be used to quickly show the function’s argument list, for example.
AutoComplete can display a candidate’s documentation, but it uses third-party libraries for that. They can make it look cooler, but they impose certain limitations, like you can’t add highlighting to the documentation text. – DmitryGutov

Thanks for the explanation! CompletionUI includes many other user-interfaces besides the tooltip, implements an auto-completion-mode, and includes many other features besides. My aim was to make a swiss-army knife of completion user-interface code, so no one else would have to go through the same tedium! Would you be interested in adding your overlay display code to CompletionUI? --TobyCubitt

AutoComplete stops working as soon as I enable Flymake. I’m using the development version. --TiagoCamargo

After loading auto-complete,



If I’m editing OrgMode files, I can start AutoComplete (using \M-/ and not auto start), but if I don’t want to make any of the completions, ESC-ESC-ESC doesn’t kill the menu. I don’t see this problem in other emacs files. Any debugging hints?

What about completion with candidates from other buffers? I’ve tried to add ac-source-words-in-all-buffer to ac-sources, but that didn’t give any effect 😟

hi, my enhancement of auto-complete, AutoCompletePlus, 😊 – ahei

In c++-mode, ac-source-filename can not work, because

(defun ac-sources-prefix-default ()
  "Default implementation for `ac-sources-prefix-function'."
  (require 'thingatpt)
  (car-safe (bounds-of-thing-at-point 'symbol)))

and thing-at-point is ahe when point after /home/ahe. I think auto-complete should have multiple ac-prefix, and then complete those all. – ahei

Can anyone explain how the ac-omni-completion-sources replacement works? I am not understanding how to use this ac-prefix stuff. I want to start completion on ‘.’ and ‘->’ for C programming, so foo→ would pop up completions for the struct Foo. This was working in 0.20 and I’m just not seeing how to set this up again. LesHarris

fix for yasnippet >=0.7.0

(defun ac-yasnippet-candidate-1 (table)
  (let ((hashtab (yas/snippet-table-hash table))
        (parent (if (fboundp 'yas/snippet-table-parent)
                    (car (yas/snippet-table-parent table))))
    (maphash (lambda (key value)
               (push key candidates))
    (setq candidates (all-completions ac-prefix (nreverse candidates)))
    (if parent
        (setq candidates
              (append candidates (ac-yasnippet-candidate-1 parent))))

I’m getting the following error message:

Symbol’s function definition is void: window-full-width-p

I googled this message, and found the following (at [1]):

  • Lisp Changes in Emacs 22.2. . . .
    • New function ‘window-full-width-p’ returns t if a window is as wide as its frame.

The manual states that GNU Emacs 22 or later is required, and the version I am using is GNU Emacs 22.1.1. Is my old version of emacs the source of the error, and if it is, should the manual be corrected to list a newer required version of emacs (at least 22.2)?

I replaced “(window-full-width-p window)” with “t”, then popup.el seems to work fine. – Anonymous Coward

The gray-shaded inline expansion gets in the way when deleting characters in the midst of a line, as it overlays following existing text. This is a bit inconvenient. Is it possible to suppress completion while actively deleting?

Is it possible to use auto-complete to translate words with a lookup at

Yes, of course. auto-complete is a frame work for completion. But you have to give it the sources to complete from and take care of the output from completion. (You could of course use Emacs default completion frame work too. Or Icicles etc.)

infinite loop if type "border-width:" in css-mode
maybe you need to modify auto-complete-config.el file and byte-compile.
--- auto-complete-config.el.orig	2010-05-29 23:51:11.000000000 +0900
+++ auto-complete-config.el	2010-08-25 20:49:15.000000000 +0900
@@ -344,10 +344,11 @@
 (defconst ac-css-value-classes
   '((absolute-size "xx-small" "x-small" "small" "medium" "large" "x-large"
     (border-style "none" "hidden" "dotted" "dashed" "solid" "double" "groove"
                   "ridge" "inset" "outset")
+    (border-width "thin" "medium" "thick" "inherit")
     (color "aqua" "black" "blue" "fuchsia" "gray" "green" "lime" "maroon" "navy"
            "olive" "orange" "purple" "red" "silver" "teal" "white" "yellow"
     (counter "counter")
     (family-name "Courier" "Helvetica" "Times")
@@ -475,6 +476,6 @@
   (add-hook 'css-mode-hook 'ac-css-mode-setup)
   (add-hook 'auto-complete-mode-hook 'ac-common-setup)
   (global-auto-complete-mode t))
 (provide 'auto-complete-config)
-;;; auto-complete-config.el ends here
+;;; auto-complete-config.el ends here

You can monkey patch using this somewhere else if you don’t want to change autocomplete.el

;; CSS autocomplete inifinite loop hacks
(add-to-list 'ac-css-value-classes
	     '(border-width "thin" "medium" "thick" "inherit"))

I changed the yasnippet source to support the lastest SVN version of Yasnippet. In addition, I added a documentation function that gives the name of the expansion and the actual template.

(defface ac-yasnippet-candidate-face
  '((t (:background "sandybrown" :foreground "black")))
  "Face for yasnippet candidate."
  :group 'auto-complete)

(defface ac-yasnippet-selection-face
  '((t (:background "coral3" :foreground "white")))
  "Face for the yasnippet selected candidate."
  :group 'auto-complete)

(defun ac-yasnippet-table-hash (table)
   ((fboundp 'yas/snippet-table-hash)
    (yas/snippet-table-hash table))
   ((fboundp 'yas/table-hash)
    (yas/table-hash table))))

(defun ac-yasnippet-table-parent (table)
   ((fboundp 'yas/snippet-table-parent)
    (yas/snippet-table-parent table))
   ((fboundp 'yas/table-parent)
    (car (yas/table-parent table)))
   ((fboundp 'yas/table-parents)
    (car (yas/table-parents table)))

(defun ac-yasnippet-candidate-1 (table)
    (let ((hashtab (ac-yasnippet-table-hash table))
          (parent (ac-yasnippet-table-parent table))
          (ac-prefix (ac-yasnippet-prefix))
      (maphash (lambda (key value)
                 (push key candidates))
      (when ac-prefix
        (setq candidates (all-completions ac-prefix (nreverse candidates)))
      (when parent
        (setq candidates
              (append candidates (ac-yasnippet-candidate-1 parent)))

(defun ac-yasnippet-candidates ()
    (if (fboundp 'yas/get-snippet-tables)
        ;; >0.6.0
        (apply 'append (mapcar 'ac-yasnippet-candidate-1 (yas/get-snippet-tables major-mode)))
      (let ((table
             (if (fboundp 'yas/snippet-table)
                 ;; <0.6.0
                 (yas/snippet-table major-mode)
               ;; 0.6.0
        (if table
            (ac-yasnippet-candidate-1 table))))))

(defun ac-yasnippet-document (complete)
  "* Completes Documentation for Yasnippet"
  (let (templates only-one (ret ""))
    (setq templates (mapcar #'cdr 
                            (mapcan #'(lambda (table)
                                        (yas/fetch table complete))
    (mapc #'(lambda (template)
              (setq ret (format "%s%s\n%s\n" ret (yas/template-name template) (yas/template-content template))))
    (when (string-match "\n\\'" ret)
      (setq ret (replace-match "" nil nil ret)))

(defun ac-yasnippet-prefix ()
  "* Gets Yasnippet Prefix."
  (if (looking-back "[^ ]*")
      (match-string 0)

(ac-define-source yasnippet
  '((depends yasnippet)
    (candidates . ac-yasnippet-candidates)
    (action . yas/expand)
    (candidate-face . ac-yasnippet-candidate-face)
    (selection-face . ac-yasnippet-selection-face)
    (document . ac-yasnippet-document)
    (requires . 3)
    (prefix . "\\(\\<[^ ]*\\)")
    (symbol . "a")))


The following made yasnippet 0.7.0 and autocomplete 1.4 (both retrieved using el-get) work nicely in Emacs 24.0.92.

;; Put this in your .emacs:
;; 		(require 'my-yas-funs)
;; To use in a given major-mode, e.g., js-mode, use:
;;		(add-hook 'js-mode-hook (lambda () (yas/minor-mode-on)))
;;		(add-hook 'js-mode-hook (lambda () (add-to-list 'ac-sources `ac-new-yas-source)))
;; Works best with the following:
;;		(define-key ac-complete-mode-map "\t" 'ac-complete)
;;		(define-key ac-complete-mode-map "\r" nil)
;;		(setq yas/trigger-key "TAB")

(require 'yasnippet)

(defvar yas-candidates nil)

(defun init-yas-candidates ()
	(let ((table (yas/get-snippet-tables major-mode)))
		(if table
		  (let (candidates (list))
				(mapcar (lambda (mode)          
				  (maphash (lambda (key value)    
					(push key candidates))          
				  (yas/table-hash mode))) 
			(setq yas-candidates candidates)))))
(defvar ac-new-yas-source
	'(	(init . init-yas-candidates)
		(candidates . yas-candidates)
		(action . yas/expand)
		(symbol . "a")))

(provide 'my-yas-funs)

--David Dreisigmeyer

In windows the pos-tip doesn’t work. To get it to work change

(eq window-system 'x)


(memq window-system '(x w32))

I emailed maintainer, but I haven’t heard anything.


BUG: Do not display completion when there is only one completion and the word is already complete! That’s just plain nonsensical!

Could you please write more documentation on how to use/reuse popup menus from popup.el. It would be nice to have an easy to use popup menus (implemented as overlays) in different contexts, for example in CompletionUI. --SewerynKokot

In css-mode, as soon as I hit ‘;’ to complete a declaration, the auto-complete menu appears and auto-selects a completion. Naturally, I’ll hit RET to begin a new line, but instead the first-selected auto-completion is inserted! I have to use C-j to get new lines. How can I prevent this without disabling auto-complete in every other mode? --IanL

Hey, if you want to stop having an autocomplete prompt when you hit RET, edit your auto-complete-config.el file and add the semicolon to the prefix regex. You should have something like that:

(defun ac-css-prefix ()
  (when (save-excursion (re-search-backward "\\_<\\(.+?\\)\\_>\\s *:.*\\=\\;" nil t))
    (setq ac-css-property (match-string 1))
    (or (ac-prefix-symbol) (point))))

Happy hacking! – Etenil

I got tired of removing a character from a function name in order to see the docstring for it popup. The code below will display the docstring for a function in a popup when the point is on the function name or over a space in the function call list. Scott Jaderholm

(require 'pos-tip)
(defun jsj-ac-show-help ()
  "show docs for symbol at point or at beginning of list if not on a symbol"
  (let ((s (save-excursion
             (or (symbol-at-point)
                 (progn (backward-up-list)
    (pos-tip-show (if (equal major-mode 'emacs-lisp-mode)
                      (ac-symbol-documentation s)
                    (ac-slime-documentation (symbol-name s)))
                  ;; 'alt-tooltip

(define-key lisp-mode-shared-map (kbd "C-c C-h") 'jsj-ac-show-help)

Hi, guys! I wrote an auto-complete-source to use Scite’s API files, called AutoCompleteSciteAPI. (For those don’t familiar with Scite, this page has some description on its API completion. Scite itself lacks such detail info)

Blog article for it: [2] (Sorry that it was written in Chinese. I’ll wrote some English description some time later. Or you can read the comment in source 😊)

Code: [3]

For me, it works fine on GNU Emacs 23.2/24.0.50 and auto-complete 1.2/1.3. I’m a emacs newbie (<1 year). If someone would point out any error in my elisp code, I’d be very happy. --BaManzi

Hi. I use autocomplete + eclim. I wrote an autocomplete source which uses eclim to retrieve completion candidates and then builds a yasnippet to expand on candidate selection. Hope someone finds it useful.

(defvar ac-eclim-yas-mark 'nil)

(defun ac-eclim-yas-candidates ()
  (let (lista)
      (when eclim-auto-save (save-buffer))
      (loop for c in (eclim/java-complete)
	    (if (not (equal (nth 0 c) "f"))
		(push (nth 1 c) lista)
	      (let ((texto (nth 2 c))
		(push (concat 
		       (replace-regexp-in-string "^\\([^(]*(\\).*" "\\1" texto)
		       (replace-regexp-in-string "[^ <]+\\(?:<[^>]+>\\)? \\([^ ,]+\\)\\(,?\\)" "${\\1}\\2"
						 (replace-regexp-in-string "^[^(]*(\\([^)]*\\)).*$" "\\1"  texto))

(defun yas/expand-eclim-snippet ()
  (let ((snip (buffer-substring-no-properties ac-eclim-yas-mark (point))))
    (delete-region ac-eclim-yas-mark (point))
    (yas/expand-snippet snip)))

(defun eclim-yas-init ()
  (setq ac-eclim-yas-mark (point)))

(ac-define-source eclim-yas
  '((candidates . ac-eclim-yas-candidates)
    (init . eclim-yas-init)
    (requires . 0)
    (prefix . c-dot)
    (action . yas/expand-eclim-snippet)
    (symbol . "f")))

--Lucas Pandolfo

Is it possible to add some additional information in the popup menus that doesn’t get inserted when the text is completed? I would like to have the additional type information semantic provides for C/C++ code in the popup menu、like

| l : long[] |
| x : int    |. 


I couldn’t find the place to post a bug report, so I’ll leave it here. As of Emacs and auto-complete 1.4 the variable ‘ac-auto-start’ is mysteriously set to ‘nil’ regardless of any configuration value. It is set right after calling ‘auto-complete-mode’ and cannot be reset afterwards. Most likely some timer resets it to nil. However, it is not ‘ac-clear-variables-every-minute’, that happens much later.


…Since I installed auto-complete I just can’t exit emacs as it freezes with ‘Wrote ~/.emacs.d/ac-comphist.d’. Any ideas? I have this plugins installed: evil, evil-nerd-commenter, undo-tree, smooth-scrolling, color-theme

Try… (setq ac-use-comphist nil). This option makes emacs to exit slowly… – Kiwon

AutoComplete and PredictiveMode. I asked the author of Predictive mode. I was informed that although Predictive mode has a module called ‘auto-complete-mode’ it is not a reference to this AutoComplete. They are separate from one another.



How does it work ? What does it get assigned to any keys ? Which function should I assign to get auto-completion ?

If you have a black background use auto-complete, the cursor turns black. This obscures the text and can be fixed by adding (set-cursor-color “white”) to your .emacs file after loading the auto-complete package.