tags:

views:

842

answers:

5

I am new to emacs and I want to use emacs for python development. I am using Ubuntu 9.10. I frustrated to getting emacs work with python. I use GNU Emacs 23.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 2.18.0).

Here what I did. *

Emacs come with python mode but it is confusing there are two types of mode one is python-mode.el and other one is python.el. I use emacs 23 so mine is python.el (I think). Do I need python-mode too? Code completion does not work when I press M-Tab , instead of it window manager works. I tried Esc-Tab but it says "No match" . How can I enable code completion?

After that I installed ropemacs

sudo aptitude install python-ropemacs

Then I created .emacs file at ~/.emacs and I added followings to .emacs file

(require 'pymacs)   
(pymacs-load "ropemacs" "rope-")   
(setq ropemacs-enable-autoimport t)

Then when I hit M-/ (Alt-/) it doesn't work when I cick from the menu Rope->Code assist it opens a file dialog for choosing root project folder. I choose current folder which has there are some python code. When I try again Code assist from menu it says "Completion for x: " nothing but empty set. How can make emacs python code completion work?

Then I downloaded anything.el, anything-config, anything-match-plugin to ~/.emacs.d folder Then I added following lines to .emacs file

(require 'anything-config)   
(require 'anything-match-plugin)   
(global-set-key "\C-ca" 'anything)   
(global-set-key "\C-ce" 'anything-for-files)

Guess what it didnt work. I tried "M-x anything" again I get No match.(I guessed may me combination of C-ca (First control-a then e ) might work it says it isnt defined). Could you explain code completion for python with clear explanations (step by step) to someone dummy as me. Thanks. Edit: I able emacs work with python with the link. Thanks all for answering

A: 

I'm not really sure you had to do anything fancy to get Python development to work. On gNewSense deltah (fork of Ubuntu 8.04) all I did was edit a .py file with the first line being:

#!/usr/bin/python

And then Emacs just figures it out and gives you python mode options. I didn't have to install anything beyond Emacs.

Then again, this may not be helpful as gNewSense pre-installs Emacs by default. I'll have to do it on one of my vanilla Ubuntu installs.

Broam
Emacs activates Python mode by looking py extension but code complation does not work
Tony Cruise
I mean Python menu is visible. I tried from Menu Python->Complete symbol but didn't work.
Tony Cruise
A: 

Emacs worked out of the box for me on Ubuntu 9.10.

Did you try C-c TAB (update imports) before trying code completion? I don't think it work unless you do that.

Nick Craig-Wood
I typed C-c TAB . Then I write impo (I want it to comlete to import) then from menu Python-> Complete symbol I got No match.
Tony Cruise
Yes you are right. My fingers typed `M-/` which works, but isn't the same thing as the menu entry `Complete Symbol` which doesn't appear to work.
Nick Craig-Wood
+1  A: 

I think you do want the package python-mode installed! The ropemacs variants appears to be for refactoring only, and pymacs is allows Python as an Emacs-extension language -- neither of which is what you need for standard support.

Dirk Eddelbuettel
Now I tried followingsudo aptitude install python-modethen I get one extra menu IM-Python and other Python menu completely changed now there is no Complete symbols
Tony Cruise
That's the way it is -- you need other emacs tools to give you code completion under Linux. The EmacsWiki may get you started and the tools (cedet, ecb, ...) are also in Ubuntu. That said, I don't use much beside TAGS and the 'much simpler but mostly good enough' M-/.
Dirk Eddelbuettel
+1  A: 

I haven't tried anything, and I haven't had much luck with rope (giant source tree causes my emacs to hang upon any file save). Instead, I find the default completion works well enough for my purposes.

The default completion keybinding is M-/. That runs dabbrev-expand which expands the current word to "the most recent, preceding word for which this is a prefix." It's not perfect: It won't parse types, and it won't search imports, but it works in 90% of the cases.

(You'll have to deactivate rope.)

AFoglia