texlive[54913] Master/texmf-dist: context-vim (27apr20)

commits+karl at tug.org commits+karl at tug.org
Mon Apr 27 23:17:14 CEST 2020


Revision: 54913
          http://tug.org/svn/texlive?view=revision&revision=54913
Author:   karl
Date:     2020-04-27 23:17:13 +0200 (Mon, 27 Apr 2020)
Log Message:
-----------
context-vim (27apr20)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/context/third/vim/VERSION
    trunk/Master/texmf-dist/doc/context/third/vim/vim.txt
    trunk/Master/texmf-dist/tex/context/third/vim/2context.vim
    trunk/Master/texmf-dist/tex/context/third/vim/t-syntax-highlight.mkiv
    trunk/Master/texmf-dist/tex/context/third/vim/t-vim.tex

Modified: trunk/Master/texmf-dist/doc/context/third/vim/VERSION
===================================================================
--- trunk/Master/texmf-dist/doc/context/third/vim/VERSION	2020-04-27 21:16:46 UTC (rev 54912)
+++ trunk/Master/texmf-dist/doc/context/third/vim/VERSION	2020-04-27 21:17:13 UTC (rev 54913)
@@ -1 +1 @@
-2018.08.10
+2020.04.25

Modified: trunk/Master/texmf-dist/doc/context/third/vim/vim.txt
===================================================================
--- trunk/Master/texmf-dist/doc/context/third/vim/vim.txt	2020-04-27 21:16:46 UTC (rev 54912)
+++ trunk/Master/texmf-dist/doc/context/third/vim/vim.txt	2020-04-27 21:17:13 UTC (rev 54913)
@@ -73,7 +73,10 @@
 
 Usage
 -----
+Include the module
 
+    \usemodule[vim]
+
 Suppose you want to syntax highlight Ruby. In particular, you want
 
     \startRUBY
@@ -112,7 +115,7 @@
 
         \inlineRUBY{...}
 
-    The contents of this environment are processed by a vim script
+    The contents of this macro are processed by a vim script
     (`2context.vim`) and the result is read back in ConTeXt.
 
 3. A macro
@@ -125,7 +128,15 @@
     processing a url, see the _Processing remote files_ section of the
     `t-filter` manual.
 
-In all the three cases, the `t-filter` module takes care of writing to external
+4. A macro
+
+        \processRUBYbuffer[...]
+
+     The argument to the macro is the name of a buffer, which is written to an
+     external file, processesd by `2context.vim` and the result is read back in
+     ConTeXt.
+
+In all the four cases, the `t-filter` module takes care of writing to external
 file, processing by `2context.vim`, and reading the contents back to ConTeXt.
 The `t-vim` module simply defines the macros that are used by `2context.vim`.
 
@@ -460,22 +471,28 @@
 Using TeX code in Comments
 --------------------------
 
-Sometimes one wants to use TeX code in comments, especially for math. To
-enable this use
+Sometimes one wants to use TeX command in code. There are two different
+methods to do so.
 
+The first method is primarily aimed towards writing math in comments. To
+enable this, use
+
     \definevimtyping
         [...]
         [...
-         escape=on,
+         escape=comment,
         ]
       
-When `escape=on`, the `2context.vim` script passes the `Comment` syntax
-region (as identified by `vim`) verbatim to TeX. So, we may use TeX
-commands inside the comment region and they will be interpreted by TeX.
-For example
+For backward compatibility, this feature can also be enabled using
+`escape=on`.
 
-    \definevimtyping[C][syntax=c, escape=on]
+When `escape=comment` is enabled, the `2context.vim` script passes the
+`Comment` syntax region (as identified by `vim`) verbatim to TeX. So, we may
+use TeX commands inside the comment region and they will be interpreted by
+TeX. For example
 
+    \definevimtyping[C][syntax=c, escape=comment]
+
     \startC
     /* The following function computes the roots of \m{ax^2+bx+c=0}
      * using the determinant \m{\Delta=\frac{-b\pm\sqrt{b^2-2ac}}{2a}} 
@@ -484,10 +501,79 @@
     \stopC
 
 **Note** that only `\ { }` have their usual meaning inside the `Comment`
-region when `escape=on` is set. Thus, to enter a math expression, use
+region when `escape=comment` is set. Thus, to enter a math expression, use
 `\m{...}` instead of `$...$`. Moreover, spaces are active inside the
 math mode, so, as in the above example, avoid spaces in the math expressions.
 
+The second method is to imitate the behavior of `\starttyping` environment,
+where one can write arbitrary TeX commands in code inside `/BTEX ... /ETEX`
+delimiters. To enable this, use
+
+    \definevimtyping
+        [...]
+        [...
+         escape=command,
+        ]
+
+When `escape=command` is enabled, the `2context.vim` script defines a new
+syntax region using
+
+    syntax region ... start="/BTEX" end="/ETEX" transparent oneline containedin=ALL contains=NONE
+      
+and passes content of this region verbatim to TeX. So, any TeX commands used
+inside this region are interpreted by TeX. For example,
+
+    \definevimtyping[C][syntax=c, escape=command]
+
+    \startC
+       /* Here is a comment describing a complicated function */
+       /BTEX\startframedtext[width=\textwidth,corner=round]/ETEX
+        double complicated (...) 
+        {
+          ....
+        }
+      /BTEX\stopframedtext/ETEX
+    \stopC
+
+**Note** that as in the case for `escape=comment`, only `\ { }` have their
+usual meaning inside `/BTEX ... /ETEX`. Moreover, spaces are active
+characters. So, using a space between `\startframedtext` and `[` or between
+after the comma in the options to `\startframedtext` will result in an error.
+
+Clearly, `/BTEX ... /ETEX` is not a valid syntax in any language, so if these
+tags are used outside of a comment region (as is the case in the above
+example), the code will not compile. So, if the code also needs to run, then
+these annotations have to be restricted to the comment region of the code. 
+
+Although, in practice, the use of both escape mechanisms is restricted to
+comments, the two mechanism have subtle differences. When using
+`escape=comment`, the `2context.vim` script simply passes the content of the
+comment region to TeX. This content is still typeset inside a
+`\SYN[Comment]{...}` group. While when using `escape=command`, the
+`2context.vim` script identifies the content of `/BTEX .. /ETEX` and passes it
+to TeX _without wrapping it insider any `\SYN[..]{...}` group_. This has an
+advantage when we want to use commands that cannot be used inside a group
+(e.g., `\inmargin`). For example, if we want to define a `\callout` macro that
+displays a note in the margin which we can refer to later, we can use:
+
+
+    \define[1]\callout{\inmargin{\rm #1}}
+    \definevimtyping[C][syntax=c, escape=command]
+
+    \startC
+       /* Here is a comment describing a complicated function */
+       double complicated (...) 
+       {
+          ... // /BTEX\callout{Fancy trick!}/ETEX
+       }
+    \stopC
+
+Finally, note that the value of `escape` set using `\definevimtyping` is not
+used to `\inline<vim>typing`. If for some reason, you do need the escape
+mechanism for inline code, use
+
+     \inline<vim>typing[escape=command]{...}
+
 Tuning color schemes
 --------------------
 

Modified: trunk/Master/texmf-dist/tex/context/third/vim/2context.vim
===================================================================
--- trunk/Master/texmf-dist/tex/context/third/vim/2context.vim	2020-04-27 21:16:46 UTC (rev 54912)
+++ trunk/Master/texmf-dist/tex/context/third/vim/2context.vim	2020-04-27 21:17:13 UTC (rev 54913)
@@ -1,5 +1,5 @@
 " Author    : Aditya Mahajan <adityam [at] umich [dot] edu> 
-" version   : 2011.12.23
+" version   : 2020.04.25
 " license   : Simplified BSD License
 
 " This script is part of the t-vim module for ConTeXt. It is based on 2html.vim.  
@@ -39,10 +39,22 @@
 endif
 
 " Set escapecomments
-if !exists("escapecomments")
-  let escapecomments=0
+if exists("escapecomments")
+  let s:escapecomments=escapecomments " 0=off, 1=comments, 2=command
+else 
+  let s:escapecomments=0
 endif
 
+" Add a new syntax region to detect ConTeXt tags
+if s:escapecomments==2
+  syntax region vimtypingTEXcomment start="/BTEX" end="/ETEX" transparent oneline containedin=ALL contains=NONE
+
+  " Find the id of /BTEX ... /ETEX syntax region
+  let s:texcommentid = hlID("vimtypingTEXcomment")
+else
+  let s:texcommentid = -1 " Assuming that all ids are positive. Not documented
+end
+
 let s:strip = strlen( matchstr( getline(s:lstart), '^\s*' ) )
 
 " Find the smallest leading white space
@@ -74,6 +86,7 @@
 while s:lnum <= s:lstop
 " Get the current line
   let s:line = getline(s:lnum)
+
   let s:len  = strlen(s:line)
   let s:new  = '' 
 
@@ -81,11 +94,31 @@
   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
+
+    " Check if the next transprarent syntax is "vimtypingTEXcomment". If not, 
+    " find the next non-transparent syntax id. 
+    let s:id = synID (s:lnum, s:col, 0)
+    if s:id == s:texcommentid
+      let s:texcomment = 1
+    else
+      let s:texcomment = 0
+      let s:id = synID (s:lnum, s:col, 1)
+    endif
+    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) 
+    while s:col <= s:len 
+      " If there is a "vimtypingTEXcomment" inside another syntax id, 
+      " "vimtypingTEXcomment" should get preference
+      let s:nextid = synID(s:lnum, s:col, 0)
+      if !s:texcomment && s:nextid != s:texcommentid
+        let s:nextid = synID(s:lnum, s:col, 1)
+      endif
+
+      if s:nextid != s:id
+        break
+      endif
+         
       let s:col = s:col + 1 
     endwhile
 
@@ -92,7 +125,12 @@
 " 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)
+    if s:texcomment
+      " Remove /BTEX and /ETEX which are 5 characters wide
+      let s:temp = strpart(s:line, s:startcol + 5 - 1, s:col - s:startcol - 5 - 5)
+    else
+      let s:temp = strpart(s:line, s:startcol - 1, s:col - s:startcol)
+    end
 " 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
@@ -99,10 +137,10 @@
 " 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")
+      if !(s:texcomment || (s:escapecomments == 1) && s:id_name == "Comment")
         let s:temp = escape( s:temp, '\{}')
       endif
-      if !empty(s:id_name)
+      if !(s:texcomment || empty(s:id_name))
         let s:temp = '\SYN[' . s:id_name . ']{' . s:temp .  '}'
       endif
       let s:new  = s:new . s:temp

Modified: trunk/Master/texmf-dist/tex/context/third/vim/t-syntax-highlight.mkiv
===================================================================
--- trunk/Master/texmf-dist/tex/context/third/vim/t-syntax-highlight.mkiv	2020-04-27 21:16:46 UTC (rev 54912)
+++ trunk/Master/texmf-dist/tex/context/third/vim/t-syntax-highlight.mkiv	2020-04-27 21:17:13 UTC (rev 54913)
@@ -87,13 +87,13 @@
 
   \forgetall
   \usealignparameter\externalfilterparameter
-  \doifinset{\externalfilterparameter\c!option}{\v!packed}
+  \doifinset{\v!packed}{\externalfilterparameter\c!option}
       {\setupwhitespace[\v!none,\v!flexible]}%
 
   \doadaptleftskip{\externalfilterparameter\c!margin}%
 
   \setbreakpoints[compound]% Only works is `option=hyphenated` is set.
-  \doifnotinset{\externalfilterparameter\c!option}{\v!hyphenated}
+  \doifnotinset{\v!hyphenated}{\externalfilterparameter\c!option}
       {\language\minusone}%
 
   \def\obeyedline{\strut\par}

Modified: trunk/Master/texmf-dist/tex/context/third/vim/t-vim.tex
===================================================================
--- trunk/Master/texmf-dist/tex/context/third/vim/t-vim.tex	2020-04-27 21:16:46 UTC (rev 54912)
+++ trunk/Master/texmf-dist/tex/context/third/vim/t-vim.tex	2020-04-27 21:17:13 UTC (rev 54913)
@@ -1,6 +1,6 @@
 %D \module
 %D   [     file=t-vim,
-%D      version=2018.04.17,
+%D      version=2020.04.25,
 %D        title=\CONTEXT\ User Module,
 %D     subtitle=Vim syntax highlighting,
 %D       author=Aditya Mahajan,
@@ -9,7 +9,7 @@
 %D        email=adityam <at> ieee <dot> org,
 %D      license=Simplified BSD License]
 
-\writestatus{loading}{Vim syntax highlighting (ver: 2018.04.17)}
+\writestatus{loading}{Vim syntax highlighting (ver: 2020.04.25)}
 
 \startmodule [vim]
 \usemodule   [filter]           % loads module catcodes
@@ -129,7 +129,7 @@
        -c "let contextstartline=\externalfilterparameter\c!start \letterbar\space %
            let contextstopline=\externalfilterparameter\c!stop   \letterbar\space %
            let strip=\getvalue{\vimtyping at id-\c!strip-\externalfilterparameter\c!strip}" %
-       -c "let escapecomments=\getvalue{\vimtyping at id-\c!escape-\externalfilterparameter\c!escape}" %
+       -c "let escapecomments=\getvalue{\vimtyping at id-\c!escape-\externalfilterparameter\c!escape}"
        -c "let highlight=[\externalfilterparameter\c!highlight]" %
        \vimrc_extras\space
        -c "source \vimtyping at script_name" %
@@ -140,10 +140,15 @@
 \setvalue{\vimtyping at id-\c!strip-\v!off}{0}
 \setvalue{\vimtyping at id-\c!strip-\v!on}{1}
 
+\setvalue{\vimtyping at id-\c!escape-}{0} % Empty value
+
 \setvalue{\vimtyping at id-\c!escape-\v!off}{0}
 \setvalue{\vimtyping at id-\c!escape-\v!on}{1}
 
+\setvalue{\vimtyping at id-\c!escape-\v!comment}{1}
+\setvalue{\vimtyping at id-\c!escape-\v!command}{2}
 
+
 % Undocumented ... but useful if the user makes a mistake
 \setvalue{\vimtyping at id-\c!strip-\v!no}{0}
 \setvalue{\vimtyping at id-\c!strip-\v!yes}{1}
@@ -151,7 +156,6 @@
 \setvalue{\vimtyping at id-\c!escape-\v!no}{0}
 \setvalue{\vimtyping at id-\c!escape-\v!yes}{1}
 
-
 \setupvimtyping
   [% \c!tab=4,
    % \c!start=1,



More information about the tex-live-commits mailing list.