On 29.08.2011 23:35, Aditya Mahajan wrote:
On Tue, 30 Aug 2011, Andreas Schneider wrote:
I worked with t-vim a bit more and encountered a small problem with the way vim handles syntax definitions. Some of them have several modes that get activated by setting a variable first. For example the syntax "sh" (shell scripts) can be enhanced for bash, ksh, etc.
Example: let g:is_bash=1 set syntax=sh
Now a line like "export foo=bar" is highlighted differently than when I would omit the "let g:is_bash=1".
Therefore I would propose another options to \setupvimtyping to specify custom options to be passed to vim. Preferably they should be passed at least before the "set syntax=..." line to make sure that this particular case -- i.e. switching syntax modes -- works well (which may be the only necessary case).
That is certainly possible, but the exact solution depends on how robust you want it to be. I can easily add an option so that
\definevimtyping [....] [extras={let g:is_bash=1}]
will pass the argument to vim. However, string arguments like
\definevimtyping [....] [extras={let g:name="Whatever"}]
will not work. The reason is that, t-vim first creates a command line argument that is passed to mtxrun. mtxrun parses the entire expression, including all the options, When mtxrun figures out that all the arguments were meant for an external program, it recreates the list of arguments (to the best of its abilities), and passes the arguments to the shell. Then the shell tries to interpret the quotes. I haven't been able to find a solution that will work correctly though these three transformations.
Another option is to write everything to an external file and source it as a vimrc file. So, you could do:
\definevimtyping [...] [vimrc=shell]
\startvimrc[shell] let g:is_bash = 1 \stopvimrc
This requires more coding, but is much more flexible than the first option.
Do all syntax highlighting options work with 0/1 parameters? If so, then the first alternative is easiest.
As far as I can see, most of the relevant options (if not all) are 0/1 switches, so the first alternative should be enough. Thanks to the pipe syntax of vim's command mode, it might be even possible specify more parameters that way. [extras={let g:foo=bar | let g:shaz=bot}] -- at least vim accepts that usually, I guess it doesn't make a difference if specified as commandline parameter. However I also like the idea of the optional vimrc via buffer. I think it might be a nice-to-have feature for the ToDo list :-) Thank you for the analysis and for coming up with these possible implementations! -- Best Regards, Andreas