-
Notifications
You must be signed in to change notification settings - Fork 407
Vimtex API function that returns name of the enclosing environment, command or region #1981
Description
Is there a Vimtex API function that returns the name of enclosing environment, or command? So for a document like the following:
\documentclass[]{}
\usepackage[]{}
\begin{document}
\begin{helloworld}[]
\mycommandfour{}
\end{helloworld}
\mycommandthree{}
\mycommandseven{}
\end{document}
the returned names would be like: documentclass, when the cursor is in the [<optionlist>]{<argument>} part of \documentclass, and so on.
Also, in any region before \begin{document}, while outside a command or environment, the returned string would be preamble. And anywhere after \end{document} would be postamble.
Motivation: Such a function can then be used to set custom completion dictionary based on the name of environment/command. That way user can have a one dictionary per tex enviornment/command to know what key-values it can accept in the optional argument. Not the most robust, but good enough to do the job.
So for instance, if environment helloworld can take a comma separated list consisting ofkey=val, and if the valid keys are width=<width>, height=<height>, hitting some C-x C-<something> would bring up completion list that has the valid key names for helloworld environment.
PS! It would be users responsibility to maintain dictionary of valid key names for their environments/commands, and perhaps share it with world while releasing a latex package with instructions on how users can use this feature with Vim & Vimtex.