Add support for hyperref command (#399)

This commit is contained in:
Karl Yngve Lervåg 2016-03-23 22:21:37 +01:00
parent 1aabb84fa7
commit d169631706
4 changed files with 34 additions and 21 deletions

View File

@ -39,7 +39,8 @@ for [style, group, commands] in [
endfor endfor
" }}}1 " }}}1
" {{{1 Add syntax highlighting for \url and \href " {{{1 Add syntax highlighting for \url, \href, \hyperref
syntax match texStatement '\\url\ze[^\ta-zA-Z]' nextgroup=texUrlVerb syntax match texStatement '\\url\ze[^\ta-zA-Z]' nextgroup=texUrlVerb
syntax match texStatement '\\url\ze\s*{' nextgroup=texUrl syntax match texStatement '\\url\ze\s*{' nextgroup=texUrl
syntax match texStatement '\\href' nextgroup=texHref syntax match texStatement '\\href' nextgroup=texHref
@ -53,10 +54,14 @@ syntax region texHref matchgroup=Delimiter start='{' end='}' contained
syntax region texHrefLinkText matchgroup=Delimiter start='{' end='}' contained syntax region texHrefLinkText matchgroup=Delimiter start='{' end='}' contained
\ contains=@Spell \ contains=@Spell
syntax match texStatement '\\hyperref' nextgroup=texHyperref
syntax region texHyperref matchgroup=Delimiter start='\[' end='\]' contained
highlight link texUrl Function highlight link texUrl Function
highlight link texUrlVerb texUrl highlight link texUrlVerb texUrl
highlight link texHref texUrl highlight link texHref texUrl
highlight link texHrefLinkText texSectionZone highlight link texHrefLinkText texSectionZone
highlight link texHyperref texRefZone
" }}}1 " }}}1
" {{{1 Improve support for cite commands " {{{1 Improve support for cite commands

View File

@ -37,22 +37,25 @@ endfunction
function! vimtex#complete#omnifunc(findstart, base) " {{{1 function! vimtex#complete#omnifunc(findstart, base) " {{{1
if a:findstart if a:findstart
let pos = col('.') - 1 let l:pos = col('.') - 1
let line = getline('.')[:pos-1] let l:line = getline('.')[:l:pos-1]
for l:completer in s:completers for l:completer in s:completers
if !get(l:completer, 'enabled', 0) | return -3 | endif if !get(l:completer, 'enabled', 0) | return -3 | endif
if line =~# l:completer.pattern . '$' for l:pattern in l:completer.patterns
let s:completer = l:completer if l:line =~# l:pattern
while pos > 0 let s:completer = l:completer
if line[pos - 1] =~# '{\|,' || line[pos-2:pos-1] ==# ', ' while l:pos > 0
return pos if l:line[l:pos - 1] =~# '{\|,\|\['
else \ || l:line[l:pos-2:l:pos-1] ==# ', '
let pos -= 1 return l:pos
endif else
endwhile let l:pos -= 1
return -2 endif
endif endwhile
return -2
endif
endfor
endfor endfor
return -3 return -3
else else
@ -68,7 +71,7 @@ endfunction
" {{{1 Bibtex " {{{1 Bibtex
let s:bib = { let s:bib = {
\ 'pattern' : '\v\\\a*cite\a*%(\s*\[[^]]*\]){0,2}\s*\{[^}]*', \ 'patterns' : ['\v\\\a*cite\a*%(\s*\[[^]]*\]){0,2}\s*\{[^}]*$'],
\ 'enabled' : 1, \ 'enabled' : 1,
\ 'bibs' : '''\v%(%(\\@<!%(\\\\)*)@<=\%.*)@<!' \ 'bibs' : '''\v%(%(\\@<!%(\\\\)*)@<=\%.*)@<!'
\ . '\\(bibliography|add(bibresource|globalbib|sectionbib))' \ . '\\(bibliography|add(bibresource|globalbib|sectionbib))'
@ -223,7 +226,10 @@ endfunction
" {{{1 Labels " {{{1 Labels
let s:ref = { let s:ref = {
\ 'pattern' : '\v\\v?%(auto|eq|[cC]?%(page)?|labelc)?ref%(\s*\{[^}]*|range\s*\{[^,{}]*%(\}\{)?)', \ 'patterns' : [
\ '\v\\v?%(auto|eq|[cC]?%(page)?|labelc)?ref%(\s*\{[^}]*|range\s*\{[^,{}]*%(\}\{)?)$',
\ '\\hyperref\s*\[[^]]*$'
\ ],
\ 'enabled' : 1, \ 'enabled' : 1,
\ 'cache' : {}, \ 'cache' : {},
\} \}
@ -337,7 +343,7 @@ endfunction
" {{{1 Filenames (\includegraphics) " {{{1 Filenames (\includegraphics)
let s:img = { let s:img = {
\ 'pattern' : '\v\\includegraphics\*?%(\s*\[[^]]*\]){0,2}\s*\{[^}]*', \ 'patterns' : ['\v\\includegraphics\*?%(\s*\[[^]]*\]){0,2}\s*\{[^}]*$'],
\ 'enabled' : 1, \ 'enabled' : 1,
\} \}
@ -370,7 +376,7 @@ endfunction
" {{{1 Filenames (\input and \include) " {{{1 Filenames (\input and \include)
let s:inc = { let s:inc = {
\ 'pattern' : '\v\\%(include%(only)?|input)\s*\{[^}]*', \ 'patterns' : ['\v\\%(include%(only)?|input)\s*\{[^}]*$'],
\ 'enabled' : 1, \ 'enabled' : 1,
\} \}
@ -390,7 +396,7 @@ endfunction
" {{{1 Glossary " {{{1 Glossary
let s:gls = { let s:gls = {
\ 'pattern' : '\v\\gls\s*\{[^}]*', \ 'patterns' : ['\v\\gls\s*\{[^}]*$'],
\ 'enabled' : 1, \ 'enabled' : 1,
\} \}

View File

@ -1456,6 +1456,7 @@ documents with |neocomplete| and |vimtex|s omni completion function: >
\ '\v\\%(' \ '\v\\%('
\ . '\a*cite\a*%(\s*\[[^]]*\]){0,2}\s*\{[^}]*' \ . '\a*cite\a*%(\s*\[[^]]*\]){0,2}\s*\{[^}]*'
\ . '|\a*ref%(\s*\{[^}]*|range\s*\{[^,}]*%(}\{)?)' \ . '|\a*ref%(\s*\{[^}]*|range\s*\{[^,}]*%(}\{)?)'
\ . '|hyperref\s*\[[^]]*'
\ . '|includegraphics\*?%(\s*\[[^]]*\]){0,2}\s*\{[^}]*' \ . '|includegraphics\*?%(\s*\[[^]]*\]){0,2}\s*\{[^}]*'
\ . '|%(include%(only)?|input)\s*\{[^}]*' \ . '|%(include%(only)?|input)\s*\{[^}]*'
\ . ')' \ . ')'

View File

@ -81,6 +81,7 @@ const double pi = 3.1415926535
\url+http://www.google.com+ \url+http://www.google.com+
\href{http://example.com}{Title text} \href{http://example.com}{Title text}
\urldef{\mysite}\url{http://example.com} \urldef{\mysite}\url{http://example.com}
\hyperref[asdasd]{asd}
\end{document} \end{document}