diff options
author | Karl Berry <karl@freefriends.org> | 2011-08-12 23:14:03 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2011-08-12 23:14:03 +0000 |
commit | 3affad3394ee81c3f5ba136242d5d56949254515 (patch) | |
tree | a0a6e75f758b5c846182e833f658014df28cba23 /Master/texmf-dist | |
parent | c74165f3bdbaaefef4e594d6dbc2ad7b13292bbb (diff) |
context-vim (11aug11)
git-svn-id: svn://tug.org/texlive/trunk@23523 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
4 files changed, 219 insertions, 19 deletions
diff --git a/Master/texmf-dist/doc/context/third/vim/vim.txt b/Master/texmf-dist/doc/context/third/vim/vim.txt index 153398011ce..ed6c0e3feae 100644 --- a/Master/texmf-dist/doc/context/third/vim/vim.txt +++ b/Master/texmf-dist/doc/context/third/vim/vim.txt @@ -31,10 +31,10 @@ Both colors and no ligatures work out of the box in MkIV. Installation ------------ -This module depends on the `t-filter` module. If you are using ConTeXt minimals, -you can install the module using +This module depends on the `t-filter` module. If you are using ConTeXt +standalone, you can install the module using - first-setup.sh --extras="t-filter,t-vim" + first-setup.sh --modules="t-filter,t-vim" Depending on your TeX distribution, you may already have the module. To verify, check if @@ -287,10 +287,66 @@ By default, the space is invisible. If you want to make the space visible, set The default value is `space=off`. -Splitting lines +Removing leading spaces +----------------------- + +If you are listing a code snippet inside another environment, it is common to +indent the TeX code. For example: + + \definevimtyping[C][syntax=C] + \definevimtyping[ruby][syntax=ruby] + + \startitemize + \item A hello world example in C + \startC + #include<stdio.h> + + int main() + { + printf("Hello World") + } + \stopC + \item A hello world example in ruby + \startruby + puts "Hello World" + \stopruby + \stopitemize + +Although, the source code is easy to read, the output will not be. This is +because, unlike regular TeX, `\start<vimtyping>` ... `\stop<vimtyping>` +environment does not ignore whote space. So, the output is the same as + + \startitemize + \item A hello world example in C + \startC + #include<stdio.h> + + int main() + { + printf("Hello World") + } + \stopC + \item A hello world example in ruby + \startruby + puts "Hello World" + \stopruby + \stopitemize + +So, all the code snippets are indented by nine space. To avoid this behavior, +set + + \definevimtyping + [...] + [... + strip=yes, + ...] + +The default value of `strip` is `no`. + +Wrapping lines --------------- -By default, long lines are not split. If you want to split long lines, set +By default, long lines are not wrapped. If you want to wrap long lines, set \definevimtyping [...] @@ -300,6 +356,77 @@ By default, long lines are not split. If you want to split long lines, set The default value is `lines=fixed`. +Highlighting lines +------------------ + +Sometimes you want to draw attention to a particular line (or set of lines). One +way to do so it to highlight the lines by a background color. This can be done +using: + + \start<vimtyping>[highlight={<list>}] + ... + \stop<vimtyping> + +where `<list>` is a comma separated list. For example, if you want to highlight +lines 1 and 5, you may use: + + \start<vimtyping>[highlight={1,5}] + ... + \stop<vimtyping> + +This will highlight lines 1 and 5 with gray background color. To change the +highlight color use + + \definevimtyping + [...] + [... + highlightcolor=<color>, + ...] + +where `<color>` is any valid ConTeXt color. + +**Note**: Currently, if you use `highlight` with `numbering=on`, each +highlighted line will be numbered thrice (with the numbers overprinted on one +another). This is because, internally, highlighting is implemented using text +backgrounds and they do not work with line numbering. + +Messages and Tracing +-------------------- + +The vim module uses the filter module in the background. The filter module +outputs some diagnostic information on the console output to indicate what is +happening. For example, for each code snippet, you will see messages like + + t-filter > command : vim -u NONE -e -s -C -n -c "set tabstop=4" -c "syntax on" -c "set syntax=scala" -c "let contextstartline=1" -c "let contextstopline=0" -c "source kpse:2context.vim" -c "qa" scala-temp-SCALA-0.tmp scala-temp-SCALA-0.vimout + +If, for some reason, the output file is not generated, or not found, a message +similar to + + t-filter > file matlab-temp-MATLAB-0.vimout cannot be found + t-filter > current filter : MATLAB + t-filter > base file : matlab-temp-MATLAB-0 + t-filter > input file : matlab-temp-MATLAB-0.tmp + t-filter > output file : matlab-temp-MATLAB-0.vimout + +is displayed in the console. At the same time, the string + + [[output file missing]] + +is displayed in the PDF output. This data, along with the filter command, is +useful for debugging what whenwrong. + +Yes, on, whatever +----------------- + +ConTeXt has two ways of indicating binary options: + +- `option=yes` and `option=no` +- `option=on` and `option=off` + +The core commands freely switch between the two. In some cases, `option=yes` has +a different meaning than `option=on`. To avoid confusion, I have made these +synonyms. Thus, whenever the documentation says `option=yes`, you may use +`option=on`. One less thing to worry about! A bit of a history ------------------ @@ -329,3 +456,8 @@ in the module, except a few minor bug fixes. Around June 2010, I decided to completely rewrite the module from scratch. The new version of `t-vim` relies on `t-filter` for all the bookkeeping. As a result, the module is smaller and more robust. + +TODO +---- + +- Fix line highlighting with highlight={list} diff --git a/Master/texmf-dist/tex/context/third/vim/2context.vim b/Master/texmf-dist/tex/context/third/vim/2context.vim index 0e29c46c5bf..ad41dc5c375 100644 --- a/Master/texmf-dist/tex/context/third/vim/2context.vim +++ b/Master/texmf-dist/tex/context/third/vim/2context.vim @@ -19,24 +19,41 @@ wincmd p " If contextstartline and contextstartline are set, use them. if exists("contextstartline") - let s:lnum = max([1, min([line("$"), contextstartline]) ]) + let s:lstart = max([1, min([line("$"), contextstartline]) ]) else - let s:lnum = 1 + let s:lstart = 1 endif if exists("contextstopline") if contextstopline <= 0 let contextstopline = line("$") + contextstopline endif - let s:end = min([line("$"), max([s:lnum, contextstopline]) ]) + let s:lstop = min([line("$"), max([s:lstart, contextstopline]) ]) else - let s:end = line("$") + let s:lstop = line("$") endif -let s:buffer_lnum = 1 +let s:strip = strlen( matchstr( getline(s:lstart), '^\s*' ) ) + +" Find the smallest leading white space +if exists("strip") && strip && (s:strip != 0) + echo "In the loop" + for s:lnum in range(s:lstart, s:lstop) + let s:line = getline(s:lnum) + let s:space = matchstr(s:line, '^\s*') + let s:len = strlen(s:space) + echo s:len + let s:strip = min(s:strip, s:len) + endfor +else + let s:strip = 0 +endif " Loop over all lines in the original text. -while s:lnum <= s:end +let s:buffer_lnum = 1 +let s:lnum = s:lstart + +while s:lnum <= s:lstop " Get the current line let s:line = getline(s:lnum) let s:len = strlen(s:line) @@ -90,6 +107,14 @@ while s:lnum <= s:end let s:idx = stridx(strpart(s:line, s:start), "\t") endwhile +" Remove leading whitespace + let s:new = substitute(s:new, '^\s\{' . s:strip . '\}', "", "") + +" Highlight line, if needed. + if (index(highlight, s:lnum) != -1) + let s:new = '\HGL{' . s:new . '}' + endif + " Go back and paste the current line wincmd p call append (s:buffer_lnum-1, s:new) diff --git a/Master/texmf-dist/tex/context/third/vim/t-syntax-highlight.tex b/Master/texmf-dist/tex/context/third/vim/t-syntax-highlight.tex index 35f24c656d7..bd2d75cebf8 100644 --- a/Master/texmf-dist/tex/context/third/vim/t-syntax-highlight.tex +++ b/Master/texmf-dist/tex/context/third/vim/t-syntax-highlight.tex @@ -1,6 +1,6 @@ %D \module %D [ file=t-syntax-highlight, -%D version=2011.06.14, +%D version=2011.08.10, %D title=\CONTEXT\ User Module, %D subtitle=Code syntax highlighting, %D author=Aditya Mahajan, @@ -20,6 +20,8 @@ \startinterface all \setinterfaceconstant {syntax} {syntax} + \setinterfaceconstant {highlight} {highlight} + \setinterfaceconstant {highlightcolor} {highlightcolor} \stopinterface %D Name space @@ -31,6 +33,10 @@ \installparameterhandler \syntaxhighlighting::namespace \syntaxhighlighting::id \installsetuphandler \syntaxhighlighting::namespace \syntaxhighlighting::id +%D Helper macro + +\def\syntaxhighlighting::yes{\v!yes,\v!on} + \def\definesyntaxhighlighting {\dodoubleargument\syntaxhighlighting::define} @@ -51,6 +57,7 @@ \edef\colorscheme::name{\externalfilterparameter\c!alternative} \let\SYN\syntaxgroup + \let\HGL\syntaxhighlightline \let\\\textbackslash \let\{\textbraceleft \let\}\textbraceright @@ -92,7 +99,7 @@ {\newcount\syntaxhighlighting::linenumber} \startsetups syntaxhighlighting::setup_line_number_mkii -\doif{\externalfilterparameter\c!numbering}\v!yes +\doifinset{\externalfilterparameter\c!numbering}\syntaxhighlighting::yes {% setuplinenumbering resets \linenumber. So we save the value of linenumber and % revert it back. \syntaxhighlighting::linenumber=\linenumber @@ -118,7 +125,7 @@ \startmode [\s!mkiv] \starttexdefinition syntaxhighlighting::read_command #1 - \doifelse{\externalfilterparameter\c!numbering}\v!yes + \doifinsetelse{\externalfilterparameter\c!numbering}\syntaxhighlighting::yes {\startlinenumbering [\syntaxhighlighting::name] [\c!continue=\externalfilterparameter{\c!number\c!continue}] @@ -130,8 +137,8 @@ \startmode [\s!mkii] \starttexdefinition syntaxhighlighting::read_command #1 - \doifelse{\externalfilterparameter\c!numbering}\v!yes - {\doifelse{\externalfilterparameter{\c!number\c!continue}}\v!yes + \doifinsetelse{\externalfilterparameter\c!numbering}\syntaxhighlighting::yes + {\doifinsetelse{\externalfilterparameter{\c!number\c!continue}}\syntaxhighlighting::yes {\startlinenumbering[\v!continue]} {\startlinenumbering} \syntaxhighlighting::read_command_aux{#1} @@ -224,6 +231,30 @@ \installspacehandler {\syntaxhighlighting::namespace} {\activatespacehandler {\syntaxhighlighting::namespace\v!off}} +% Line highlighting +% For MkIV, we can use the new bar mechanism to highlight a line. +% For consistency, we use text background, which is slower but works for both +% MkII and MkIV. + +% \startmode[*mkiv] +% \definebar[syntaxhighlightline] +% [\c!order=\v!background, +% \c!rulethickness=2.5, +% \c!offset=1.25, +% \c!continue=\v!yes, +% \c!color=\externalfilterparameter\c!highlightcolor, +% ] +% \stopmode + +\definetextbackground[syntaxhighlightline] + [\c!location=\v!paragraph, + \c!alternative=0, + \c!frame=\v!off, + \c!background=\v!color, + \c!backgroundcolor=\externalfilterparameter\c!highlightcolor, + ] + + \protectmodulecatcodes \stopmodule 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 f2713a0af1b..372219324dd 100644 --- a/Master/texmf-dist/tex/context/third/vim/t-vim.tex +++ b/Master/texmf-dist/tex/context/third/vim/t-vim.tex @@ -1,12 +1,12 @@ %D \module %D [ file=t-vim, -%D version=2011.06.14, +%D version=2011.08.10, %D title=\CONTEXT\ User Module, %D subtitle=Vim syntax highlighting, %D author=Aditya Mahajan, %D date=\currentdate, %D copyright=Aditya Mahajan, -%D email=adityam <at> umich <dot> edu, +%D email=adityam <at> ieee <dot> org, %D license=Simplified BSD License] \writestatus{loading}{ConTeXt User Module / Vim syntax highlighting} @@ -38,7 +38,7 @@ \stoptexdefinition % Mode to testing the dev version of 2context script. -\doifmodeelse{vimtest} +\doifmodeelse{vim-dev} {\def\vimtyping::script_name{2context.vim}} {\def\vimtyping::script_name{kpse:2context.vim}} @@ -53,11 +53,20 @@ -c "set syntax=\externalfilterparameter\c!syntax" % -c "let contextstartline=\externalfilterparameter\c!start" % -c "let contextstopline=\externalfilterparameter\c!stop" % + -c "let strip=\getvalue{\vimtyping::id-\c!strip-\externalfilterparameter\c!strip}" % + -c "let highlight=[\externalfilterparameter\c!highlight]" % -c "source \vimtyping::script_name" % -c "qa" % \externalfilterinputfile\space \externalfilteroutputfile} +\setvalue{\vimtyping::id-\c!strip-\v!off}{0} +\setvalue{\vimtyping::id-\c!strip-\v!on}{1} + +% Undocumented ... but useful if the user makes a mistake +\setvalue{\vimtyping::id-\c!strip-\v!no}{0} +\setvalue{\vimtyping::id-\c!strip-\v!yes}{1} + \setupvimtyping [% \c!tab=4, % \c!start=1, @@ -68,6 +77,9 @@ % \c!after=, % \c!style=\tttf, % \c!color=, + \c!strip=\v!off, + \c!highlight=, + \c!highlightcolor=lightgray, \c!filtercommand=\vimtyping::filter_command, % \c!continue=yes, % \c!read=\v!yes, |