Open rwblokzijl opened 1 year ago
Hey! I also considered that at some point, but didn't really use any of the comments
features, so decided against it (didn't want to bother with it 😅).
I wouldn't mind supporting it, though, as comments
is heavily related to commentstring
. Do you have any ideas on how this would work and how it would be configured? Maybe we could somehow automatically guess the comments
value based on the commentstring
?
Had chatgpt do some research for me, and came up with the following function:
function get_comments_for_filetype(ft)
-- Create a hidden buffer in the background
local temp_buf = vim.api.nvim_create_buf(true, true)
-- Set the desired filetype in the temporary buffer
vim.api.nvim_buf_set_option(temp_buf, 'filetype', ft)
-- Get the comments var from the temporary buffer
local comments = vim.api.nvim_buf_get_option(temp_buf, 'comments')
-- Delete the temporary buffer
vim.api.nvim_buf_delete(temp_buf, { force = true })
return comments
end
You could also do something similar to this for the commentstring
to avoid having to support them manually.
However if you're married to the idea of supporting them manually, you can find all commentstring
and comments
vars in the neovim source code: https://github.com/neovim/neovim/tree/master/runtime/ftplugin
From
:h comments
This plugin should also set the
comments
var. That way OG plugins like https://github.com/glts/vim-textobj-comment will also work.