Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Looking for indent advice howto in emacs python-mode

Reply
Thread Tools

Looking for indent advice howto in emacs python-mode

 
 
Steven W. Orr
Guest
Posts: n/a
 
      03-31-2008
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
 
Reply With Quote
 
 
 
 
bruno.desthuilliers@gmail.com
Guest
Posts: n/a
 
      03-31-2008
On 31 mar, 18:32, "Steven W. Orr" <(E-Mail Removed)> wrote:
> Here's what I want to do:
>
> if ( ( v == 1 )
> or ( v == 2 )
> or ( v == 3 ) ):
> pass


Why the parens ?

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


 
Reply With Quote
 
 
 
 
Gabriel Genellina
Guest
Posts: n/a
 
      04-01-2008
En Mon, 31 Mar 2008 16:36:13 -0300, http://www.velocityreviews.com/forums/(E-Mail Removed)
<(E-Mail Removed)> escribió:

> On 31 mar, 18:32, "Steven W. Orr" <(E-Mail Removed)> wrote:
>> Here's what I want to do:
>>
>> if ( ( v == 1 )
>> or ( v == 2 )
>> or ( v == 3 ) ):
>> pass

>
> 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)

--
Gabriel Genellina

 
Reply With Quote
 
7stud
Guest
Posts: n/a
 
      04-01-2008
On Mar 31, 10:32*am, "Steven W. Orr" <(E-Mail Removed)> wrote:
> Here's what I want to do:
>
> if ( ( v == 1 )
> * *or ( v == 2 )
> * *or ( v == 3 ) ):
> * * *pass
>


python indenting = 4 spaces
 
Reply With Quote
 
Carl Banks
Guest
Posts: n/a
 
      04-01-2008
On Mar 31, 12:32 pm, "Steven W. Orr" <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: how to indent/dedent a region in emacs? Alexander Schmolck Python 0 06-11-2008 10:49 PM
gnu indent: how to avoid extra indent? dt C Programming 4 12-31-2006 11:31 AM
emacs ruby-mode statement modifier indent problem? Mike Shire Ruby 6 04-20-2005 06:34 AM
Emacs python mode indent levels John Fouhy Python 2 07-15-2004 12:46 PM
Emacs python mode equivalent to c-tab-always-indent G.A. Python 2 11-11-2003 09:53 PM



Advertisments