pycomplete.el removes other useful ac-sources

Bug #1071441 reported by Vinod on 2012-10-25
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Urs Fleisch

Bug Description

Autocompletion in a python buffer only uses the ac-source-pycomplete source. I would prefer that it use that source, in addition to the other default sources. The problem is in line 411 of pycomplete.el, in the function py-complete-initialize.

It reads: (setq ac-sources '(ac-source-pycomplete))
when it should read: (add-to-list 'ac-sources 'ac-source-pycomplete)

Related branches

Vinod (vinod-kurup) wrote :
Urs Fleisch (ufleisch) wrote :

The code completion provided by ac-source-pycomplete tries to be intelligent. For example, when completing a variable, it will only complete local variables defined in the def, parameters of the def and global variables defined in the module. The completions provided by default (ac-source-abbrev, ac-source-dictionary, ac-source-words-in-same-mode-buffers) are not very intelligent, they may have been useful when no other intelligent code completion was available, but why would you want to add such completions? Code completion is not useful if the completions are not valid and just suggesting any word found in any other Python buffer makes completion useless. If you think that some real code completions are missing in ac-source-pycomplete, please report it and we can try to fix that.

If you really want to use other completion sources together with ac-source-pycomplete, just add this to your Emacs initialization file:

(add-hook 'python-mode-hook '(lambda () (setq ac-sources '(ac-source-pycomplete ac-source-abbrev ac-source-dictionary ac-source-words-in-same-mode-buffers))))

Vinod (vinod-kurup) wrote :

Just a couple examples that are useful to me:

I have my email address in my .dict file, so it always autocompletes. I often have reason to type that in comments in my python file. It's not a huge need, but it works in every other programming language that I use in Emacs, so it's nice to have it consistent in Python as well.

I use ac-source-words-in-same-mode-buffers a lot in Django. At the top of a file, I will import the models and forms from other files. I will then use those in the views file. As an example, I have:

from forms import MicropostForm

def new(request):
    form = MicropostForm(request.POST)

In this example, MicropostForm doesn't autocomplete if you are only using ac-source-pycomplete.

Bottom line is that I'd like autocompletion to work in Python buffers as it does in other language buffers (Lisp, etc), though I understand if you don't want to change it. I have already added the python-mode-hook to my own init.el (though it's important to add it before calling py-complete-initialize)

Changed in python-mode:
assignee: nobody → Urs Fleisch (ufleisch)
importance: Undecided → Medium
milestone: none → 6.1.1
Changed in python-mode:
status: New → In Progress
Andreas Roehler (a-roehler) wrote :

please re-open if not done for you

Changed in python-mode:
status: In Progress → Fix Committed
Changed in python-mode:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers