inbound indentation of multiline assignements

Bug #629916 reported by Mr. Fooz
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
Undecided
Andreas Roehler

Bug Description

Thanks for making such a great tool for editing python code in emacs.

If I use parentheses for multiline continuations, indentation works as I expect. For example,

foo_long_long_long_long = (
    bar_long_long_long_long[
        (x_long_long_long_long == X) &
        (y_long_long_long_long == Y)])

is beautiful and just the way I like it.

On the other hand, if I use a backslash for continuations, a single indentation is created and all subsequent lines stop using the extra indentation logic. Below the third and fourth lines fail to have any extra indentation

foo_long_long_long_long = \
    bar_long_long_long_long[
    (x_long_long_long_long == X) &
    (y_long_long_long_long == Y)]

It would be nice if backslash line continuations worked the same way as parethesized expressions: additional lines would continue to have all the indentation logic active.

Although I'm personally happy to use parens for continuations, others I work with strongly prefer backslash continuations and when I edit their files, it hard to not mess up their indentation.

Related branches

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Hi,

thanks taking part.

As the indentation cases provided don't concern syntax,
I'm afraid it's a pure style question with several
solutions possible.

Interesting matter, please permit some considerations
(just personal views, which might be wrong...)

If a indent in python has not syntactic meaning, that
  should be visible IMHO, if possible.

Given that's a valid argument, both styles offered are
not satisfying. I'd choose

foo_long_long_long_long = (
                           bar_long_long_long_long[
                           (x_long_long_long_long == X) &
                           (y_long_long_long_long == Y)])

resp.

foo_long_long_long_long = \
                          bar_long_long_long_long[
                          (x_long_long_long_long == X) &
                          (y_long_long_long_long == Y)]

BTW not displayed correctly here.
Indent should be at the column of first lines end.

Andreas

--
https://code.launchpad.net/~a-roehler/python-mode
https://code.launchpad.net/s-x-emacs-werkstatt/

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
Revision history for this message
Andreas Roehler (a-roehler) wrote :

Hi,

identation would result now in

foo_long_long_long_long = (bar_hflong_long_long_long
                        [(x_long_long_long_long == X) &
                      (y_long_long_long_long == Y)]
                        )

closing this bug, is this has been discussed so far.

Thanks again

Andreas

Changed in python-mode:
status: New → Opinion
Revision history for this message
Skip Montanaro (smontanaro) wrote :

Am 25.03.2011 19:32, schrieb <email address hidden>:
> I find this indentation truly grating:
>
> self.last_abc_attr = self.last_xyz_attr = \
> self.last_abc_other = \
> self.last_xyz_other = None
>
> Now, I can move self.last_xyz_attr to a continuation line, but though the
> result is slightly different, it is, in my opinion, just as bad:
>
> self.last_abc_attr = \
> self.last_xyz_attr = \
> self.last_abc_other = \
> self.last_xyz_other = None
>
> What I would like to see is this (given a four-space block indent):
>
> self.last_abc_attr = \
> self.last_xyz_attr = \
> self.last_abc_other = \
> self.last_xyz_other = None
>
> or, if the second expression remained on the first line:
>
> self.last_abc_attr = self.last_xyz_attr = \
> self.last_abc_other = \
> self.last_xyz_other = None
>
> I don't care if this behavior is the default. I just want to be able to
> control it. Currently, I have to manually format lines like this, and if
> I'm not careful and reindent an entire function or file, then python-mode
> undoes my work.

Changed in python-mode:
status: Opinion → In Progress
summary: - indentation with backslash line continuations
+ inbound indentation of multiline assignements
Changed in python-mode:
status: In Progress → Fix Committed
Changed in python-mode:
milestone: none → 6.0
Changed in python-mode:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.