mawww / kakoune

mawww's experiment for a better code editor
http://kakoune.org
The Unlicense
9.9k stars 713 forks source link

[BUG] Python filetype does not allow paragraphs in block comments. #5147

Closed sjjf closed 3 months ago

sjjf commented 5 months ago

Version of Kakoune

v2023.08.05-290-ge9bd7083

Reproducer

Enter the following in a filetype=python buffer:

# this is a paragraph
#

Go to the end of the last line, and hit enter.

Outcome

The preceding empty comment line is deleted, giving:

# this is a paragraph

Expectations

The preceding empty comment should be retained, to allow for creating a paragraph break in the block comment. This would give:

# this is a paragraph
#

Additional information

As per pep8, block comments in Python should support paragraphs, with paragraph separation being provided by an empty comment line (see https://peps.python.org/pep-0008/#block-comments).

I'm guessing the intent of the current implementation is to allow exiting a block comment without having to explicitly backspace to clear the comment prefix, which I think is perfectly reasonable. The issue is that the current implementation means you have to jump through extra manual hoops in order to get paragraphs in your block comments.

The block comments section of pep8 isn't explicit about what to do with more than one empty comment line in block comments, the exact text is:

Paragraphs inside a block comment are separated by a line containing a single #.

I think it's reasonable to interpret this as meaning that a single empty comment needs to be supported, but that more than one isn't - that would mean you could adjust the python-insert-on-new-line command to treat two consecutive empty comments the way it currently treats one (exiting the block comment), while leaving a single empty comment as-is to allow a paragraph break. I'm getting a pull request implementing this change ready.

sjjf commented 3 months ago

Thanks for merging my proposed fix.