Add imaps of the type <leader>xc -> \$command{c}.#1612
Add imaps of the type <leader>xc -> \$command{c}.#1612rsekman wants to merge 3 commits intolervag:masterfrom rsekman:style_imaps
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. |
| function! vimtex#imaps#style(command) | ||
| if !s:is_math() | ||
| return '' | ||
| endif |
There was a problem hiding this comment.
Yes, but: What if we wanted to use this for non math stuff? E.g. \emph{...}?
There was a problem hiding this comment.
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.
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.
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#styleis a helper function.Refactoring and generalization of #1611.