Comment indented incorrectly after inline comment

Bug #873372 reported by Ryan Kaskel
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
Medium
Andreas Roehler

Bug Description

Another little comment bug:

---------------------
foo = True # the next line is indented incorrectly
           # to here
----------------------

I think it should line up with 'f' in 'foo'.

Ryan Kaskel (ryankaskel)
description: updated
Revision history for this message
Barry Warsaw (barry) wrote : Re: [Bug 873372] [NEW] Comment indented incorrectly after inline comment

On Oct 13, 2011, at 02:18 PM, Ryan Kaskel wrote:

>Another little comment bug:
>
>---------------------
>foo = True # the next line is indented incorrectly
>           # to here
>----------------------
>
>I think it should line up with 'f' in 'foo'.

I'm not sure I agree entirely. I tend to avoid these types of comments, but I
think this one is worth a discussion on the mailing list.

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

Am 13.10.2011 16:37, schrieb Barry Warsaw:
> On Oct 13, 2011, at 02:18 PM, Ryan Kaskel wrote:
>
>> Another little comment bug:
>>
>> ---------------------
>> foo = True # the next line is indented incorrectly
>> # to here
>> ----------------------
>>
>> I think it should line up with 'f' in 'foo'.
>
> I'm not sure I agree entirely. I tend to avoid these types of comments, but I
> think this one is worth a discussion on the mailing list.
>

so cc to it.

I'm in favor of the present behavior BTW.

However agree, there are two reasonable positions of a following indent.

Would support a request that way:

when cursor is at the indented comment in second line, a dedent should
reach the column 0.

Agreed?

Revision history for this message
Barry Warsaw (barry) wrote : Re: [Python-mode] [Bug 873372] [NEW] Comment indented incorrectly after inline comment

On Oct 13, 2011, at 06:41 PM, Andreas Röhler wrote:

>Am 13.10.2011 16:37, schrieb Barry Warsaw:
>> On Oct 13, 2011, at 02:18 PM, Ryan Kaskel wrote:
>>
>>> Another little comment bug:
>>>
>>> ---------------------
>>> foo = True # the next line is indented incorrectly
>>> # to here
>>> ----------------------
>>>
>>> I think it should line up with 'f' in 'foo'.
>>
>> I'm not sure I agree entirely. I tend to avoid these types of comments, but I
>> think this one is worth a discussion on the mailing list.
>>
>
>so cc to it.
>
>I'm in favor of the present behavior BTW.
>
>However agree, there are two reasonable positions of a following indent.
>
>Would support a request that way:
>
>when cursor is at the indented comment in second line, a dedent should reach
>the column 0.

In this case, but in cases where there is leading indentation, a dedent would
reach that column. Right?

>Agreed?

Seems reasonable to me.

-Barry

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

Am 13.10.2011 19:32, schrieb Barry Warsaw:
> On Oct 13, 2011, at 06:41 PM, Andreas Röhler wrote:
>
>> Am 13.10.2011 16:37, schrieb Barry Warsaw:
>>> On Oct 13, 2011, at 02:18 PM, Ryan Kaskel wrote:
>>>
>>>> Another little comment bug:
>>>>
>>>> ---------------------
>>>> foo = True # the next line is indented incorrectly
>>>> # to here
>>>> ----------------------
>>>>
>>>> I think it should line up with 'f' in 'foo'.
>>>
>>> I'm not sure I agree entirely. I tend to avoid these types of comments, but I
>>> think this one is worth a discussion on the mailing list.
>>>
>>
>> so cc to it.
>>
>> I'm in favor of the present behavior BTW.
>>
>> However agree, there are two reasonable positions of a following indent.
>>
>> Would support a request that way:
>>
>> when cursor is at the indented comment in second line, a dedent should reach
>> the column 0.
>
> In this case, but in cases where there is leading indentation, a dedent would
> reach that column. Right?

OK, that might line up that way possibly

call_this_function(
     foo=bar).another_function( # some comment
     # some more comment
         foo=bar)

>
>> Agreed?
>
> Seems reasonable to me.
>
> -Barry
>

Revision history for this message
Ryan Kaskel (ryankaskel) wrote :

Like Barry, I tend to avoid these types of comments.

If it's a really short comment, I might put it there. I never continue the comment on the next line like

x = 1 # set this here
          # so it does something

I tend to merge both and put it on the line above.

I think the present behavior can stay but a dedent should take the cursor to where it would have been had the comment not been there. (column 0 in the example but not in the following:

def foo():
    bar = 1 # set bar here -- hit return and then dedent
    baz = 0
    |
    > cursor taken here after dedent

I'll comment on the other syntax (from comment 4 here) in that "bug's" thread.

Revision history for this message
Andreas Roehler (a-roehler) wrote : Re: [Bug 873372] Re: Comment indented incorrectly after inline comment

Am 13.10.2011 20:33, schrieb Ryan Kaskel:
> Like Barry, I tend to avoid these types of comments.
>
> If it's a really short comment, I might put it there. I never continue
> the comment on the next line like
>
> x = 1 # set this here
> # so it does something
>
> I tend to merge both and put it on the line above.
>
> I think the present behavior can stay but a dedent should take the
> cursor to where it would have been had the comment not been there.
> (column 0 in the example but not in the following:
>
> def foo():
> bar = 1 # set bar here -- hit return and then dedent
> baz = 0
> |
> > cursor taken here after dedent

that's the way it works now
nothing to change here

>
> I'll comment on the other syntax (from comment 4 here) in that "bug's"
> thread.
>

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

Am 13.10.2011 20:33, schrieb Ryan Kaskel:
> Like Barry, I tend to avoid these types of comments.
>
> If it's a really short comment, I might put it there. I never continue
> the comment on the next line like

Me too.

So after all, the current behavior seems not that useful.
Rather remove special indent after inline comments.

[ ... ]

Changed in python-mode:
status: New → In Progress
Revision history for this message
Ryan Kaskel (ryankaskel) wrote :

> that's the way it works now
> nothing to change here

Are you sure? I just tried it and in the below case I have to dedent three times to get the desired position:

def foo():
    bar = True # set bar here
            # dedents here
        # then here
    # finally here

I would prefer if the current special indent after inline comments was removed. This is the behavior I would like:

def foo():
    bar = True # set it
    # return should take me here
                         # because I never put comments on multiple lines out here

Barry didn't agree. You and I seem to favor the above style.

Revision history for this message
Ryan Kaskel (ryankaskel) wrote :

(the formatting on the last comment should aline with "# set it")

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

Am 14.10.2011 11:52, schrieb Ryan Kaskel:
>> that's the way it works now
>> nothing to change here
>
> Are you sure? I just tried it and in the below case I have to dedent
> three times to get the desired position:
>
> def foo():
> bar = True # set bar here
> # dedents here
> # then here
> # finally here

OK, see it.

>
> I would prefer if the current special indent after inline comments was
> removed. This is the behavior I would like:
>
> def foo():
> bar = True # set it
> # return should take me here
> # because I never put comments on multiple lines out here

not sure if I get it displayed correctly

Last both comment line are at col 4, right?

>
> Barry didn't agree.

? Didn't notice that.

> You and I seem to favor the above style.
>

BTW a fix is underway, which will bind the current inline-honoring to a
var, default will be the new behavior suggested.

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

Am 14.10.2011 11:53, schrieb Ryan Kaskel:
> (the formatting on the last comment should aline with "# set it")
>

really?

How would you express a rule for that?

vertical-camel ? :)

BTW checked in before reading this,
maybe have a look

Changed in python-mode:
status: In Progress → Fix Committed
Revision history for this message
Ryan Kaskel (ryankaskel) wrote :

Perfect. Thanks so much and have a great weekend!

Is there a link to the fix's diff from the bug page? I want to start studying the source code so maybe one day I can contribute code.

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.