-
Notifications
You must be signed in to change notification settings - Fork 395
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
Add imaps of the type <leader>xc -> \$command{c}. #1612
Conversation
Useful for commands such as mathbf, mathfrak, mathcal. For now, specify these like \ { 'lhs' : 'b', 'rhs' : 'vimtex#imaps#style("mathbf")', 'expr' : 1, 'leader' : '#'}, where 'expr' makes vimtex evaluate the rhs as an expression, and vimtex#imaps#style is a helper function.
This looks well done. I see one minor issue: Writing If you want to look into it, then I'll wait before I merge. Else I think it is probably not something people will notice and care about. That is, I'll gladly merge this as is, but I will first let you consider if it is possible to avoid the minor inconvenience. |
@@ -155,6 +155,9 @@ function! vimtex#imaps#wrap_environment(lhs, rhs) abort " {{{1 | |||
endfunction | |||
|
|||
function! vimtex#imaps#style(command) | |||
if !s:is_math() | |||
return '' | |||
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.
Yes, but: What if we wanted to use this for non math stuff? E.g. \emph{...}
?
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.
We could use another helper function, perhaps rename this one to vimtex#imaps#style_math
.
I guess ideally the wrapper should prevent the rhs from being called, but I think this requires passing in function handles, testing for this in every wrapper, and so on.
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 the simplest solution is to simply rename the function. I'll merge this now and just do that. Pragmatism is imporant to avoid over engineering.
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.
Good! However, the name of the function also needs to be changed in the pre-configured imaps. I'll push a commit with this change.
Thanks, I've merged this now. I made very minor modifications and generally appreciate that you've adapted so well to my style when adding this. Also, very good work, this seems like it could be useful. Btw: Perhaps we should also update the docs? |
I was trying to make a new imap macro for easily typing characters in It might be useful to have an example in the docs for neophytes like me that don't understand what they're doing: If you want to make it so typing call vimtex#imaps#add_map({
\ 'lhs' : 'r',
\ 'rhs' : 'vimtex#imaps#style_math("mathrm")',
\ 'expr' : 1,
\ 'leader' : '#',
\ 'wrapper' : 'vimtex#imaps#wrap_math'
\}) |
Thanks, I've pushed an update to the docs. |
Useful for commands such as mathbf, mathfrak, mathcal. For now, specify these like
\ { 'lhs' : 'b', 'rhs' : 'vimtex#imaps#style("mathbf")', 'expr' : 1, 'leader' : '#'},
where
'expr'
makes vimtex evaluate the rhs as an expression, andvimtex#imaps#style
is a helper function.Refactoring and generalization of #1611.