-
Notifications
You must be signed in to change notification settings - Fork 114
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
Use vim's builtin format mapping #121
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like providing a simple hook for people who want to override formatexpr and an example of how. It would be pretty aggressive behavior to unconditionally override formatexpr, though. Could be based on a setting, but for things like this it's usually more flexible and less brittle to provide the pieces and let the user hook it up themselves. For instance, if they wanted to override formatexpr for some but not all filetypes, they'd come asking how to adapt this to do what they wanted and we wouldn't have a simple clean way to offer them.
What do you think about changing it so the autocmd is in your vimrc and just calls a simple codefmt helper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it needs to be opt-in. See my previous longer comment in Conversation.
Removed autocmd from mappings file, PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG to merge besides getting the functions into the generated help docs. LMK if you need any help with that part.
if !empty(get(b:, 'codefmt_formatter')) | ||
let l:Predicate = {f -> f.name ==# b:codefmt_formatter} | ||
else | ||
let l:Predicate = {f -> f.AppliesToBuffer() && s:IsAvailable(f)} | ||
endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference: We haven't been using lambdas in any of our plugins yet, but I checked and they were originally added in 7.4.2044 from 2016. That's probably long enough ago. At some point I should probably declare a min supported vim version for the plugin and get it testing against that version, though.
@@ -252,6 +262,23 @@ function! codefmt#GetSupportedFormatters(ArgLead, CmdLine, CursorPos) abort | |||
return join(l:groups[0] + l:groups[1] + l:groups[2], "\n") | |||
endfunction | |||
|
|||
"" | |||
" Returns whether there is a default formatter available for the current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make this @public
and regenerate the vimdoc?
It should have a sample of how to use it somewhere in the help docs, but for that part I'm happy to merge it w/o and add the docs after.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (two years later :)
Signed-off-by: Ari Archer <[email protected]>
Thanks!
Looks like the autocmd is still in the mappings file? I'd suggest to instead restructure a bit to define a augroup codefmt_formatexpr
autocmd!
autocmd BufEnter * call codefmt#SetFormatExprIfAvailable()
augroup END |
No description provided.