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

[Feature Request] Integrate caw.vim #12

Open
yuki-yano opened this issue Jun 4, 2021 · 4 comments
Open

[Feature Request] Integrate caw.vim #12

yuki-yano opened this issue Jun 4, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@yuki-yano
Copy link

caw.vim is an excellent comment management plugin and I would like to see it integrated.
I am new to Lua, is there anything I can do to help?

https://github.com/tyru/caw.vim

@JoosepAlviste
Copy link
Owner

Hey! There are 2 main ways that I can see how integrations might work:

  1. (Preferred) The commenting plugin allows configuring a "hook" function that will be called before the commenting is done. For example, b3nj5m1n/kommentary has this option available. Then, it's just a matter of configuring the commenting plugin to run lua require('ts_context_commentstring.internal').update_commentstring() before the commentstring is used.
  2. Adding custom key mappings which would first run lua require('ts_context_commentstring.internal').update_commentstring() and then trigger the commenting plugin functions. There is a useful utility function in this project update_commentstring_and_run which can be used to run <Plug> mappings after updating the commentstring.

When it comes to caw.vim, both options are viable. Since it uses <Plug>, it should be quite simple to first disable the default mappings and then define your own mappings like the vim-commentary integration in this project:

nmap <buffer><expr> gc v:lua.context_commentstring.update_commentstring_and_run('caw:prefix')
nmap <buffer><expr> gcc v:lua.context_commentstring.update_commentstring_and_run('caw:hatpos:toggle')
nmap <buffer><expr> gci v:lua.context_commentstring.update_commentstring_and_run('caw:hatpos:comment')
nmap <buffer><expr> gcui v:lua.context_commentstring.update_commentstring_and_run('caw:hatpos:uncomment')
nmap <buffer><expr> gcI v:lua.context_commentstring.update_commentstring_and_run('caw:zeropos:comment')
nmap <buffer><expr> gcuI v:lua.context_commentstring.update_commentstring_and_run('caw:zeropos:uncomment')
nmap <buffer><expr> gca v:lua.context_commentstring.update_commentstring_and_run('caw:dollarpos:comment')
nmap <buffer><expr> gcua v:lua.context_commentstring.update_commentstring_and_run('caw:dollarpos:uncomment')
nmap <buffer><expr> gcw v:lua.context_commentstring.update_commentstring_and_run('caw:wrap:comment')
nmap <buffer><expr> gcuw v:lua.context_commentstring.update_commentstring_and_run('caw:wrap:uncomment')
nmap <buffer><expr> gcb v:lua.context_commentstring.update_commentstring_and_run('caw:box:comment')
nmap <buffer><expr> gco v:lua.context_commentstring.update_commentstring_and_run('caw:jump:comment-next')
nmap <buffer><expr> gcO v:lua.context_commentstring.update_commentstring_and_run('caw:jump:comment-prev')

I just copied the mappings from the docs and I'm not sure if that definition is 100% correct. Some nmaps might need to be omaps or xmaps, etc. Also, make sure to map them only in files where treesitter is active. I would test those mappings out and if they work well, we could add them to this plugin if you'd like.

The other option would be to ask caw.vim maintainers to add a possibility to configure a hook, like kommentary did. Since I don't know almost anything about caw.vim, I'm not sure if they would be open to this idea, you could ask them if you'd like :)

Anyways, let me know how it goes with these mappings or if there are any other questions!

@tyru
Copy link

tyru commented Jun 6, 2021

Hi @JoosepAlviste, I'm a caw.vim author.

I'd like to implement caw.vim integration but I don't know how to implement a hook function in caw.vim,
because current caw.vim has only vim script source codes.
I have to write a hook function by lua?

@tyru
Copy link

tyru commented Jun 6, 2021

run lua require('ts_context_commentstring.internal').update_commentstring() before the commentstring is used.

@JoosepAlviste I didn't understand well but now I understand above function changes commentstring option.
I'm working on tyru/caw.vim#165
Above PR calls the function before firing commenting / uncommenting.

@JoosepAlviste JoosepAlviste added the enhancement New feature or request label Nov 3, 2021
@JoosepAlviste
Copy link
Owner

Hey @tyru! How is the integration going on caw.vim side?

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

3 participants