开发者

How to use Emacs with Python

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. Wh开发者_如何学编程en 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


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.)


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜