Skip to content

Commit

Permalink
feat(fold): support comment package
Browse files Browse the repository at this point in the history
refer: #2882
  • Loading branch information
lervag committed Feb 7, 2024
1 parent f36e585 commit 386007c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions autoload/vimtex/fold.vim
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function! vimtex#fold#init_state(state) abort " {{{1
\ . '|^\s*}'
let a:state.fold_re_next = ''
for l:name in [
\ 'comment_pkg',
\ 'preamble',
\ 'cmd_single',
\ 'cmd_single_opt',
Expand Down
39 changes: 39 additions & 0 deletions autoload/vimtex/fold/comment_pkg.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
" VimTeX - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve Lervåg
" Email: karl.yngve@gmail.com
"

function! vimtex#fold#comment_pkg#new(config) abort " {{{1
return extend(deepcopy(s:folder), a:config)
endfunction

" }}}1


let s:folder = {
\ 'name' : 'comment_pkg',
\ 're' : {
\ 'start' : '^\s*\\begin\s*{comment}',
\ 'end' : '^\s*\\end\s*{comment}',
\ },
\ 'opened' : v:false,
\}
function! s:folder.level(line, lnum) abort dict " {{{1
if a:line =~# self.re.start
let self.opened = v:true
return 'a1'
elseif a:line =~# self.re.end
let self.opened = v:false
return 's1'
elseif self.opened
return '='
endif
endfunction

" }}}1
function! s:folder.text(line, level) abort dict " {{{1
return a:line
endfunction

" }}}1
1 change: 1 addition & 0 deletions autoload/vimtex/options.vim
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function! vimtex#options#init() abort " {{{1
call s:init_option('vimtex_fold_types_defaults', {
\ 'preamble' : {},
\ 'items' : {},
\ 'comment_pkg' : {},
\ 'comments' : { 'enabled' : 0 },
\ 'envs' : {
\ 'blacklist' : [],
Expand Down
4 changes: 4 additions & 0 deletions doc/vimtex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,9 @@ OPTIONS *vimtex-options*
corresponding "real" sections. The fold title is the
provided title with the `Fake...` part prepended.

<comment_pkg> Fold `\begin{comments} ... \end{comments}` and disable
folding inside the environment.

<comments> Fold multiline comments. This is disabled by default.

<markers> Fold on vim-style markers inside comments, that is,
Expand Down Expand Up @@ -1928,6 +1931,7 @@ OPTIONS *vimtex-options*
let g:vimtex_fold_types_defaults = {
\ 'preamble' : {},
\ 'items' : {},
\ 'comment_pkg' : {},
\ 'comments' : {'enabled' : 0},
\ 'envs' : {
\ 'blacklist' : [],
Expand Down

0 comments on commit 386007c

Please sign in to comment.