From c47ddda2f685a41fd1f39e5ddfb53dc76658690f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 10 Oct 2013 14:47:08 +0200 Subject: [PATCH] Added an improved indent function --- indent/tex.vim | 154 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 indent/tex.vim diff --git a/indent/tex.vim b/indent/tex.vim new file mode 100644 index 0000000..e72c028 --- /dev/null +++ b/indent/tex.vim @@ -0,0 +1,154 @@ +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 +let s:cpo_save = &cpo +set cpo&vim + +" {{{1 Options and common patterns +setlocal autoindent +setlocal indentexpr=s:indent() +setlocal indentkeys& +setlocal indentkeys+=[,(,{,),},],\&,0=item + +" Define some common patterns +let s:envs_lists = 'itemize\|description\|enumerate\|thebibliography' +let s:envs_noindent = 'document\|verbatim\|lstlisting' +let s:delimiters_open = '\(' . join([ + \ '{', + \ '(', + \ '\[', + \ '\\{', + \ '\\(', + \ '\\\[', + \ '\\\Cbegin\s*{.\{-}}', + \ '\\\Cleft\s*\%([^\\]\|\\.\|\\\a*\)', + \ '\\\cbigg\?\((\|\[\|\\{\)', + \ ], '\|') . '\)' +let s:delimiters_close = '\(' . join([ + \ '}', + \ ')', + \ '\]', + \ '\\}', + \ '\\)', + \ '\\\]', + \ '\\\Cend\s*{.\{-}}', + \ '\\\Cright\s*\%([^\\]\|\\.\|\\\a*\)', + \ '\\\cbigg\?\()\|\]\|\\}\)', + \ ], '\|') . '\)' +" }}}1 + +" {{{1 s:indent +function! s:indent() + " Find a non-blank non-comment line above the current line + let lnum = prevnonblank(v:lnum - 1) + while lnum != 0 && getline(lnum) =~ '^\s*%' + let lnum = prevnonblank(lnum - 1) + endwhile + + " Zero indent for top of file + if lnum == 0 + return 0 + endif + + " Get current and previous line, remove comments + let cline = substitute(getline(v:lnum), '\\\@= 0 + let sum += 1 + let match = matchstr(a:line, a:pattern, indx) + let indx += len(match) + let indx = match(a:line, a:pattern, indx) + endwhile + return sum +endfunction +" }}}1 + +let &cpo = s:cpo_save +unlet s:cpo_save + +" vim:fdm=marker:ff=unix