summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/third/vim
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2012-01-27 00:09:30 +0000
committerKarl Berry <karl@freefriends.org>2012-01-27 00:09:30 +0000
commit9b57eb36b0d85c4e42cd2c3d135667f804d6465f (patch)
tree23f57336e813fc3c3ebcc40a9e1c98a5407606e3 /Master/texmf-dist/tex/context/third/vim
parent601875160463d0325b0105f8a9f2208b871389b2 (diff)
context-vim (26jan12)
git-svn-id: svn://tug.org/texlive/trunk@25207 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/third/vim')
-rw-r--r--Master/texmf-dist/tex/context/third/vim/2context.vim150
-rw-r--r--Master/texmf-dist/tex/context/third/vim/t-syntax-highlight.mkiv111
-rw-r--r--Master/texmf-dist/tex/context/third/vim/t-vim.tex9
3 files changed, 208 insertions, 62 deletions
diff --git a/Master/texmf-dist/tex/context/third/vim/2context.vim b/Master/texmf-dist/tex/context/third/vim/2context.vim
new file mode 100644
index 00000000000..dfdaa8439c4
--- /dev/null
+++ b/Master/texmf-dist/tex/context/third/vim/2context.vim
@@ -0,0 +1,150 @@
+" Author : Aditya Mahajan <adityam [at] umich [dot] edu>
+" version : 2011.12.23
+" license : Simplified BSD License
+
+" This script is part of the t-vim module for ConTeXt. It is based on 2html.vim.
+" Since this script is called by the t-vim module, we assume that Two buffers
+" are open. The first buffer is the input buffer, and the second buffer is the
+" output buffer. The script parses content line-by-line from the first buffer
+" and pastes the modified result on the second buffer.
+
+" Split screen and go to the second buffer, ensure modifiable is set, and the
+" buffer is empty.
+sblast
+set modifiable
+%d
+
+" Go to first buffer
+wincmd p
+
+" If contextstartline and contextstartline are set, use them.
+if exists("contextstartline")
+ let s:lstart = max([1, min([line("$"), contextstartline]) ])
+else
+ let s:lstart = 1
+endif
+
+if exists("contextstopline")
+ if contextstopline <= 0
+ let contextstopline = line("$") + contextstopline
+ endif
+ let s:lstop = min([line("$"), max([s:lstart, contextstopline]) ])
+else
+ let s:lstop = line("$")
+endif
+
+" Set highlight
+if !exists("highlight")
+ let highlight=[]
+endif
+
+" Set escapecomments
+if !exists("escapecomments")
+ let escapecomments=0
+endif
+
+let s:strip = strlen( matchstr( getline(s:lstart), '^\s*' ) )
+
+" Find the smallest leading white space
+if exists("strip") && strip && (s:strip != 0)
+ echo "Calculating amount of leading whitespace"
+ for s:lnum in range(s:lstart, s:lstop)
+ let s:line = getline(s:lnum)
+ if (match(s:line, '^\s*$')) == -1 " line is not empty
+ let s:space = matchstr(s:line, '^\s*')
+ let s:len = strlen(s:space)
+ " echo s:len
+ let s:strip = min([s:strip, s:len])
+ if s:strip == 0
+ break
+ end
+ end
+ endfor
+ " echo "Strip amount:" . s:strip
+else
+ let s:strip = 0
+endif
+
+" Loop over all lines in the original text.
+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)
+ let s:new = ''
+
+" Loop over each character in the line
+ let s:col = s:strip + 1
+ while s:col <= s:len
+ let s:startcol = s:col " The start column for processing text
+ let s:id = synID (s:lnum, s:col, 1)
+ let s:col = s:col + 1
+" Speed loop (it's small - that's the trick)
+" Go along till we find a change in synID
+ while s:col <= s:len && s:id == synID(s:lnum, s:col, 1)
+ let s:col = s:col + 1
+ endwhile
+
+" Output the text with the same synID, with class set to {s:id_name}
+ let s:id = synIDtrans (s:id)
+ let s:id_name = synIDattr (s:id, "name", "gui")
+ let s:temp = strpart(s:line, s:startcol - 1, s:col - s:startcol)
+" Remove line endings (on unix machines reading windows files)
+ let s:temp = substitute(s:temp, '\r*$', '', '')
+" It might have happened that that one has been the last item in a row, so
+" we don't need to print in in that case
+ if strlen(s:temp) > 0
+" Change special TeX characters to escape sequences.
+ if !(escapecomments && s:id_name == "Comment")
+ let s:temp = escape( s:temp, '\{}')
+ endif
+ if !empty(s:id_name)
+ let s:temp = '\SYN[' . s:id_name . ']{' . s:temp . '}'
+ endif
+ let s:new = s:new . s:temp
+ endif
+
+" Why will we ever enter this loop
+" if s:col > s:len
+" break
+" endif
+ endwhile
+
+" Expand tabs
+ let s:pad = 0
+ let s:start = 0
+ let s:idx = stridx(s:line, "\t")
+ while s:idx >= 0
+ let s:i = &ts - ((s:start + s:pad + s:idx) % &ts)
+" let s:new = substitute(s:new, '\t', strpart(s:expandedtab, 0, s:i), '')
+ let s:new = substitute(s:new, '\t', '\\tab{' . s:i . '}', '')
+ let s:pad = s:pad + s:i - 1
+ let s:start = s:start + s:idx + 1
+ 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)
+ wincmd p
+
+" Increment line numbers
+ let s:lnum = s:lnum + 1
+ let s:buffer_lnum = s:buffer_lnum + 1
+endwhile
+
+wincmd p
+" We have a spurious line in the end. So we remove it.
+$delete
+" Write the file
+write
diff --git a/Master/texmf-dist/tex/context/third/vim/t-syntax-highlight.mkiv b/Master/texmf-dist/tex/context/third/vim/t-syntax-highlight.mkiv
index 776f7f32ff0..8dbeb20236b 100644
--- a/Master/texmf-dist/tex/context/third/vim/t-syntax-highlight.mkiv
+++ b/Master/texmf-dist/tex/context/third/vim/t-syntax-highlight.mkiv
@@ -15,7 +15,7 @@
\usemodule [syntax-groups]
\usemodule [filter] % loads module-catcodes
-\unprotectmodulecatcodes
+\unprotect
\startinterface all
\setinterfaceconstant {syntax} {syntax}
@@ -25,37 +25,32 @@
%D Name space
-\def\syntaxhighlighting@id {syntaxhighlighting}
-\def\syntaxhighlighting@namespace {@@@@\syntaxhighlighting@id}
-\def\syntaxhighlighting@name {}
-
-\edef\t!syntaxhighlighting {\syntaxhighlighting@id}
-
-\installparameterhandler \syntaxhighlighting@namespace \syntaxhighlighting@id
-\installsetuphandler \syntaxhighlighting@namespace \syntaxhighlighting@id
+\definenamespace
+ [syntaxhighlighting]
+ [\c!type=module,
+ \c!name=syntaxhighlighting,
+ \c!command=\v!yes,
+ setup=\v!list,
+ \c!style=\v!no,
+ \s!parent=syntaxhighlighting]
+
+\appendtoks
+ \defineexternalfilter[\currentsyntaxhighlighting]
+ [\s!parent=\????syntaxhighlighting\currentexternalfilter,\c!taglabel=\vimtyping@id]%
+ \definelinenumbering [\currentsyntaxhighlighting]%
+ \setevalue{type\currentsyntaxhighlighting file}{\getvalue{process\currentsyntaxhighlighting file}}%
+\to\everydefinesyntaxhighlighting
+
+\def\syntaxhighlighting@id {syntaxhighlighting}
+\edef\t!syntaxhighlighting {\syntaxhighlighting@id}
%D Helper macro
\def\syntaxhighlighting@yes{\v!yes,\v!on}
-\def\definesyntaxhighlighting
- {\dodoubleargument\syntaxhighlighting@define}
-
-\starttexdefinition syntaxhighlighting@define [#1][#2]
- \setupsyntaxhighlighting[#1][\s!parent=\syntaxhighlighting@namespace,#2]
-
- \edef\syntaxhighlighting@name{#1}
- \defineexternalfilter[#1][\s!parent=\syntaxhighlighting@namespace#1,\c!taglabel=\vimtyping@id]
-
- \setups{syntaxhighlighting@setup_line_number_mkiv}
-
- \setvalue{type#1file}{\getvalue{process#1file}}
-
-\stoptexdefinition
-
\startsetups syntaxhighlighting@setup
- \edef\syntaxhighlighting@name{\currentexternalfilter}
+ \edef\currentsyntaxhighlighting{\currentexternalfilter}
\edef\colorscheme@name{\externalfilterparameter\c!alternative}
\let\SYN\syntaxgroup
@@ -74,28 +69,7 @@
\setcatcodetable\externalfilter@minimal_catcodes
\expandafter\def\activeendoflinetoken{\strut\par}
- \activatespacehandler{\syntaxhighlighting@namespace\externalfilterparameter\c!space}
-\stopsetups
-
-\startsetups syntaxhighlighting@setup_line_number_mkiv
-\definelinenumbering [#1]
-
-\setuplinenumbering
- [#1]
- [\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},
- ]
+ \activatespacehandler{\????syntaxhighlighting\externalfilterparameter\c!space}
\stopsetups
\starttexdefinition syntaxhighlighting@read_command #1
@@ -107,8 +81,22 @@
\starttexdefinition syntaxhighlighting@linenumbering_start
\doifinset{\externalfilterparameter\c!numbering}\syntaxhighlighting@yes
{\startlinenumbering
- [\syntaxhighlighting@name]
- [\c!continue=\externalfilterparameter{\c!number\c!continue}]}
+ [\currentsyntaxhighlighting]
+ [\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},
+ \c!continue=\externalfilterparameter{\c!number\c!continue},
+ ]}
\dostarttagged\t!syntaxhighlighting\colorscheme@name
\stoptexdefinition
@@ -138,7 +126,7 @@
\c!output=\externalfilterinputfile, % placeholder
\c!setups=syntaxhighlighting@setup,
\c!option=\v!packed, % Could be a list
- \s!parent=\externalfilter@namespace,
+ \s!parent=\????externalfilter,
% Numbering options
\c!numbering=\v!no,
\c!number\c!start=1,
@@ -161,24 +149,22 @@
\c!highlight\c!command=\syntaxhighlightline,
]
-\def\currentsyntaxhighlighting {\syntaxhighlighting@name}
-
% Space handler
%
% The space handing code for MkII and MkIV is not consistent. So, we provide our
% own versions.
-\setvalue{\syntaxhighlighting@namespace::\c!lines::\v!split}{\hskip}
-\setvalue {\syntaxhighlighting@namespace::\c!lines::\v!fixed}{\dontleavehmode\kern}
+\setvalue{\????syntaxhighlighting::\c!lines::\v!split}{\hskip}
+\setvalue{\????syntaxhighlighting::\c!lines::\v!fixed}{\dontleavehmode\kern}
% default
-\setvalue{\syntaxhighlighting@namespace::\c!lines::}{\hskip}
+\setvalue{\????syntaxhighlighting::\c!lines::}{\hskip}
\def\syntaxhighlighting@split%
- {\getvalue{\syntaxhighlighting@namespace::\c!lines::\externalfilterparameter\c!lines}}
+ {\getvalue{\????syntaxhighlighting::\c!lines::\externalfilterparameter\c!lines}}
% Visible space
-\installspacemethod {\syntaxhighlighting@namespace\v!on}
+\installspacemethod {\????syntaxhighlighting\v!on}
{\obeyspaces
\unexpanded\def\obeyedspace
{\syntaxhighlighting@split\zeropoint\relax
@@ -186,14 +172,14 @@
\syntaxhighlighting@split\zeropoint\relax}}%
% Invisible space
-\installspacemethod {\syntaxhighlighting@namespace\v!off}
+\installspacemethod {\????syntaxhighlighting\v!off}
{\obeyspaces
\unexpanded\def\obeyedspace
{\syntaxhighlighting@split\interwordspace\relax}}
% Default
-\installspacemethod {\syntaxhighlighting@namespace}
- {\activatespacehandler {\syntaxhighlighting@namespace\v!off}}
+\installspacemethod {\????syntaxhighlighting}
+ {\activatespacehandler {\????syntaxhighlighting\v!off}}
% Line highlighting
@@ -206,8 +192,11 @@
\c!color=\externalfilterparameter\c!highlightcolor,
]
+% For backward compatibility
+\def\syntaxhighlighting@namespace {\????syntaxhighlighting}
+\def\syntaxhighlighting@name {\currentsyntaxhighlighting}
-\protectmodulecatcodes
+\protect
\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 91fe748917c..522100bd78d 100644
--- a/Master/texmf-dist/tex/context/third/vim/t-vim.tex
+++ b/Master/texmf-dist/tex/context/third/vim/t-vim.tex
@@ -50,6 +50,7 @@
\edef\vimtyping@name{#1}
\edef\externalfilter@name{#1}
+ \edef\currentexternalfilter{#1}
\begingroup % to keep assignments local
\setupvimtyping[#1][\c!name=,#2]
@@ -83,6 +84,7 @@
\edef\vimtyping@name{#1}
\edef\externalfilter@name{#1}
+ \edef\currentexternalfilter{#1}
\begingroup % to keep assignments local
\setupvimtyping[#1][\c!name=,\c!before=,\c!after=,#2]
@@ -104,9 +106,12 @@
\doifmodeelse{vim-dev}
{\def\vimtyping@script_name{2context.vim}}
{\doifmodeelse\s!mkiv
- {\ctxlua{context.setvalue("vimtyping@script_name",resolvers.resolve("full:2context.vim"))}}
+ {\ctxlua{context.setvalue("vimtyping@script_name",resolvers.resolve("full:2context.vim"))}
+ \ctxlua{print(resolvers.resolve("full:2context.vim")}}
{\def\vimtyping@script_name{kpse:2context.vim}}}
+\show\vimtyping@script_name
+
\def\vimtyping@filter_command
{vim -u \vimrcfilename\space % read global config file
--noplugin % dont load plugins
@@ -201,6 +206,8 @@
\expanded{\setupexternalfilter[\vimrc@id][\c!name=\externalfilterparameter\c!vimrc]}
\edef\externalfilter@name{\vimrc@id}
+ \edef\currentexternalfilter{\vimrc@id}
+
\externalfilter@set_filenames
\global\xdef\vimrcfilename{\externalfilter@input_file}