Cf. #477: Add folding for usepackages
This commit is contained in:
parent
c16bd14709
commit
f6deaa6ccf
@ -41,7 +41,7 @@ function! vimtex#fold#init_script() " {{{1
|
|||||||
"
|
"
|
||||||
" List of identifiers for improving efficiency
|
" List of identifiers for improving efficiency
|
||||||
"
|
"
|
||||||
let s:folded = '\v^\s*\%'
|
let s:folded = '\v^\s*\%|^\s*\]\{'
|
||||||
let s:folded .= '|\\%(' . join([
|
let s:folded .= '|\\%(' . join([
|
||||||
\ 'begin',
|
\ 'begin',
|
||||||
\ 'end',
|
\ 'end',
|
||||||
@ -51,6 +51,7 @@ function! vimtex#fold#init_script() " {{{1
|
|||||||
\ '%(front|main|back)matter',
|
\ '%(front|main|back)matter',
|
||||||
\ 'appendix',
|
\ 'appendix',
|
||||||
\ 'part',
|
\ 'part',
|
||||||
|
\ 'usepackage',
|
||||||
\ ], '|') . ')'
|
\ ], '|') . ')'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -138,6 +139,15 @@ function! vimtex#fold#level(lnum) " {{{1
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" Fold usepackages
|
||||||
|
if line =~# '^\s*\\usepackage\s*\[\s*\%($\|%\)'
|
||||||
|
let s:usepackage = 1
|
||||||
|
return 'a1'
|
||||||
|
elseif get(s:, 'start', 0) && line =~# '^\s*\]{'
|
||||||
|
let s:usepackage = 0
|
||||||
|
return 's1'
|
||||||
|
endif
|
||||||
|
|
||||||
" Fold chapters and sections
|
" Fold chapters and sections
|
||||||
for [part, level] in b:vimtex_fold.parts
|
for [part, level] in b:vimtex_fold.parts
|
||||||
if line =~# part
|
if line =~# part
|
||||||
@ -236,6 +246,13 @@ function! vimtex#fold#text() " {{{1
|
|||||||
" Initialize
|
" Initialize
|
||||||
let line = getline(v:foldstart)
|
let line = getline(v:foldstart)
|
||||||
|
|
||||||
|
" Text for usepackage
|
||||||
|
if line =~# '^\s*\\usepackage'
|
||||||
|
return '\usepackage[...]{'
|
||||||
|
\ . vimtex#cmd#get_at(v:foldstart, 1).args[0].text
|
||||||
|
\ . '}'
|
||||||
|
endif
|
||||||
|
|
||||||
let level = v:foldlevel > 1
|
let level = v:foldlevel > 1
|
||||||
\ ? repeat('-', v:foldlevel-2) . g:vimtex_fold_levelmarker
|
\ ? repeat('-', v:foldlevel-2) . g:vimtex_fold_levelmarker
|
||||||
\ : ''
|
\ : ''
|
||||||
|
Loading…
Reference in New Issue
Block a user