kommentary icon indicating copy to clipboard operation
kommentary copied to clipboard

prefer_single_line_comments does not work for xml

Open tkkcc opened this issue 3 years ago • 5 comments

I set

require('kommentary.config').configure_language("default", {
    prefer_single_line_comments = true,
})

for

<string>DejaVu Sans</string>
<string>DejaVu Sans Mono</string>

expect(nerdcommenter)

<!--<string>DejaVu Sans</string>-->
<!--<string>DejaVu Sans Mono</string>-->

but get

<!-- <string>DejaVu Sans</string>
<string>DejaVu Sans Mono</string> -->

tkkcc avatar Jun 30 '21 16:06 tkkcc

Do you have JoosepAlviste/nvim-ts-context-commentstring installed? The following lines in that plugin's instruction will mess up with prefer_single_line_comments

single_line_comment_string = 'auto',
multi_line_comment_strings = 'auto',

3719e04 avatar Jul 19 '21 06:07 3719e04

I comment JoosepAlviste/nvim-ts-context-commentstring and suy/vim-context-commentstring, then do PlugClean and PlugUpdate. The problem is still. Can you get the expected result? @yhu266

tkkcc avatar Jul 19 '21 06:07 tkkcc

Yes I do get expected results. I have the following configurations (in Lua)

require('kommentary.config').configure_language('default', {
  prefer_single_line_comments = true,
  use_consistent_indentation = true,
  ignore_whitespace = true,
  -- JoosepAlviste/nvim-ts-context-commentstring
  hook_function = function()
    require('ts_context_commentstring.internal').update_commentstring()
  end,
})

3719e04 avatar Jul 19 '21 06:07 3719e04

Thanks @yhu266 . I tried but problem remains. Because xml's commentstring <!--%s--> does not end with %s, the following function believes xml is a language that doesn't support multi-line comments. The ending return gives {false,{"<!--","-->"}}.

https://github.com/b3nj5m1n/kommentary/blob/0f8e910156b8ea92690ec3c85808cdba04007ed0/lua/kommentary/config.lua#L269-L283

This will turn mode into force_multi, and ignore user options.

https://github.com/b3nj5m1n/kommentary/blob/0f8e910156b8ea92690ec3c85808cdba04007ed0/lua/kommentary/config.lua#L377-L384

It is safe but not perfect. Also, current single_line_comment_string does not support surrounding comment.

tkkcc avatar Jul 19 '21 11:07 tkkcc

The same thing is happening for me on Markdown and HTML filetypes.

Do you have JoosepAlviste/nvim-ts-context-commentstring installed? The following lines in that plugin's instruction will mess up with prefer_single_line_comments

For context, I don't have this installed.

Iron-E avatar Jul 25 '21 20:07 Iron-E