Looking for indent advice howto in emacs python-mode

S

Steven W. Orr

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?

TIA


--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
 
G

Gabriel Genellina

En Mon, 31 Mar 2008 16:36:13 -0300, (e-mail address removed)
Why the parens ?

if a == 1 \
or b == 2 \
or c == 3:
pass

I know it's mostly a matter of style, but I prefer to add parenthesis and
avoid line continuation characters. Sometimes I use parenthesis for
strings too, when multiline strings are not a good choice:

txt = ("En un lugar de "
"la Mancha, de cuyo "
"nombre no quiero "
"acordarme, no ha "
"mucho tiempo...")

(A multiline string would keep the inner \n but in this case I don't want
that)
 
C

Carl Banks

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top