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

prefer_single_line_comments does not work for xml #52

Open
tkkcc opened this issue Jun 30, 2021 · 5 comments
Open

prefer_single_line_comments does not work for xml #52

tkkcc opened this issue Jun 30, 2021 · 5 comments

Comments

@tkkcc
Copy link

tkkcc commented Jun 30, 2021

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> -->
@3719e04
Copy link

3719e04 commented Jul 19, 2021

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',

@tkkcc
Copy link
Author

tkkcc commented Jul 19, 2021

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

@3719e04
Copy link

3719e04 commented Jul 19, 2021

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,
})

@tkkcc
Copy link
Author

tkkcc commented Jul 19, 2021

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,{"<!--","-->"}}.

function M.config_from_commentstring(commentstring)
local placeholder = '%s'
local index_placeholder = commentstring:find(vim.pesc(placeholder))
if not index_placeholder then
return M.get_default_config()
end
index_placeholder = index_placeholder - 1
--[[ Test if the commentstring is a single-line or multi-line comment,
extract the appropriate fields into a table ]]
if index_placeholder + #placeholder == #commentstring then
return {vim.trim(commentstring:sub(1, -#placeholder-1)), false}
end
return {false, {vim.trim(commentstring:sub(1, index_placeholder)),
vim.trim(commentstring:sub(index_placeholder + #placeholder + 1, -1))}}
end

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

-- If the language doesn't support multi-line comments
if config[2] == false then
mode = modes.force_single
-- If the language doesn't support single-line comments
elseif config[1] == false then
mode = modes.force_multi
end
return mode

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

@Iron-E
Copy link

Iron-E commented Jul 25, 2021

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.

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