diff options
author | Karl Berry <karl@freefriends.org> | 2011-03-08 00:14:59 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2011-03-08 00:14:59 +0000 |
commit | 53fe6f6193f41db0351601461be11b02ef899e19 (patch) | |
tree | ba4e87a10d7a3c10678a274035fd7a151e250ea4 /Master/texmf-dist/tex | |
parent | 5437158c22fe88be543299dd6b84463d75659887 (diff) |
context-vim (7mar11)
git-svn-id: svn://tug.org/texlive/trunk@21637 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/context/third/vim/t-vim.tex | 252 |
1 files changed, 191 insertions, 61 deletions
diff --git a/Master/texmf-dist/tex/context/third/vim/t-vim.tex b/Master/texmf-dist/tex/context/third/vim/t-vim.tex index 03cf65502d4..59daac5d5da 100644 --- a/Master/texmf-dist/tex/context/third/vim/t-vim.tex +++ b/Master/texmf-dist/tex/context/third/vim/t-vim.tex @@ -1,6 +1,6 @@ %D \module %D [ file=t-vim, -%D version=2011.02.21, +%D version=2011.03.06, %D title=\CONTEXT\ User Module, %D subtitle=Vim syntax highlighting, %D author=Aditya Mahajan, @@ -12,52 +12,120 @@ \writestatus{loading}{ConTeXt User Module / Vim syntax highlighting} \startmodule[vim] - -\unprotect - \usemodule[filter] -% We specify colors in hex so -\setupcolor[hex] +% I use the experimental namespaces defined in t-filter. +\pushcatcodetable +\setcatcodetable\externalfiltermodulecatcodes + +% Colors are specified in hex; in MkII the hex mode needs to be activated. +\doifmode\s!mkii + {\setupcolor[hex]} \startinterface all - \setinterfaceconstant {syntax} {syntax} + \setinterfaceconstant {syntax} {syntax} \stopinterface -\def\????vimtyping{@@@@vimtyping} +\def\vimtyping::id {vimtyping} +\def\vimtyping::namespace {@@@@\vimtyping::id} +\def\vimtyping::name {} + +\def\vimalternative::id {vimalternative} +\def\vimalternative::namespace {@@@@\vimalternative::id} +\def\vimalternative::name {} + +\installparameterhandler \vimtyping::namespace \vimtyping::id +\installsetuphandler \vimtyping::namespace \vimtyping::id -\installparameterhandler \????vimtyping {vimtyping} -\installsetuphandler \????vimtyping {vimtyping} + \def\definevimtyping - {\dodoubleargument\dodefinevimtyping} - -\def\dodefinevimtyping[#1][#2]% - {\getparameters[\????vimtyping#1][\s!parent=\????vimtyping,#2]% - \edef\currentvimtyping{#1}% - \defineexternalfilter[#1][\s!parent=\????vimtyping#1]% - \setvalue{type#1file}{\dodoubleargument\doprocessexternalfilterfile[#1]}% - } - -\startsetups[vimsetup] - \edef\currentvimtyping{\currentexternalfilter}% - \edef\currentvimalternative{\externalfilterparameter\c!alternative}% + {\dodoubleargument\vimtyping::define} + +\starttexdefinition vimtyping::define [#1][#2] + \getparameters[\vimtyping::namespace#1][\s!parent=\vimtyping::namespace,#2] + + \edef\vimtyping::name{#1} + \doifmode\s!mkiv{\setups{vimtyping::setup_line_number_mkiv}} + + \defineexternalfilter[#1][\s!parent=\vimtyping::namespace#1] + \setvalue{type#1file}{\getvalue{process#1file}} + +\stoptexdefinition + +\startsetups vimtyping::setup + + \edef\vimtyping::name{\currentexternalfilter} + \edef\vimalternative::name{\externalfilterparameter\c!alternative} + \let\SYN\vimsyntax - \def\NL{\strut}% TODO: Add line numbering + \def\NL{\strut}% + \def\tab##1% - {\dorecurse{\externalfilterparameter\c!tab} - {\space}}% + {\dorecurse{##1}{\space}}% + + \doifmode\s!mkii{\setups{vimtyping::setup_line_number_mkii}}% + \doifinset{\externalfilterparameter\c!option}{\v!packed} - {\setupwhitespace[\v!none,\v!flexible]}% - \setcatcodetable\externalfilterwritecatcodes + {\setupwhitespace[\v!none,\v!flexible]}% + + \setcatcodetable\externalfilter::write_catcodes +\stopsetups + +\startsetups vimtyping::setup_line_number_mkiv + \definelinenumbering [#1] + + \setuplinenumbering + [\vimtyping::name] + [\c!conversion=\externalfilterparameter\c!numberconversion, + \c!start=\externalfilterparameter{\c!number\c!start}, + \c!step=\externalfilterparameter{\c!number\c!step}, + \c!method=\externalfilterparameter{\c!number\c!method}, + \c!location=\externalfilterparameter{\c!number\c!location}, + \c!style=\externalfilterparameter\c!numberstyle, + \c!color=\externalfilterparameter\c!numbercolor, + \c!width=\externalfilterparameter{\c!number\c!width}, + \c!left=\externalfilterparameter{\c!number\c!left}, + \c!right=\externalfilterparameter{\c!number\c!right}, + \c!command=\externalfilterparameter\c!numbercommand, + \c!distance=\externalfilterparameter{\c!number\c!distance}, + \c!align=\externalfilterparameter{\c!number\c!align}, + ] \stopsetups +\doifmode\s!mkii + {\newcount\vimtyping::linenumber} + +\startsetups vimtyping::setup_line_number_mkii +\doif{\externalfilterparameter\c!numbering}\v!yes + {% setuplinenumbering resets \linenumber. So we save the value of linenumber and + % revert it back. + \vimtyping::linenumber=\linenumber + + \setuplinenumbering + [\c!conversion=\externalfilterparameter\c!numberconversion, + \c!start=\externalfilterparameter{\c!number\c!start}, + \c!step=\externalfilterparameter{\c!number\c!step}, + \c!method=\externalfilterparameter{\c!number\c!method}, + \c!location=\externalfilterparameter{\c!number\c!location}, + \c!style=\externalfilterparameter\c!numberstyle, + \c!color=\externalfilterparameter\c!numbercolor, + \c!width=\externalfilterparameter{\c!number\c!width}, + \c!left=\externalfilterparameter{\c!number\c!left}, + \c!right=\externalfilterparameter{\c!number\c!right}, + \c!command=\externalfilterparameter\c!numbercommand, + \c!distance=\externalfilterparameter{\c!number\c!distance}, + \c!align=\externalfilterparameter{\c!number\c!align}, + ] + + \linenumber=\vimtyping::linenumber} +\stopsetups \doifmodeelse{vimtest} - {\def\vimconversionfile{2context.vim}} - {\def\vimconversionfile{kpse:2context.vim}} + {\def\vimtyping::script_name{2context.vim}} + {\def\vimtyping::script_name{kpse:2context.vim}} -\def\vimfiltercommand +\def\vimtyping::filter_command {vim -u NONE % don't read global config file -e % run in ex mode -s % silent @@ -68,42 +136,86 @@ -c "set syntax=\externalfilterparameter\c!syntax" % -c "let contextstartline=\externalfilterparameter\c!start" % -c "let contextstopline=\externalfilterparameter\c!stop" % - -c "source \vimconversionfile" % + -c "source \vimtyping::script_name" % -c "qa" % \externalfilterinputfile\space \externalfilteroutputfile} +\startmode [\s!mkiv] +\starttexdefinition vimtyping::read_command #1 + \doifelse{\externalfilterparameter\c!numbering}\v!yes + {\startlinenumbering + [\vimtyping::name] + [\c!continue=\externalfilterparameter{\c!number\c!continue}] + \ReadFile{#1} + \stoplinenumbering} + {\ReadFile{#1}} +\stoptexdefinition +\stopmode + +\startmode [\s!mkii] +\starttexdefinition vimtyping::read_command #1 + \doifelse{\externalfilterparameter\c!numbering}\v!yes + {\doifelse{\externalfilterparameter{\c!number\c!continue}}\v!yes + {\startlinenumbering[\v!continue]} + {\startlinenumbering} + \ReadFile{#1} + \stoplinenumbering} + {\ReadFile{#1}} +\stoptexdefinition +\stopmode + \def\startvimalternative - {\dosingleargument\dostartvimalternative} + {\dosingleargument\vimalternative::start} -\def\dostartvimalternative[#1]% - {\pushmacro\currentvimalternative - \edef\currentvimalternative{#1}} +\def\vimalternative::start[#1]% + {\pushmacro\vimalternative::name + \edef\vimalternative::name{#1}} \def\stopvimalternative - {\popmacro\currentvimalternative} + {\popmacro\vimalternative::name} \def\setvimsyntax - {\doquadrupleargument\dosetvimsyntax} - -\def\dosetvimsyntax[#1][#2][#3][#4]% name color style command - {\def\dodosetupvimsyntax##1% - { \doifsomething{#2} - {\definecolor[\????vimtyping:\currentvimalternative:##1:color] [#2]% - \getparameters[\????vimtyping::\currentvimalternative::##1] - [\c!color={\????vimtyping:\currentvimalternative:##1:color}]} - \getparameters[\????vimtyping::\currentvimalternative::##1] - [\c!style=#3, - \c!command=#4]}% - \processcommalist[#1]\dodosetupvimsyntax} - - -\def\vimsyntax[#1]#2% style content - {\dostartattributes{\????vimtyping::\currentvimalternative::Normal}\c!style\c!color\empty% - \dostartattributes{\????vimtyping::\currentvimalternative::#1}\c!style\c!color\empty% - \getvalue{\????vimtyping::\currentvimalternative::#1\c!command}{#2}% - \dostopattributes - \dostopattributes} + {\doquadrupleargument\vimalternative::set_syntax} + +\starttexdefinition vimalternative::set_syntax [#1][#2][#3][#4] + % #1 = name + % #2 = color + % #3 = style + % #4 = command + \def\dodosetupvimsyntax##1% + {\doifsomething{#2} + % we check if color exists; otherwise ConTeXt gives a warning on stdout + % which is very distracting + {\definecolor[\vimalternative::namespace\vimalternative::name##1color_name] [#2] + \getparameters[\vimalternative::namespace\vimalternative::name##1] + [\c!color={\vimalternative::namespace\vimalternative::name##1color_name}]} + \getparameters[\vimalternative::namespace\vimalternative::name##1] + [\c!style=#3, + \c!command=#4]} + \processcommalist[#1]\dodosetupvimsyntax +\stoptexdefinition + + +\starttexdefinition vimsyntax [#1]#2 + % #1 = style + % #2 = content + \dostartattributes{\vimalternative::namespace\vimalternative::name Normal}\c!style\c!color\empty + \dostartattributes{\vimalternative::namespace\vimalternative::name #1}\c!style\c!color\empty + \getvalue{\vimalternative::namespace\vimalternative::name#1\c!command}{#2} + \dostopattributes + \dostopattributes +\stoptexdefinition + +% \startvimalternative[pscolor] +% +% \definesyntax +% [Normal] +% [color=\externalfilterparameter\c!color, +% style=\tttf, +% command=] +% +% \stopvimalternative \startvimalternative[pscolor] \setvimsyntax [Normal] [\externalfilterparameter\c!color][\tttf] @@ -194,17 +306,35 @@ \c!alternative=pscolor, \c!before=, \c!after=, - \c!filtercommand=\vimfiltercommand, + \c!filtercommand=\vimtyping::filter_command, \c!continue=yes, \c!read=\v!yes, - \c!readcommand=\ReadFile, + \c!readcommand=\vimtyping::read_command, \c!output=\externalfilterbasefile.vimout, - \c!setups=vimsetup, + \c!setups=vimtyping::setup, \c!option=\v!packed, % Could be a list - \s!parent=\????externalfilter, + \s!parent=\externalfilter::namespace, + % Numbering options + \c!numbering=\v!no, + \c!number\c!start=1, + \c!number\c!step=1, + \c!number\c!continue=\v!no, + \c!numberconversion=\v!numbers, + \c!number\c!method=\v!first, + \c!number\c!location=\v!left, + \c!numberstyle=\tfx, + \c!numbercolor=, + \c!number\c!width=2em, + \c!number\c!left=, + \c!number\c!right=, + \c!number\c!command=, + \c!number\c!distance=0.5em, + \c!number\c!align=\v!flushright, ] -\protect +\def\currentvimtyping {\vimtyping::name} + +\popcatcodetable \stopmodule |