Looking for indent advice howto in emacs python-mode

Carl Banks pavlovevidence at gmail.com
Tue Apr 1 01:31:23 EDT 2008


On Mar 31, 12:32 pm, "Steven W. Orr" <ste... at syslang.net> wrote:
> Here's what I want to do:
>
> if ( ( v == 1 )
>    or ( v == 2 )
>    or ( v == 3 ) ):
>      pass
>
> but emacs (left to its own devices, does this.
>
> if ( ( v == 1 )
>       or ( v == 2 )
>       or ( v == 3 ) ):
>      pass
>
> It works great for me in C-mode. Does anyone know how to jimmie up
> python-mode so it would know how to do this?


Not sure about the python.el that ships with emacs 21, but the python-
mode.el that is used in emacs 20, it can't be done without modifying
the Lisp code.

An open nesting character with nothing on the line following it will
indent the following line 4 (or whateve py-basic-indent is set to)
spaces.  An open nesting character with something following it will
indent the following line to match the column of the first item.
There is no option to change this.

If you are not afraid of Elisp, then the function to modify is called
py-compute-indentation, and you should look for a comment with the
text "again mimic the first line item".  That is where the indent in
this case is set.  The code following the comment "elset they're about
to enter the first item" sets the indent for the other case.  You
might want to use that code in all cases.  (Warning: this may cause
problems elsewhere, such as nesting function call.)

And once again, all bets are off if you're using python.el in Emacs
21.


Carl Banks



More information about the Python-list mailing list