Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs auto-complete not displaying results

I am running the most recent version of auto-complete in elpa with the new stable release of Emacs (24.3) in Linux. I have the following setup on my Emacs init file.

(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
(require 'auto-complete-config)
(setq-default ac-sources
          '(
        ac-source-filename
        ac-source-abbrev 
        ac-source-dictionary
        ac-source-words-in-same-mode-buffers))
(ac-config-default)

If I start typing: /home/james/.em in a buffer (e.g. a Python buffer) I would expect auto-complete to suggest:

.emacs
.emacs.d

but it does not show anything. The same thing happens with other files.

Sometimes I do see suggestions and/or the pop-up menu shows up, but other times it doesn't.

Any thoughts why?

like image 659
Amelio Vazquez-Reina Avatar asked Oct 04 '22 17:10

Amelio Vazquez-Reina


1 Answers

ac-config-default sets a list of sources that does not include ac-source-filename. By calling this function after setq-default ac-sources you are resetting them back to the defaults. The auto-complete manual suggests setting mode-hooks to set up the desired sources for specific modes. The example from the manual is

(defun my-ac-emacs-lisp-mode ()
  (setq ac-sources '(ac-source-symbols ac-source-words-in-same-mode-buffers)))

(add-hook 'emacs-lisp-mode-hook 'my-ac-emacs-lisp-mode)

Adapting this to python-mode should be easy enough. Alternatively you can globally override the settings set by ac-config-default by calling it first, i.e.

(require 'auto-complete-config)
(ac-config-default)
(setq-default ac-sources
          '(
        ac-source-filename
        ac-source-abbrev 
        ac-source-dictionary
        ac-source-words-in-same-mode-buffers))

That way setq-default ac-sources will override the sources set by ac-config-default rather than the other way around.

like image 194
Ista Avatar answered Oct 10 '22 04:10

Ista