1" Vim indent file 2" Language: reStructuredText Documentation Format 3" Maintainer: Nikolai Weibull <[email protected]> 4" Latest Revision: 2011-08-03 5 6if exists("b:did_indent") 7 finish 8endif 9let b:did_indent = 1 10 11setlocal indentexpr=GetRSTIndent() 12setlocal indentkeys=!^F,o,O 13setlocal nosmartindent 14 15if exists("*GetRSTIndent") 16 finish 17endif 18 19let s:itemization_pattern = '^\s*[-*+]\s' 20let s:enumeration_pattern = '^\s*\%(\d\+\|#\)\.\s\+' 21 22function GetRSTIndent() 23 let lnum = prevnonblank(v:lnum - 1) 24 if lnum == 0 25 return 0 26 endif 27 28 let ind = indent(lnum) 29 let line = getline(lnum) 30 31 if line =~ s:itemization_pattern 32 let ind += 2 33 elseif line =~ s:enumeration_pattern 34 let ind += matchend(line, s:enumeration_pattern) 35 endif 36 37 let line = getline(v:lnum - 1) 38 39 " Indent :FIELD: lines. Don’t match if there is no text after the field or 40 " if the text ends with a sent-ender. 41 if line =~ '^:.\+:\s\{-1,\}\S.\+[^.!?:]$' 42 return matchend(line, '^:.\{-1,}:\s\+') 43 endif 44 45 if line =~ '^\s*$' 46 execute lnum 47 call search('^\s*\%([-*+]\s\|\%(\d\+\|#\)\.\s\|\.\.\|$\)', 'bW') 48 let line = getline('.') 49 if line =~ s:itemization_pattern 50 let ind -= 2 51 elseif line =~ s:enumeration_pattern 52 let ind -= matchend(line, s:enumeration_pattern) 53 elseif line =~ '^\s*\.\.' 54 let ind -= 3 55 endif 56 endif 57 58 return ind 59endfunction 60