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

This plugin doesn't set the comments var. #81

Open
rwblokzijl opened this issue Nov 4, 2023 · 2 comments
Open

This plugin doesn't set the comments var. #81

rwblokzijl opened this issue Nov 4, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@rwblokzijl
Copy link

rwblokzijl commented Nov 4, 2023

From :h comments

                                          'comments' 'com' E524 E525
  'comments' 'com'        string  (default
                                  "s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-")
                          local to buffer
          A comma-separated list of strings that can start a comment line.  See
          format-comments.  See option-backslash about using backslashes to
          insert a space.

                                          'commentstring' 'cms' E537
  'commentstring' 'cms'   string  (default "")
                          local to buffer
          A template for a comment.  The "%s" in the value is replaced with the
          comment text.  Currently only used to add markers for folding, see
          fold-marker.

This plugin should also set the comments var. That way OG plugins like https://github.com/glts/vim-textobj-comment will also work.

@rwblokzijl rwblokzijl added the bug Something isn't working label Nov 4, 2023
@JoosepAlviste
Copy link
Owner

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?

@JoosepAlviste JoosepAlviste added enhancement New feature or request and removed bug Something isn't working labels Nov 12, 2023
@rwblokzijl
Copy link
Author

rwblokzijl commented Nov 19, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants