Improve syntax in indent file
This commit is contained in:
parent
986b46c78f
commit
8d78038f06
@ -23,94 +23,86 @@ setlocal indentkeys+=[,(,{,),},],\&,=item
|
|||||||
|
|
||||||
function! VimtexIndent() " {{{1
|
function! VimtexIndent() " {{{1
|
||||||
" Find a non-blank non-comment line above the current line
|
" Find a non-blank non-comment line above the current line
|
||||||
let lnum = prevnonblank(v:lnum - 1)
|
let l:nprev = prevnonblank(v:lnum - 1)
|
||||||
while lnum != 0 && getline(lnum) =~# '^\s*%'
|
while l:nprev != 0 && getline(l:nprev) =~# '^\s*%'
|
||||||
let lnum = prevnonblank(lnum - 1)
|
let l:nprev = prevnonblank(l:nprev - 1)
|
||||||
endwhile
|
endwhile
|
||||||
|
if l:nprev == 0
|
||||||
" Zero indent for top of file
|
|
||||||
if lnum == 0
|
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Get current and previous line, remove comments
|
" Get current and previous line and remove comments
|
||||||
let cline = substitute(getline(v:lnum), '\\\@<!%.*', '', '')
|
let l:cur = substitute(getline(v:lnum), '\\\@<!%.*', '', '')
|
||||||
let pline = substitute(getline(lnum), '\\\@<!%.*', '', '')
|
let l:prev = substitute(getline(l:nprev), '\\\@<!%.*', '', '')
|
||||||
|
|
||||||
" Check for verbatim modes
|
" Check for verbatim modes
|
||||||
if synIDattr(synID(v:lnum, indent(v:lnum), 1), 'name') ==# 'texZone'
|
if synIDattr(synID(v:lnum, indent(v:lnum), 1), 'name') ==# 'texZone'
|
||||||
if empty(cline)
|
return empty(l:cur) ? indent(l:nprev) : indent(v:lnum)
|
||||||
return indent(lnum)
|
|
||||||
else
|
|
||||||
return indent(v:lnum)
|
|
||||||
end
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Align on ampersands
|
" Align on ampersands
|
||||||
if cline =~# '^\s*&' && pline =~# '\\\@<!&.*'
|
if l:cur =~# '^\s*&' && l:prev =~# '\\\@<!&.*'
|
||||||
return indent(v:lnum) + match(pline, '\\\@<!&') - stridx(cline, '&')
|
return indent(v:lnum) + match(l:prev, '\\\@<!&') - stridx(l:cur, '&')
|
||||||
endif
|
|
||||||
|
|
||||||
" Find previous non-empty non-comment non-ampersand line
|
|
||||||
while lnum != 0 && (match(pline, '\\\@<!&') != -1 || pline =~# '^\s*%')
|
|
||||||
let lnum = prevnonblank(lnum - 1)
|
|
||||||
let pline = getline(lnum)
|
|
||||||
endwhile
|
|
||||||
|
|
||||||
" Zero indent for top of file
|
|
||||||
if lnum == 0
|
|
||||||
return 0
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Use previous indentation for comments
|
" Use previous indentation for comments
|
||||||
if cline =~# '^\s*%'
|
if l:cur =~# '^\s*%'
|
||||||
return indent(v:lnum)
|
return indent(v:lnum)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let ind = indent(lnum)
|
" Find previous non-empty non-comment non-ampersand line
|
||||||
|
while l:nprev != 0 && (match(l:prev, '\\\@<!&') != -1 || l:prev =~# '^\s*%')
|
||||||
|
let l:nprev = prevnonblank(l:nprev - 1)
|
||||||
|
let l:prev = getline(l:nprev)
|
||||||
|
endwhile
|
||||||
|
if l:nprev == 0
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:ind = indent(l:nprev)
|
||||||
|
|
||||||
" Add indent on begin environment
|
" Add indent on begin environment
|
||||||
if pline =~# '\\begin{.*}' && pline !~ s:envs_noindent
|
if l:prev =~# '\\begin{.*}' && l:prev !~ s:envs_noindent
|
||||||
let ind = ind + &sw
|
let l:ind = l:ind + &sw
|
||||||
|
|
||||||
" Add extra indent for list environments
|
" Add extra indent for list environments
|
||||||
if pline =~ s:envs_lists
|
if l:prev =~ s:envs_lists
|
||||||
let ind = ind + &sw
|
let l:ind = l:ind + &sw
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Subtract indent on end environment
|
" Subtract indent on end environment
|
||||||
if cline =~# '\\end{.*}' && cline !~ s:envs_noindent
|
if l:cur =~# '\\end{.*}' && l:cur !~ s:envs_noindent
|
||||||
let ind = ind - &sw
|
let l:ind = l:ind - &sw
|
||||||
|
|
||||||
" Subtract extra indent for list environments
|
" Subtract extra indent for list environments
|
||||||
if cline =~ s:envs_lists
|
if l:cur =~ s:envs_lists
|
||||||
let ind = ind - &sw
|
let l:ind = l:ind - &sw
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Indent opening and closing delimiters
|
" Indent opening and closing delimiters
|
||||||
let [l:re_open, l:re_close] = vimtex#delim#get_valid_regexps(v:lnum, col('.'))
|
let [l:re_open, l:re_close] = vimtex#delim#get_valid_regexps(v:lnum, col('.'))
|
||||||
let ind += &sw*(
|
let l:ind += &sw*(
|
||||||
\ max([s:count(pline, l:re_open) - s:count(pline, l:re_close), 0])
|
\ max([s:count(l:prev, l:re_open) - s:count(l:prev, l:re_close), 0])
|
||||||
\ - max([s:count(cline, l:re_close) - s:count(cline, l:re_open), 0]))
|
\ - max([s:count(l:cur, l:re_close) - s:count(l:cur, l:re_open), 0]))
|
||||||
|
|
||||||
" Indent list items
|
" Indent list items
|
||||||
if pline =~# '^\s*\\\(bib\)\?item'
|
if l:prev =~# '^\s*\\\(bib\)\?item'
|
||||||
let ind += &sw
|
let l:ind += &sw
|
||||||
endif
|
endif
|
||||||
if cline =~# '^\s*\\\(bib\)\?item'
|
if l:cur =~# '^\s*\\\(bib\)\?item'
|
||||||
let ind -= &sw
|
let l:ind -= &sw
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Indent tikz elements
|
" Indent tikz elements
|
||||||
if pline =~# s:tikz_commands && pline !~# ';'
|
if l:prev =~# s:tikz_commands && l:prev !~# ';'
|
||||||
let ind += &sw
|
let l:ind += &sw
|
||||||
elseif pline !~# s:tikz_commands && pline =~# ';'
|
elseif l:prev !~# s:tikz_commands && l:prev =~# ';'
|
||||||
let ind -= &sw
|
let l:ind -= &sw
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ind
|
return l:ind
|
||||||
endfunction
|
endfunction
|
||||||
"}}}
|
"}}}
|
||||||
function! s:count(line, pattern) " {{{1
|
function! s:count(line, pattern) " {{{1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user