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