JoosepAlviste / nvim-ts-context-commentstring

Neovim treesitter plugin for setting the commentstring based on the cursor location in a file.
MIT License
1.18k stars 35 forks source link

Can I set newlines in commentstrings? #53

Closed reyniersbram closed 1 year ago

reyniersbram commented 1 year ago

I want my block comments for lua to be like this:

--[[
some commented-out text or code
--]]

So I thought it would be easy to just do something like this:

require("nvim-treesitter.config").setup{
    ...
    context_commentstring = {
    ...
        config = {
            lua = {
                __default = "-- %s",
                __multiline = "--[[\n%s\n]]"
            },
        },
    },
}

but when commenting a block of code with Comment.nvim the newlines are replaced by spaces.

Am I doing something wrong, or is it just not possible to have newlines in a commentstring.

This is a link to the specific code in my dotfiles repo.

JoosepAlviste commented 1 year ago

Hey!

I tried this out myself too and couldn't get it to work with the Lua multiline strings either:

require('Comment').setup {
  pre_hook = function()
    return [=[--[[
%s
]]]=]
  end,
}

I think that this plugin can't do much about this though since the commenting plugin needs to handle the commentstring with new lines.

I found this issue in Comment.nvim that might be similar to your use case: https://github.com/numToStr/Comment.nvim/issues/38 Maybe this helps?

But you could open an issue/feature request in the Comment.nvim repo since I don't think we could do anything about this in this plugin.

Let me know how it goes!