< BACKMake Note | BookmarkCONTINUE >
152015024128143245168232148039196038240039088173205162105045222218065012143150139177233

Editing Code

As you already know, Python provides two development environments that offer a lot of useful features which can help you while coding: Pythonwin and IDLE. However, for simple programs, or in case you don't have a graphical environment available, you can stick to simple text editors that can be used to handle the job very nicely.

On Windows systems, you can use editors such as Editpad and Notepad to write Python scripts; on DOS systems, EDIT, and on UNIX systems you have choices such as Pico, Vi, Emacs, and others.

Pico is a full screen editor that is reasonably intuitive. Pico's commands can be learned in just some minutes and Pico itself is good for editing small texts with just a few changes. However, you need commands that are more powerful when a text becomes bigger because Pico only has a limited number of commands. These commands are shown at the bottom of the editing screen. Also note that Pico makes limited use of mice. Pico is not 100% recommended for Python programming because it wasn't designed as a programmer's editor. It does things such as automatic word wrap, which might not be what you want.

Vi (visual editor) is another full screen editor that was seen as a big improvement over line editing. Vi is highly customizable, allows filtering, has number prefixes for commands, has an invocation of a shell, has better jump commands, can read in the result of external commands, save parts of text, substitute literal strings and regular expressions, and many other options. The vi clone vim (vi improved) can be scripted in Python among other languages.

JED is a freely available text editor for UNIX, VMS, MSDOS, OS/2, and MS Windows. This editor has many features, including drop-down menus, folding support, color syntax highlighting on color terminals, and emulation of Emacs, EDT, Wordstar, and Borland editors. It's said that the latest version of the JED editor has a Python mode, with many of the same features as the Emacs/XEmacs Python mode.

See its Web page for more information:

http://space.mit.edu/~davis/jed.html

Vi, Pico, and JED are certainly powerful editors. However, Emacs is quite a jump in feature variety. Emacs is a very extensible and customizable editor. The richness of Emacs makes it more difficult to learn, but it is worth the try. A version of Emacs called XEmacs (which is a very famous implementation) can also be used for writing Python programs.

Emacs

Emacs originally was an acronym for Editor MACroS. The heart of Emacs is an interpreter for elisp (Emacs Lisp), which is a dialect of the Lisp programming language with extensions to support text editing. Currently, Emacs is much more than a text editor. Besides allowing you to edit several styles of source codes and other general-purpose files, it contains many extensions that provide support for features such as Web browsing and mail reading. Emacs is a GNU project, and it is maintained by the Free Software Foundation.

Some of the features of Emacs include

  • Content sensitive major modes for a wide variety of file types, from plain text to source code to HTML files.

  • Complete online documentation, including a tutorial for new users.

  • Emacs is highly extensible through the Emacs Lisp language.

  • Support for many human languages and their scripts.

  • A large number of extensions which add other functionality (the GNU Emacs distribution includes many extensions).

Check out the GNU Emacs Web site for details:

http://www.gnu.org/software/emacs/

Note

XEmacs is a highly customizable open source text editor and application development system, which is based on GNU Emacs, and shares a lot of code with it. XEmacs is protected under the GNU Public License, and its emphasis is on modern graphical user interface support and an open software development model. XEmacs has an active development community and runs on Win32 and UNIX platforms. See http://www.xemacs.org/ for details.



Emacs has its own section on the Python Web site, precisely at the following address:

http://www.python.org/emacs/

At that page, you can find a collection of links to several Emacs codes that might help with your Python programming. Most of the code works fine on top of the latest versions of both Emacs and XEmacs.

From that page, you can also get access to some Emacs modes that enable the coding of Python source code when using Emacs, such as the Python Mode, located at

http://www.python.org/emacs/python-mode/

You might want to byte-compile that python-mode file when installing it on your system, primarily for better performance. To do so, you need to open Emacs (or XEmacs) and execute the following commands. Note that you can safely ignore any byte compiler warnings.

						
C-x C-f /path/to/python-mode.el RET
M-x byte-compile-file RET

					

On the Web site, besides getting access to the latest release of the python-mode (the current version is 3.105), you can also obtain other useful stuff, which includes: a detailed list of changes since the last released version, installation notes, a FAQ, and a Emacs/XEmacs compatibility details list, which brings special notes about Emacs/XEmacs versions and package interactions.

To install the python-mode package so that it can be used in Python, you would put it in the site-lisp directory, and edit your site-start.el to autoload python-mode.el and bind it to .py files.

The following links provide additional information related to the usage of Emacs/XEmacs along with Python.

The OO-Browser—This is a multi-windowed, interactive, object-oriented class browser that supports Python, and was designed for professional use under the Emacs editor. See the following Web site for details:

http://www.beopen.com/manuals/alt-oobr-cover.html

Introduction to Using OO-Browser with Python—This is a paper by Harri Pasanen, presented at the International Python Conference IV, June 1996.

http://www.python.org/workshops/1996-06/papers/h.pasanen/oobr_contents.html

Python Library Reference Hot-Key Help System for XEmacs—This is Harri Pasanen's work. This program shows the Python Library Reference for the word under cursor every time you press the F1 key when in Python mode under the XEmacs.

http://bigbear.pc.helsinki.fi/harri/


Last updated on 1/30/2002
Python Developer's Handbook, © 2002 Sams Publishing

< BACKMake Note | BookmarkCONTINUE >

Index terms contained in this section

applications
     Emacs
            editing source code 2nd 3rd
      JED
      Pico
     source code
            editing 2nd 3rd 4th
      Vi (visual editor)
     XEmacs
            editing source code 2nd 3rd
browsers
      OO
changing
      source code 2nd 3rd 4th
code
     source
            editing 2nd 3rd 4th
editing
      source code 2nd 3rd 4th
elisp (Emacs Lisp) programming language
Emacs
     editing
            source code 2nd 3rd
Emacs Lisp (elisp) programming language
Free Software Foundation
installing
      python-mode package
Introduction to using OO-Browser with Python
JED
modifying
      source code 2nd 3rd 4th
OO-Browser
packages
     python-mode
            installing
Pasanen, Harry 2nd
Pico
programming languages
      elisp (Emacs Lisp)
programs
     Emacs
            editing source code 2nd 3rd
      JED
      Pico
     source code
            editing 2nd 3rd 4th
      Vi (visual editor)
     XEmacs
            editing source code 2nd 3rd
Python Library Hot-Key Help System for XEmacs
python-mode package
      installing
software
     Emacs
            editing source code 2nd 3rd
      JED
      Pico
     source code
            editing 2nd 3rd 4th
      Vi (visual editor)
     XEmacs
            editing source code 2nd 3rd
source code
      editing 2nd 3rd 4th
Vi (visual editor)
visual editor (Vi)
XEmacs
     editing
            source code 2nd 3rd

© 2002, O'Reilly & Associates, Inc.