diff --git a/autoload/vimtex/fold.vim b/autoload/vimtex/fold.vim index e14ed37..b72e354 100644 --- a/autoload/vimtex/fold.vim +++ b/autoload/vimtex/fold.vim @@ -73,10 +73,19 @@ function! vimtex#fold#init_buffer() " {{{1 augroup END endif else - augroup vimtex_fold_manual - autocmd CursorMoved call vimtex#fold#refresh('zx') - autocmd CursorMoved autocmd! vimtex_fold_manual + let s:fold_manual_id = get(s:, 'fold_manual_id', 0) + 1 + let b:fold_manual_augroup = 'vimtex_fold_' . s:fold_manual_id + execute 'augroup' b:fold_manual_augroup + autocmd! + autocmd CursorMoved call s:fold_manual_refresh() augroup END + + function! s:fold_manual_refresh() + call vimtex#fold#refresh('zx') + execute 'autocmd!' b:fold_manual_augroup + execute 'augroup!' b:fold_manual_augroup + unlet b:fold_manual_augroup + endfunction endif endfunction diff --git a/autoload/vimtex/latexmk.vim b/autoload/vimtex/latexmk.vim index 66f925d..a802b70 100644 --- a/autoload/vimtex/latexmk.vim +++ b/autoload/vimtex/latexmk.vim @@ -497,7 +497,7 @@ function! s:buffer_left() " {{{1 endfunction function! s:buffer_deleted() " {{{1 - if s:vimtex.pid == 0 | return | endif + if get(get(s:, 'vimtex', {}), 'pid', 0) == 0 | return | endif " " The buffer is deleted, so we must kill the remaining latexmk process if the diff --git a/indent/tex.vim b/indent/tex.vim index d3a62de..ed79cbf 100644 --- a/indent/tex.vim +++ b/indent/tex.vim @@ -89,12 +89,22 @@ function! VimtexIndent() " {{{1 endif " Indent opening and closing delimiters - let popen = s:count_delimiters(pline, s:delimiters_open) - let copen = s:count_delimiters(cline, s:delimiters_open) - let pclose = s:count_delimiters(pline, s:delimiters_close) - let cclose = s:count_delimiters(cline, s:delimiters_close) + let popen = s:count_delimiters(pline, s:tex_delimiters_open) + let copen = s:count_delimiters(cline, s:tex_delimiters_open) + let pclose = s:count_delimiters(pline, s:tex_delimiters_close) + let cclose = s:count_delimiters(cline, s:tex_delimiters_close) let ind += &sw*(max([popen - pclose, 0]) - max([cclose - copen, 0])) + " Indent opening and closing delimiters for math mode + if match(map(synstack(v:lnum, max([col('.') - 1, 1])), + \ 'synIDattr(v:val, ''name'')'), '^texMathZone') >= 0 + let popen = s:count_delimiters(pline, s:math_delimiters_open) + let copen = s:count_delimiters(cline, s:math_delimiters_open) + let pclose = s:count_delimiters(pline, s:math_delimiters_close) + let cclose = s:count_delimiters(cline, s:math_delimiters_close) + let ind += &sw*(max([popen - pclose, 0]) - max([cclose - copen, 0])) + endif + " Indent list items if pline =~# '^\s*\\\(bib\)\?item' let ind += &sw @@ -136,25 +146,31 @@ let s:tikz_indented = 0 " Define some common patterns let s:envs_lists = 'itemize\|description\|enumerate\|thebibliography' let s:envs_noindent = 'document\|verbatim\|lstlisting' -let s:delimiters_open = '\(' . join([ +let s:tex_delimiters_open = '\(' . join([ \ '{', - \ '(', \ '\[', - \ '\\{', \ '\\(', \ '\\\[', \ '\\\Cbegin\s*{.\{-}}', - \ '\\\Cleft\s*\%([^\\]\|\\.\|\\\a*\)', - \ '\\\cbigg\?\((\|\[\|\\{\)', \ ], '\|') . '\)' -let s:delimiters_close = '\(' . join([ +let s:tex_delimiters_close = '\(' . join([ \ '}', - \ ')', \ '\]', - \ '\\}', \ '\\)', \ '\\\]', \ '\\\Cend\s*{.\{-}}', + \ ], '\|') . '\)' +let s:math_delimiters_open = '\(' . join([ + \ '(', + \ '\[', + \ '\\{', + \ '\\\Cleft\s*\%([^\\]\|\\.\|\\\a*\)', + \ '\\\cbigg\?\((\|\[\|\\{\)', + \ ], '\|') . '\)' +let s:math_delimiters_close = '\(' . join([ + \ ')', + \ '\]', + \ '\\}', \ '\\\Cright\s*\%([^\\]\|\\.\|\\\a*\)', \ '\\\cbigg\?\()\|\]\|\\}\)', \ ], '\|') . '\)'