Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support paragraph breaks in python block comments. #5148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sjjf
Copy link
Contributor

@sjjf sjjf commented Apr 18, 2024

The current python filetype module treats a single empty comment line (typically created by hitting enter twice while in a block comment) as the end of the block comment, deleting the empty comment line and ending comment prefix copying. This runs contrary to PEP8, which explicitly allows for paragraphs in block comments, with an empty comment as the paragraph separator (see https://peps.python.org/pep-0008/#block-comments for the actual text).

This change implements support for using a single empty comment as a paragraph separator, with two consecutive empty comments being treated as the end of the block comment; both empty comment lines are deleted and comment prefix copying is ended.

This would close issue #5147

This change basically means that you can hit enter twice while you're in a block comment, and you'll get an empty comment and the cursor at the start of a new commented line - if you enter text the block comment will continue as normal, if you hit enter again at this point the block comment is terminated, the empty comments are deleted, and you go back to regular code. This follows the basic logic of the current implementation, while allowing for paragraph breaks in block comments.

This behaviour arguably isn't ideal, particularly with the two empty comments disappearing suddenly - that rather goes against the principle of least surprise. But given the way block comments work it's hard to see a better approach - something like Ctrl-enter, perhaps? I don't know how that would work with a modal editor like Kakoune, though.

Possible issues with the whole idea aside, I'm not confident this is the best possible implementation - it was a lot fiddlier than I anticipated to make it work the way I intended, and it doesn't feel very elegant. There may be cases that aren't handled properly, though I've tried to make it reasonably robust. Any suggestions for improving the code would be appreciated.

I've added tests in the regression/5147-python-block-comment-paragraphs directory, if there's a more appropriate place for them please let me know and I'll relocate them. Additional test cases or a better way to implement them are welcome.

I've already submitted a copyright waiver for previous contributions, I assume that's still considered valid.

@sjjf
Copy link
Contributor Author

sjjf commented Apr 19, 2024

Fixed regression on issue #860 - I forgot to run the full test suite before pushing the changes, only the tests I'd added . . .

@sjjf
Copy link
Contributor Author

sjjf commented Apr 19, 2024

And some further tweaking, hopefully improving the implementation a bit.

@sjjf sjjf force-pushed the python_comment_paras branch 3 times, most recently from 62391a8 to 0690e6d Compare April 28, 2024 09:17
The current python filetype module treats a single empty comment line
(typically created by hitting enter twice while in a block comment) as
the end of a block comment, deleting the empty comment and ending
comment prefix copying. This runs contrary to PEP8, which explicitly
allows for paragraphs in block comments, with an empty comment as the
paragraph separator.

This change implements support for using a single empty comment as a
paragraph separator, with two consecutive empty comments being treated
as the end of the block comment; both empty comment lines are deleted
and comment prefix copying is ended.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant