diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2020-04-25 21:30:46 +0200 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2020-04-25 21:30:46 +0200 |
commit | d757bfd643cc73c2d495355c153ed0257f5d5b47 (patch) | |
tree | ff210950456938a779d98f6a2ba7321aca512897 /autoload/vimtex/syntax/p/listings.vim | |
parent | 8ec73a3a8974a62a613680a6b6222a77a7b99546 (diff) | |
download | vim-polyglot-d757bfd643cc73c2d495355c153ed0257f5d5b47.tar.gz vim-polyglot-d757bfd643cc73c2d495355c153ed0257f5d5b47.zip |
Change latex provider to luatex, closes #476
Diffstat (limited to 'autoload/vimtex/syntax/p/listings.vim')
-rw-r--r-- | autoload/vimtex/syntax/p/listings.vim | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/autoload/vimtex/syntax/p/listings.vim b/autoload/vimtex/syntax/p/listings.vim new file mode 100644 index 00000000..81c7da24 --- /dev/null +++ b/autoload/vimtex/syntax/p/listings.vim @@ -0,0 +1,75 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1 + +" vimtex - LaTeX plugin for Vim +" +" Maintainer: Karl Yngve LervÄg +" Email: karl.yngve@gmail.com +" + +function! vimtex#syntax#p#listings#load() abort " {{{1 + if has_key(b:vimtex_syntax, 'listings') | return | endif + let b:vimtex_syntax.listings = s:get_nested_languages() + + " First some general support + syntax match texInputFile + \ "\\lstinputlisting\s*\(\[.\{-}\]\)\={.\{-}}" + \ contains=texStatement,texInputCurlies,texInputFileOpt + syntax match texZone "\\lstinline\s*\(\[.\{-}\]\)\={.\{-}}" + + " Set all listings environments to listings + syntax cluster texFoldGroup add=texZoneListings + syntax region texZoneListings + \ start="\\begin{lstlisting}\(\_s*\[\_[^\]]\{-}\]\)\?"rs=s + \ end="\\end{lstlisting}\|%stopzone\>"re=e + \ keepend + \ contains=texBeginEnd + + " Next add nested syntax support for desired languages + for l:nested in b:vimtex_syntax.listings + let l:cluster = vimtex#syntax#misc#include(l:nested) + if empty(l:cluster) | continue | endif + + let l:group_main = 'texZoneListings' . toupper(l:nested[0]) . l:nested[1:] + let l:group_lstset = l:group_main . 'Lstset' + let l:group_contained = l:group_main . 'Contained' + execute 'syntax cluster texFoldGroup add=' . l:group_main + execute 'syntax cluster texFoldGroup add=' . l:group_lstset + + execute 'syntax region' l:group_main + \ 'start="\c\\begin{lstlisting}\s*' + \ . '\[\_[^\]]\{-}language=' . l:nested . '\%(\s*,\_[^\]]\{-}\)\?\]"rs=s' + \ 'end="\\end{lstlisting}"re=e' + \ 'keepend' + \ 'transparent' + \ 'contains=texBeginEnd,@' . l:cluster + + execute 'syntax match' l:group_lstset + \ '"\c\\lstset{.*language=' . l:nested . '\%(\s*,\|}\)"' + \ 'transparent' + \ 'contains=texStatement,texMatcher' + \ 'skipwhite skipempty' + \ 'nextgroup=' . l:group_contained + + execute 'syntax region' l:group_contained + \ 'start="\\begin{lstlisting}"rs=s' + \ 'end="\\end{lstlisting}"re=e' + \ 'keepend' + \ 'transparent' + \ 'containedin=' . l:group_lstset + \ 'contains=texStatement,texBeginEnd,@' . l:cluster + endfor + + highlight link texZoneListings texZone +endfunction + +" }}}1 + +function! s:get_nested_languages() abort " {{{1 + return map( + \ filter(getline(1, '$'), "v:val =~# 'language='"), + \ 'matchstr(v:val, ''language=\zs\w\+'')') +endfunction + +" }}}1 + +endif |