auto-complete automatically adds a number of sources to ac-sources:

(ac-source-features ac-source-functions ac-source-variables ac-source-symbols)

And I set up auto-complete default ac-sources like this:

(ac-source-yasnippet ac-source-abbrev ac-source-filename ac-source-files-in-current-dir 
 ac-source-capf ac-source-gtags ac-source-words-in-same-mode-buffers)

But I found that some sources listed in ac-sources complete the same thing. For example, I get the following completions for (setq):

  • ac-source-functions shows: setq f
  • ac-source-symbols shows: setq s
  • ac-source-capf shows: setq s
  • ac-source-words-in-same-mode-buffers shows: setq

I want to disable the following sources only in emacs-lisp-mode: ac-source-symbols, ac-source-capf.

How can I do this?

(If you know of any other way to solve my problem, please leave a comment. Thanks.)

2 Answers 2


Here is a function that deletes ac-source-symbols and ac-source-capf from ac-sources:

(defun ac-remove-sources ()
  (setq ac-sources (delete 'ac-source-capf ac-sources))
  (setq ac-sources (delete 'ac-source-symbols ac-sources)))

You can tell Emacs to run this function for emacs-lisp-mode buffers by adding it to emacs-lisp-mode-hook like so:

(add-hook 'emacs-lisp-mode-hook 'ac-remove-sources t)

Note that in order to make sure that it overrides the default behavior, you'll need to put this code after the code that loads the default customizations for auto-complete in your init-file.

  • right, I need to put this behind default initialize, I think that's why my config not working. Commented Jan 27, 2015 at 8:26

I found a similar solution:

(defun ac-source-remove (source-removed-list)
  "Remove some ac-source from ac-sources.

(add-hook 'emacs-lisp-mode-hook
          (lambda ()
            (ac-source-remove '(ac-source-capf ac-source-symbols))))"
  ;; Use `remq' instead of `delq' which will remove element in global `ac-sources' too.
  (mapc (lambda (x) (setq-local ac-sources (remq x ac-sources)))

(add-hook 'emacs-lisp-mode-hook
          (lambda () (ac-source-remove '(ac-source-capf ac-source-symbols))))
  • You should avoid using anonymous functions (lambda) when adding functionality to mode hooks. It makes values of hook variables harder to read, and you can't use remove-hook to remove functionality later on. Instead, you should define a function that implements the desired behavior and add that to the mode hook.
    – itsjeyd
    Commented Jan 27, 2015 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.