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

[Feature request] Customize comment characters #564

Closed
filipesilva opened this issue Feb 21, 2020 · 6 comments
Closed

[Feature request] Customize comment characters #564

filipesilva opened this issue Feb 21, 2020 · 6 comments

Comments

@filipesilva
Copy link

When I press the Toggle line comment command, the current line is prefixed with ; .

My colleagues are using another editor (spacemacs I think), that seems to use ;; for comments instead. I've also seen ;; in a lot of code snippets online.

I thought it might be a good idea to customize the characters that the editor inserts.

But I wasn't aware but this seems to be a ELisp convention:

So perhaps this is a more complicated situation.

@PEZ
Copy link
Collaborator

PEZ commented Feb 22, 2020

Thanks for investigating this a bit. I think it is pretty clear that line comments should be ;; rather than ;, so opted for just changing that instead of making it a configuration. (Walking the Calva Tao 😄 )

I also added support for Toggle block comment, wrapping the block in a (comment ...) form.

Test with this VSIX, which also sports the latest Calva Highlight and Paredit parsing: https://4016-125431277-gh.circle-artifacts.com/0/tmp/artifacts/calva-2.0.77-dev-58d85c07.vsix

@filipesilva
Copy link
Author

Just installed it and can confirm that the Toggle line comment keybind now uses ;; instead of ;. I Agree that it's better to just "do right thing" instead of adding an option for it.

The new Toggle block comment doesn't seem to toggle per se though. It seems to wrap on the first use, and wrap again on the second use. I imagined that it would work as Toggle line comment insofar as it added and removed the (comment ... ) block. But maybe that was not your intention to begin with.

@filipesilva
Copy link
Author

Here's how it looks after using Toggle block comment four time:

(comment
 (comment
 (comment
 (comment
 (print "hello block comment") ) ) ) )

Looking at 58d85c0 makes me wonder if there's some weird interaction going on. You're just adding the vscode language settings for comments so it is out of your hands how the toggling proper works. Maybe the auto-indent is adding a couple of spaces and making it so the toggle doesn't work anymore?

@PEZ
Copy link
Collaborator

PEZ commented Feb 23, 2020

I don't think there is any auto-indent going on even. You have to press tab after the wrapping to get it formatted. ¯_(ツ)_/¯

@filipesilva
Copy link
Author

If I start with

(print "hello block comment")

And run Toggle block comment, I get

(comment
 (print "hello block comment") )

So it added (comment\n and ). Note the two spaces after \n and the single space before ).

But in 58d85c0, we don't see those three spaces:

blockComment: ['(comment\n', ')']

If I start with

(do
  (print "hello block comment"))

And run Toggle block comment with (print "hello block comment") selected, I get

(do
  (comment
 (print "hello block comment") ))

So the same thing, regardless of current indentation: (comment\n and ), three spaces.

@PEZ
Copy link
Collaborator

PEZ commented Feb 23, 2020

There is a setting for if VS Code should add spaces there or not. Doesn't matter for toggling or not though... I made an experiment with using #_( and ) as the pair instead. Then the toggle happens once, but VS Code loses track of the current selection so toggling again just wrecks havoc. Short of making our own command for this, I don't think we can do much about it.

@PEZ PEZ closed this as completed in 58d85c0 Feb 23, 2020
PEZ added a commit that referenced this issue Mar 6, 2020
Fixes #564
Also add support for toggle block comment, wrapping w/ (comment ...)
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

2 participants