Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Emacs with Python

Tags:

python

emacs

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

like image 586
Tony Cruise Avatar asked Dec 07 '09 21:12

Tony Cruise


2 Answers

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

like image 155
AFoglia Avatar answered Oct 09 '22 08:10

AFoglia


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.

like image 32
Dirk Eddelbuettel Avatar answered Oct 09 '22 07:10

Dirk Eddelbuettel