-
Website
http://www.enigmacurry.com/ -
Original page
http://www.enigmacurry.com/2009/01/21/autocompleteel-python-code-completion-in-emacs/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
prasant
1 comment · 1 points
-
Christopher D. Walborn
1 comment · 1 points
-
Tim Lesher
1 comment · 1 points
-
Alex K
1 comment · 1 points
-
EnigmaCurry
11 comments · 1 points
-
-
Popular Threads
-
EnigmaCurry
1 day ago · 3 comments
-
EnigmaCurry
Any ideas? The whole thing feels like a great idea, I`d be glad to make it work in my setting.
I have tab bound to indent or expand, depending Something like this:
<pre lang="lisp">
(defun indent-or-expand (arg)
"Either indent according to mode, or expand the word preceding
point."
(interactive "*P")
(if (and
(or (bobp) (= ?w (char-syntax (char-before))))
(or (eobp) (not (= ?w (char-syntax (char-after))))))
(dabbrev-expand arg)
(indent-according-to-mode)))
(defun my-tab-fix ()
(local-set-key [tab] 'indent-or-expand))
(add-hook 'c-mode-hook 'my-tab-fix)
(add-hook 'sh-mode-hook 'my-tab-fix)
(add-hook 'emacs-lisp-mode-hook 'my-tab-fix)
(add-hook 'python-mode-hook 'my-tab-fix)
</pre>
I lived that way in Emacs for a long time, and in non-python buffers that's how I still live. AutoComplete.el can still use this functionality by adding different sources to the python-mode-hook:
<pre lang="lisp">
(set (make-local-variable 'ac-sources)
(append ac-sources '(ac-source-that-you-want)))
</pre>
Valid, predefined sources include:
1) ac-source-words-in-buffer
2) ac-source-files-in-current-dir
You can even get full dabbrev-expand as you suggested using this contributed source:
http://www.emacswiki.org/cgi-bin/emacs/ac-dabbr...
As far as interfering with the "flow" of coding, I didn't like the way AutoComplete.el by default starts completing as you type. In the code above I have some advice functions that turn off this behavior and only complete when I explicitly press TAB.
There is a problem I just meet,when I press TAB
the minibuffer displayed a message
Symbol's function definition is void rope-completions
ps:I have installed pyemacs 0.24beta,rope0.9.1,ropemacs0.6
rope-completions is one of the very newest functions in ropemode.
Make sure you're installing the development version of rope, ropemacs and ropemode from mercurial (hg) as shown above.
I found some problem on python3.0,it doesn't work.
No, I haven't done much py3k stuff. Rope has a branch specifically for py3k, but I have not used it: http://bitbucket.org/agr/rope_py3k/
@kaiputer, great! I'm glad this was useful to you. :)
Because of this sentence I found your another post here and applied the steps in this post.
It looks I'm getting the same error with Jimmy Wu;
Symbol's function definition is void rope-completionsShould I uninstall everything and redo everything as described in this post?
This post has everything you need. You don't need to go to that other link. It's just to let people know that these changes are also in my git repository, but that's an alternative to just following the directions in this post.
The problem you are seeing with rope-completions is that you don't have the development version of ropemode/ropemacs installed. If you follow the above directions on checking them out with "hg" you should resolve that problem.
I'm in the middle of trying to add support for auto-complete into IPython inside emacs and found this helpful. I was wondering about the defadvice you add to ac-start and ac-cleanup. The docs for auto-complete suggest that binding [tab] to ac-start should be enough for things to work but it doesn't without the extra advice.
Glad you're getting some good use out of it! The reason for the defadvice is pretty technical and it may be actually covering up a bug in autocomplete.el .. I'm not too sure, but it works.
A deeper explanation:
1) By default autocomplete has ac-auto-start turned on. This makes it so that when you're typing along anything that is "completeable" automatically pops up the drop down menu. First of all, I don't like that behaviour, I want it to be explicit, meaning I only want it to complete when I actually press TAB. Secondly, if you were to type something like "string.capitalize" it would start to complete the "string" part, but if you did NOT utilize the completion function but instead just kept on typing up to the "." then autocomplete doesn't complete on the "capitalize" part. In this case you have to backspace over the "." and type the "." again and it starts to complete the "capitalize" part. That "bug" is most likely in my code, not in autocomplete.el, Like I said, I didn't write it with ac-auto-start in mind.
2)This is probably a bug in autocomplete.el. Once you turn off ac-auto-start and you start a completion it brings up the drop down menu, but as you start typing to narrow down the choices, the dropdown box does not update. For whatever reason, the box ONLY updates if you have ac-auto-start on. That's where the defadvice comes in. ac-auto-start is still off in the default case. When you press TAB to start completing, ac-auto-start is temporarily turned on until the completion is done at which time the ac-auto-start is turned back off. That way the dropdown box is only turned on when you press TAB, but it still updates as you type a completion.
Clear as mud? Feel free to ask me anything you didn't understand.
nice setup :).
How can I make completion go faster though?
When I do
import sys
print sys.pa<TAB>
rope/pymacs looks through ALL the files on my hard drive which takes a while. Why doesn't it just search in my Python libraries?
ln -s ../ropemode/ropemode ropemacs/
That directory doesn't exist so ln raises an error.
if 0 == 1:
__print 0
__print 1
If point is on the 'p' of the second line, TAB should cycle the whole line through indentation alternatives. Instead, I get an auto-complete list with
ArithmeticError
AssertionError
AttributeError
etc...
Any idea?
you're talking about and I changed this in my github (linked above). Did you
check there? The relevant file is ryan-python.el.
I'm leaving this post as is, for posterity, so check my github for updates.
Now, maybe I would change the line:
ln -s vendor/yasnippet-0.5.9/snippets/ .
for
ln -s vendor/yasnippet-0.5.9/snippets . <- required in Mac OS i.e.
and add:
rm vendor/*.tar*
Thank you a lot!
me know.
Symbol's value as variable is void: ac-source-yasnippet
The link that I had for autocomplete.el got changed to point to version
0.2.0, which made some incompatible changes, I modified the post to point to
the 0.1.0 version which should work better for you.
Probably soon I'll update this post for version 0.2.0.
thx
complete?
results in "ERROR 400: BAD REQUEST"
There is only revision 6 available now (for whatever reason). This one works though:
$ wget http://tinyurl.com/mbfr74
Best,
-- Maik
Any update on the updated version with auto-complete 0.2.0 ?
Thanks again.
Cheers,
Nicolas
1. first how do i make sure auto completion is case insensitive e.g typing django.http.h listing django.http.HttpResponse. something of that sort.
2. how do i change the red color used for python warning and errors
3. how do i make key-bindings work with only specific modes
thanks
http://www.rwdev.eu/articles/emacspyeng
With your code above, I think you would have the best damn autocompletion/documentation for Python out there.
Very helpful and useful post. Thanks.
I have written a complete newbies startup guide for emacs+python here : http://venkys-dotplan.blogspot.com and included this technique of auto-completion as part of that.
http://nerdtopia.org/auto-complete.el
Once I get the hang of emacs/elisp (only been using it for a week or two, vi convert here.), I'll try to write something that works with .2. Until then, happy hacking!
Well done.
What a mess it can be setting up python in emacs!
this function is so cool, but I got the error "Symbol's value as variable is void: ac-source-yasnippet", I read the posts and see must download autocomplete.el 0.1.0, but it's not available on the wiki, could you provide me 0.1.0?
Thanks a lot!
prefix-list-elements: Symbol's function definition is void: rope-completion
Is the current rope(macs|mode) missing rope-completions or is something maybe not being loaded?
Anyway, thanks for all the helpful information.
Christopher
my emacs:23.1-winnt
and my os: winxp
http://richardriley.net/projects/emacs/dotprogr...
But your emacs configuration on github works fine; after adding a few missing files and renaming some directories. Thanks very much.