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

Adding multi-line block comments for Python #1372

Closed
kolibril13 opened this issue Apr 20, 2024 · 5 comments
Closed

Adding multi-line block comments for Python #1372

kolibril13 opened this issue Apr 20, 2024 · 5 comments

Comments

@kolibril13
Copy link

Describe the issue

Currently, it's not possible to toggle multi line block-comments in JupyterLab on non-US keyboard layouts.
It would be amazing if this feature could be added to codemirror, as this would help a lot of people all around the world to quickly comment/uncomment their code blocks in JuyterLab.
Here is the corresponding comment in JupyterLab:
jupyterlab/jupyterlab#16186 (comment)
Thanks for considering this issue!
cc. @krassowski

Browser and platform

JupyterLab

Reproduction link

No response

@marijnh
Copy link
Member

marijnh commented Apr 20, 2024

I wasn't aware Python has block comments. What exactly do you mean?

@krassowski
Copy link

To clarify, this has nothing to do with keyboard layouts.

The problem is that the block comment command is no-op in languages where the block comment tokens are not defined.

The first question is whether you would consider having block comment syntax using string literals (""") for lang-python. This is technically not a comment syntax, but is de facto used as such, especially to create function-level comments (docstrings).

Currently lang-python defines commentTokens: {line: "#"} but does not define the block comment.

On JupyterLab repo a frequent request is to make the block comment work for Python. Naively, this would be a small change:

- commentTokens: {line: "#"}
+ commentTokens: {line: "#", block: {open: '"""', close: '"""'}}

but I am not sure if having the same opening and closing syntax for block comments is supported.

An alternative idea would be to fallback from the block comment command to use line comment if block comment is not defined.

@marijnh
Copy link
Member

marijnh commented Apr 20, 2024

I don't want to set string syntax as comment syntax (though you could do so locally if you want, using pythonLanguage.data.of({commentTokens: ...})). I'm not sure this has nothing to do with key bindings. You could bind toggleComment instead of toggleBlockComment, couldn't you?

@krassowski
Copy link

krassowski commented Apr 20, 2024

though you could do so locally if you want, using pythonLanguage.data.of({commentTokens: ...})

Neat, thank you for the hint!

You could bind toggleComment instead of toggleBlockComment, couldn't you?

Users often use both Python and JavaScript and another language in the same notebook (Python for computation, JS for visualisation), so they do want to have separate shortcuts for different kinds of comments.

We could write a command which decides based on the language to use one or the other (or more specifically to do that based on whether language data at a given position includes commentTokens.block). The question is whether this should be default for toggleBlockComment but my guess is that it does not need to be in CodeMirror core as writing a custom command here is simple enough and can be done with public API.

@marijnh
Copy link
Member

marijnh commented Apr 20, 2024

I agree. Given that there's already toggle comment commands for block, line, and any type, I don't want to make the comment-type-specific commands also generic. You'll have to write a custom command, but it can be pretty simple, just running the commands from @codemirror/command in the order you prefer until one returns true.

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

No branches or pull requests

3 participants