In this page, I will explain my emacs environment for programing and interactive session with Python. I put emphasis on my because this may not be the most elegant solution (and probably it isn't). The effectiveness of a human interface depends a lot on the user's preference. Therefore, the example shown here strongly reflects my personal preferences. You may want to change details of the behavior. You can do so but you have to know a bit about Emacs Lisp. Since I don't have a time to explain Emacs Lisp here, I will just refer you to two nice documents for learning Emacs Lisp, An Introduction to Programming in Emacs Lisp and GNU Emacs Lisp Reference Manual.
Before going into the details of the emacs setting, I will list my computer environment as a reference.
Hardware | PC (Sony VAIO type Z) |
OS | Ubuntu 9.10 (x86-64) |
In addition to Emacs, you need to install several packages. I took most of the information from here.
Once you have installed the above packages, edit your .emacs file.
Here is an example of .emacs file. You can merge this file into your .emacs file. Please read the comments in the file to see what is going on.
When you invoke Emacs, supply "-py" option. This is necessary because in my .emacs, this option is used to determine whether to load pymacs and ropemacs or not. pymacs and ropemacs are not loaded by default because it takes some time and delays the start up of Emacs. You do not want to load them unless you know you are going to use rope. If "-py" option is used, Emacs will load pymacs and ropemacs at the start up. If you did not specify "-py" but want to use rope later in the session, you can call my-pymacs-init (by typing "M-x my-pymacs-init") at any time.
If you open a file with an extension ".py", the python-mode will be automatically invoked. You will have nice syntax highlighting and automatic indentation.