@@ -54,31 +54,37 @@ function! vimtex#fold#init_state(state) abort " {{{1
5454 \ . ' |^\s*\]\s*%(\{|$)'
5555 \ . ' |^\s*}'
5656 let a: state .fold_re_next = ' '
57+ let a: state .fold_re_comment = ' '
5758 for l: name in [
58- \ ' comment_pkg' ,
5959 \ ' preamble' ,
6060 \ ' cmd_single' ,
6161 \ ' cmd_single_opt' ,
6262 \ ' cmd_multi' ,
6363 \ ' cmd_addplot' ,
6464 \ ' sections' ,
6565 \ ' markers' ,
66- \ ' comments' ,
6766 \ ' items' ,
6867 \ ' envs' ,
6968 \ ' env_options' ,
7069 \]
7170 let l: type = get (a: state .fold_types_dict, l: name , {})
72- if ! empty (l: type )
73- call add (a: state .fold_types_ordered, l: type )
74- if exists (' l:type.re.fold_re' )
75- let a: state .fold_re .= ' |' . l: type .re .fold_re
76- endif
77- if exists (' l:type.re.fold_re_next' )
78- let a: state .fold_re_next .=
79- \ (empty (a: state .fold_re_next) ? ' \v' : ' |' )
80- \ . l: type .re .fold_re_next
81- endif
71+ if empty (l: type ) | continue | endif
72+
73+ call add (a: state .fold_types_ordered, l: type )
74+ if exists (' l:type.re.fold_re' )
75+ let a: state .fold_re .= ' |' .. l: type .re .fold_re
76+ endif
77+
78+ if exists (' l:type.re.fold_re_next' )
79+ let a: state .fold_re_next .=
80+ \ (empty (a: state .fold_re_next) ? ' \v' : ' |' )
81+ \ .. l: type .re .fold_re_next
82+ endif
83+
84+ if exists (' l:type.re.fold_re_comment' )
85+ let a: state .fold_re_comment .=
86+ \ (empty (a: state .fold_re_comment) ? ' \v' : ' |' )
87+ \ .. l: type .re .fold_re_comment
8288 endif
8389 endfor
8490endfunction
@@ -110,6 +116,18 @@ function! vimtex#fold#level(lnum) abort " {{{1
110116 return ' ='
111117 endif
112118
119+ " Handle comments by considering the syntax
120+ if vimtex#syntax#in_comment (a: lnum , 1 )
121+ \ && l: line !~# b: vimtex .fold_re_comment
122+ if l: line = ~# ' ^\s*\\begin\s*{comment}'
123+ return ' a1'
124+ elseif l: line = ~# ' ^\s*\\end\s*{comment}'
125+ return ' s1'
126+ else
127+ return ' ='
128+ endif
129+ endif
130+
113131 for l: type in b: vimtex .fold_types_ordered
114132 let l: value = l: type .level (l: line , a: lnum )
115133 if ! empty (l: value ) | return l: value | endif
0 commit comments