| 1 | " Vim indent file
|
|---|
| 2 | " Language: LaTeX
|
|---|
| 3 | " Maintainer: Johannes Tanzler <jtanzler@yline.com>
|
|---|
| 4 | " Created: Sat, 16 Feb 2002 16:50:19 +0100
|
|---|
| 5 | " Last Change: Sun, 17 Feb 2002 00:09:11 +0100
|
|---|
| 6 | " Last Update: 18th feb 2002, by LH :
|
|---|
| 7 | " (*) better support for the option
|
|---|
| 8 | " (*) use some regex instead of several '||'.
|
|---|
| 9 | " Version: 0.02
|
|---|
| 10 | " URL: comming soon: http://www.unet.univie.ac.at/~a9925098/vim/indent/tex.vim
|
|---|
| 11 |
|
|---|
| 12 | " --> If you're a Vim guru & and you find something that could be done in a
|
|---|
| 13 | " better (perhaps in a more Vim-ish or Vi-ish) way, please let me know!
|
|---|
| 14 |
|
|---|
| 15 | " Options: {{{
|
|---|
| 16 | "
|
|---|
| 17 | " To set the following options (ok, currently it's just one), add a line like
|
|---|
| 18 | " let g:tex_indent_items = 1
|
|---|
| 19 | " to your ~/.vimrc.
|
|---|
| 20 | "
|
|---|
| 21 | " * g:tex_indent_items
|
|---|
| 22 | "
|
|---|
| 23 | " If this variable is set, item-environments are indented like Emacs does
|
|---|
| 24 | " it, i.e., continuation lines are indented with a shiftwidth.
|
|---|
| 25 | "
|
|---|
| 26 | " NOTE: I've already set the variable below; delete the corresponding line
|
|---|
| 27 | " if you don't like this behaviour.
|
|---|
| 28 | "
|
|---|
| 29 | " Per default, it is unset.
|
|---|
| 30 | "
|
|---|
| 31 | " set unset
|
|---|
| 32 | " ----------------------------------------------------------------
|
|---|
| 33 | " \begin{itemize} \begin{itemize}
|
|---|
| 34 | " \item blablabla \item blablabla
|
|---|
| 35 | " bla bla bla bla bla bla
|
|---|
| 36 | " \item blablabla \item blablabla
|
|---|
| 37 | " bla bla bla bla bla bla
|
|---|
| 38 | " \end{itemize} \end{itemize}
|
|---|
| 39 | "
|
|---|
| 40 | "
|
|---|
| 41 | " This option applies to itemize, description, enumerate, and
|
|---|
| 42 | " thebibliography.
|
|---|
| 43 | "
|
|---|
| 44 | " }}}
|
|---|
| 45 |
|
|---|
| 46 | " Delete the next line to avoid the special indention of items
|
|---|
| 47 | if !exists("g:tex_indent_items")
|
|---|
| 48 | let g:tex_indent_items = 1
|
|---|
| 49 | endif
|
|---|
| 50 |
|
|---|
| 51 | if exists("b:did_indent") | finish
|
|---|
| 52 | endif
|
|---|
| 53 | let b:did_indent = 1
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | setlocal indentexpr=GetTeXIndent()
|
|---|
| 57 | setlocal nolisp
|
|---|
| 58 | setlocal nosmartindent
|
|---|
| 59 | setlocal autoindent
|
|---|
| 60 | setlocal indentkeys+=},=\\item,=\\bibitem
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 | " Only define the function once
|
|---|
| 64 | if exists("*GetTeXIndent") | finish
|
|---|
| 65 | endif
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 | function GetTeXIndent()
|
|---|
| 70 |
|
|---|
| 71 | " Find a non-blank line above the current line.
|
|---|
| 72 | let lnum = prevnonblank(v:lnum - 1)
|
|---|
| 73 |
|
|---|
| 74 | " At the start of the file use zero indent.
|
|---|
| 75 | if lnum == 0 | return 0
|
|---|
| 76 | endif
|
|---|
| 77 |
|
|---|
| 78 | let ind = indent(lnum)
|
|---|
| 79 | let line = getline(lnum) " last line
|
|---|
| 80 | let cline = getline(v:lnum) " current line
|
|---|
| 81 |
|
|---|
| 82 | " Do not change indentation of commented lines.
|
|---|
| 83 | if line =~ '^\s*%'
|
|---|
| 84 | return ind
|
|---|
| 85 | endif
|
|---|
| 86 |
|
|---|
| 87 | " Add a 'shiftwidth' after beginning of environments.
|
|---|
| 88 | " Don't add it for \begin{document} and \begin{verbatim}
|
|---|
| 89 | ""if line =~ '^\s*\\begin{\(.*\)}' && line !~ 'verbatim'
|
|---|
| 90 | " LH modification : \begin does not always start a line
|
|---|
| 91 | if line =~ '\\begin{\(.*\)}' && line !~ 'verbatim'
|
|---|
| 92 | \ && line !~ 'document'
|
|---|
| 93 |
|
|---|
| 94 | let ind = ind + &sw
|
|---|
| 95 |
|
|---|
| 96 | if g:tex_indent_items == 1
|
|---|
| 97 | " Add another sw for item-environments
|
|---|
| 98 | if line =~ 'itemize\|description\|enumerate\|thebibliography'
|
|---|
| 99 | let ind = ind + &sw
|
|---|
| 100 | endif
|
|---|
| 101 | endif
|
|---|
| 102 | endif
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 | " Subtract a 'shiftwidth' when an environment ends
|
|---|
| 106 | if cline =~ '^\s*\\end' && cline !~ 'verbatim'
|
|---|
| 107 | \&& cline !~ 'document'
|
|---|
| 108 |
|
|---|
| 109 | if g:tex_indent_items == 1
|
|---|
| 110 | " Remove another sw for item-environments
|
|---|
| 111 | if cline =~ 'itemize\|description\|enumerate\|thebibliography'
|
|---|
| 112 | let ind = ind - &sw
|
|---|
| 113 | endif
|
|---|
| 114 | endif
|
|---|
| 115 |
|
|---|
| 116 | let ind = ind - &sw
|
|---|
| 117 | endif
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 | " Special treatment for 'item'
|
|---|
| 121 | " ----------------------------
|
|---|
| 122 |
|
|---|
| 123 | if g:tex_indent_items == 1
|
|---|
| 124 |
|
|---|
| 125 | " '\item' or '\bibitem' itself:
|
|---|
| 126 | if cline =~ '^\s*\\\(bib\)\=item'
|
|---|
| 127 | let ind = ind - &sw
|
|---|
| 128 | endif
|
|---|
| 129 |
|
|---|
| 130 | " lines following to '\item' are intented once again:
|
|---|
| 131 | if line =~ '^\s*\\\(bib\)\=item'
|
|---|
| 132 | let ind = ind + &sw
|
|---|
| 133 | endif
|
|---|
| 134 |
|
|---|
| 135 | endif
|
|---|
| 136 |
|
|---|
| 137 | return ind
|
|---|
| 138 | endfunction
|
|---|
| 139 |
|
|---|