Subject: Re: bug#21921: New function comment-line also comments first line after region

From: Rasmus <[email-masked]>
Date: Sun, 15 Nov 2015 12:45:02 +0100

Hi Clément,

Thanks for details report.

Clément Pit--Claudel <[email-masked]> writes:

> Its documentation says:
>
>   If region is active, comment lines in active region instead.
>
> However, it seems that it also comments out the line just after the end
> of the region.
>
> For example, given the following text
>
> abc
> def
> ghi
>
> Placing the cursor before `a', then pressing C-SPC C-n C-n, causes two
> lines to be marked: (> is highlighting, | is point)
>
>>abc
>>def
> |ghi
>
> Yet pressing C-x C-; (comment-region) comments out all three lines.

Because the end of region is at point.  Try to run this:

        (list (point)  (region-beginning) (region-end))

Also, from the docstring,

      Unlike ‘comment-dwim’, this always comments whole lines.

You'd get what you'd expect if you run comment-dwim (M-;)

> Similarly, again starting from 
>
> abc
> def
> ghi
>
> placing the point before `g' and pressing C-SPC C-p C-p causes two lines
> to be marked:

Again, in fact the region start at 'g'.  Check e.g. with C-x C-x.  But
it's not obvious from the face.

>>|abc
>>def
> ghi
>
> Yet pressing C-x C-; comments out all three lines. I find this second example especially confusing.
>
> Is this behaviour only surprising to me?

Perhaps the confusion is caused by region not being displayed at column
zero.

The behavior is correct IMO.

For your particular examples, comment-dwim does what you want, it seems.

Hope it helps,
Rasmus

-- 
Spil noget med Slayer!