Setting up Emacs to use python

Tristan Juricek tjuricek at ucsd.edu
Sun Feb 20 14:31:48 EST 2000


Thank you, this works wonderfully.

-Tristan

"Thomas A. Bryan" wrote:

> Tristan Juricek wrote:
> >
> > I've just installed Linux on my computer and I'm interested in setting
> > up Emacs for use with Python.  Being new at both Emacs and Python, I'm a
> > little unclear on what I need to do.  In case it's not a quick answer,
> > does anybody know of a good set of documentation on this subject?
>
> It would help if you mentioned which Linux distribution and version you
> have.  In any case, the following instructions are fairly generic.
> Note that in Emacs speak, C-x means "hold the control key while
> pressing the x key."  C-x f means "hold the control key while pressing
> the x key and then release the control key to press the f key."
> C-x C-f means "hold the control key while pressing the x key and then
> hold the control key while pressing the f key."  If that explanation
> wasn't clear to you, try reading the Emacs tutorial by pressing
> C-h t or by selecting it from the Help menu.
>
> Try to save some effort since python-mode may have come with your
> distribution.  Start emacs, and type
>  M-x locate-library
>  python-mode
> It will say something like /usr/share/emacs/site-lisp/python-mode.el
> if it can find Python-mode on your system.
> You can also open a Python file to check to see whether Python mode
> is being activated:
> emacs &
> (in the emacs application, type) C-x C-f test.py
> The buffer status line should look something like
> --:-- test.py              (Python)--L1--All----------------------
> If it instead looks like this
> --:-- test.py              (Fundamental)--L1--All-----------------
> then Python mode is not installed or not properly configured.
> If you don't see such a status line, you can always get a brief
> description of all the currently active modes by pressing C-h m.
> See whether Python mode is listed in the modes *Help* buffer.
>
> (optional step)
> You may have 'locate' or 'slocate' on your machine.  To check
> whether you already have python-mode.el installed somewhere on
> your machine.  Try running something like this
>   locate python | grep 'el$'
> That locates all files with python in the name that end in 'el'.
> It's generally called python-mode.el, but it could be something
> like python.el.  If it's already on your system, then open
> the file to see what version it is.  The current version is 3.105.
>
> If necessary, download python-mode.el from
> http://www.python.org/emacs/python-mode/python-mode.el
> and read the instructions available at
> http://www.python.org/emacs/python-mode/installation.html
>
> Generally, there is at least one directory on your system where
> emacs will automatically look for byte-compiled modes and such.
> In an emacs window (also called a frame, by the way), type
> M-x describe-variable
> load-path
> Emacs should open a new buffer with an explanation of the load-path
> variable and its current value.  One or more directories generally
> have the name site-lisp in them.  If necessary, move python-mode.el
> into one of those directories.  For example, on a Red Hat 6.0 system,
> something like this should work.
> mv /path/to/downloaded/python-mode.el /usr/share/emacs/site-lisp/
>
> Then follow those instructions on the python web site, something like
> C-x C-f /usr/share/emacs/site-lisp/python-mode.el  RET
> M-x byte-compile-file  RET
> M-x locate-library   RET   python-mode   RET
> C-x C-f ~/.emacs  RET
> (Add the following lines to the end of your .emacs file.)
> ;;; For Python mode
> (setq auto-mode-alist
>       (cons '("\\.py$" . python-mode) auto-mode-alist))
> (setq interpreter-mode-alist
>       (cons '("python" . python-mode)
>             interpreter-mode-alist))
> (autoload 'python-mode "python-mode" "Python hacking mode." t)
> ;;; add these lines if you like color-based syntax highlighting
> (global-font-lock-mode t)
> (setq font-lock-maximum-decoration t)
>
> Now, close emacs (C-x C-c) and reopen emacs.
> Open a buffer
>   C-x C-f test.py
> Check that you're in Python mode (see above).
> Learn *all* of the features of Python-mode by typing
>   C-c ?
> to open a buffer with 684 lines describing the mode.
>
> it's-easier-than-it-sounds-ly yours
> ---Tom




More information about the Python-list mailing list