Looking for indent advice howto in emacs python-mode

Discussion in 'Python' started by Steven W. Orr, Mar 31, 2008.

  1. 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
    Steven W. Orr, Mar 31, 2008
    #1
    1. Advertising

  2. Steven W. Orr

    Guest

    On 31 mar, 18:32, "Steven W. Orr" <> 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
    , Mar 31, 2008
    #2
    1. Advertising

  3. En Mon, 31 Mar 2008 16:36:13 -0300,
    <> escribió:

    > On 31 mar, 18:32, "Steven W. Orr" <> 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
    Gabriel Genellina, Apr 1, 2008
    #3
  4. Steven W. Orr

    7stud Guest

    On Mar 31, 10:32 am, "Steven W. Orr" <> wrote:
    > Here's what I want to do:
    >
    > if ( ( v == 1 )
    >    or ( v == 2 )
    >    or ( v == 3 ) ):
    >      pass
    >


    python indenting = 4 spaces
    7stud, Apr 1, 2008
    #4
  5. Steven W. Orr

    Carl Banks Guest

    On Mar 31, 12:32 pm, "Steven W. Orr" <> 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
    Carl Banks, Apr 1, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. G.A.
    Replies:
    2
    Views:
    971
    Skip Montanaro
    Nov 11, 2003
  2. John Fouhy

    Emacs python mode indent levels

    John Fouhy, Jul 15, 2004, in forum: Python
    Replies:
    2
    Views:
    837
    John Lenton
    Jul 15, 2004
  3. dt
    Replies:
    4
    Views:
    468
    CBFalconer
    Dec 31, 2006
  4. Mike Shire
    Replies:
    6
    Views:
    243
    Carlo E. Prelz
    Apr 20, 2005
  5. Joe Peterson
    Replies:
    0
    Views:
    154
    Joe Peterson
    Dec 28, 2006
Loading...

Share This Page