-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(syntax): add wip support for robust-externalize
refer: #2977
- Loading branch information
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
" VimTeX - LaTeX plugin for Vim | ||
" | ||
" Maintainer: Karl Yngve Lervåg | ||
" Email: karl.yngve@gmail.com | ||
" | ||
|
||
function! vimtex#syntax#p#robust_externalize#load(cfg) abort " {{{1 | ||
" Match environment boundaries | ||
syntax match texRobExtEnvBgn contained '\\begin{\%(RobExt\)\?CacheMeCode\|CacheMe}' | ||
\ nextgroup=texRobExtEnvOpt,texRobExtEnvArg skipwhite skipnl | ||
\ contains=texCmdEnv | ||
call vimtex#syntax#core#new_opt('texRobExtEnvOpt', {'next': 'texRobExtEnvArg'}) | ||
call vimtex#syntax#core#new_arg('texRobExtEnvArg', {'contains': 'texRobExtEnvArg'}) | ||
|
||
" Match generic environments | ||
call vimtex#syntax#core#new_env({ | ||
\ 'name': '\%(RobExt\)\?CacheMeCode\|CacheMe', | ||
\ 'region': 'texRobExtZone', | ||
\ 'contains': 'texCmdEnv,texRobExtEnvBgn', | ||
\}) | ||
call vimtex#syntax#core#new_env({ | ||
\ 'name': 'PlaceholderPathFromCode', | ||
\ 'region': 'texRobExtZone', | ||
\ 'contains': 'texCmdEnv,texRobExtEnvBgn', | ||
\}) | ||
call vimtex#syntax#core#new_env({ | ||
\ 'name': 'SetPlaceholderCode\*\?', | ||
\ 'region': 'texRobExtZone', | ||
\ 'contains': 'texCmdEnv,texRobExtEnvBgn', | ||
\}) | ||
|
||
" Add nested syntax support for supported languages | ||
for [l:preset, l:target] in [ | ||
\ ['c', 'c'], | ||
\ ['bash', 'bash'], | ||
\ ['python', 'python'], | ||
\ ['my python', 'python'], | ||
\] | ||
let l:cluster = vimtex#syntax#nested#include(l:target) | ||
|
||
let l:name = toupper(l:target[0]) . l:target[1:] | ||
let l:grp_env = 'texRobExtZone' . l:name | ||
let l:options = 'keepend' | ||
let l:contains = 'contains=texCmdEnv,texRobExtEnvBgn' | ||
|
||
if empty(l:cluster) | ||
execute 'highlight def link' l:grp_env 'texRobExtZone' | ||
else | ||
let l:contains .= ',' . l:cluster | ||
endif | ||
|
||
" Match normal robext environments | ||
execute 'syntax region' l:grp_env | ||
\ 'start="\\begin{\z(\%(RobExt\)\?CacheMeCode\|CacheMe\)}\_s*{' . l:preset . '[ ,}]"' | ||
\ 'end="\\end{\z1}"' | ||
\ l:options | ||
\ l:contains | ||
endfor | ||
|
||
" Specify default highlight groups | ||
highlight def link texRobExtEnvArg texSymbol | ||
highlight def link texRobExtEnvArgOpt texOpt | ||
highlight def link texRobExtEnvOpt texOpt | ||
highlight def link texRobExtZone texZone | ||
endfunction | ||
|
||
" }}}1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
\documentclass{article} | ||
\usepackage{robust-externalize} | ||
|
||
\begin{document} | ||
|
||
\begin{CacheMeCode}{c} | ||
int main() { | ||
return 1; | ||
} | ||
\end{CacheMeCode} | ||
|
||
\begin{CacheMeCode}{bash, tikz terminal} | ||
echo 'test.dat' | ||
exit 0 | ||
\end{CacheMeCode} | ||
\begin{figure} | ||
\begin{CacheMeCode}{python matplotlib, add to preamble={\def\hello#1{Hello #1!}}} | ||
def f(p: string): | ||
return [x + p for x in ('a', 'b')] | ||
\end{CacheMeCode} | ||
\end{figure} | ||
|
||
\begin{RobExtCacheMeCode}{my python matplotlib, | ||
add to preamble={\def\hello#1{Hello #1!}} | ||
} | ||
def f(p: string): | ||
return [x + p for x in ('a', 'b')] | ||
\end{RobExtCacheMeCode} | ||
|
||
\begin{CacheMe}{tikzpicture}[scale=0.6] | ||
\draw[gray, thick] (-1,2) -- (2,-4); | ||
\draw[gray, thick] (-1,-1) -- (2,2); | ||
\filldraw[black] (0,0) circle (2pt) node[anchor=west]{Intersection point}; | ||
\end{CacheMe} | ||
|
||
\begin{SetPlaceholderCode*}{__PYTHON_TEMP} | ||
def f(p: string): | ||
return [x + p for x in ('a', 'b')] | ||
\end{SetPlaceholderCode*} | ||
|
||
\begin{PlaceholderPathFromCode}[.py]{__PYTHON_TEMP} | ||
def f(p: string): | ||
return [x + p for x in ('a', 'b')] | ||
\end{PlaceholderPathFromCode} | ||
|
||
\end{document} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
source common.vim | ||
|
||
Edit test-robust-externalize.tex | ||
|
||
if empty($INMAKE) | finish | endif | ||
|
||
call vimtex#test#finished() |