7
|
1 " Vim indent file
|
1216
|
2 " Language: reStructuredText Documentation Format
|
839
|
3 " Maintainer: Nikolai Weibull <now@bitwi.se>
|
3082
|
4 " Latest Revision: 2011-08-03
|
7
|
5
|
|
6 if exists("b:did_indent")
|
|
7 finish
|
|
8 endif
|
|
9 let b:did_indent = 1
|
|
10
|
|
11 setlocal indentexpr=GetRSTIndent()
|
375
|
12 setlocal indentkeys=!^F,o,O
|
1216
|
13 setlocal nosmartindent
|
7
|
14
|
|
15 if exists("*GetRSTIndent")
|
|
16 finish
|
|
17 endif
|
|
18
|
3082
|
19 let s:itemization_pattern = '^\s*[-*+]\s'
|
|
20 let s:enumeration_pattern = '^\s*\%(\d\+\|#\)\.\s\+'
|
|
21
|
7
|
22 function 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
|
3082
|
31 if line =~ s:itemization_pattern
|
|
32 let ind += 2
|
|
33 elseif line =~ s:enumeration_pattern
|
|
34 let ind += matchend(line, s:enumeration_pattern)
|
7
|
35 endif
|
|
36
|
|
37 let line = getline(v:lnum - 1)
|
|
38
|
3082
|
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
|
7
|
45 if line =~ '^\s*$'
|
|
46 execute lnum
|
3082
|
47 call search('^\s*\%([-*+]\s\|\%(\d\+\|#\)\.\s\|\.\.\|$\)', 'bW')
|
7
|
48 let line = getline('.')
|
3082
|
49 if line =~ s:itemization_pattern
|
|
50 let ind -= 2
|
|
51 elseif line =~ s:enumeration_pattern
|
|
52 let ind -= matchend(line, s:enumeration_pattern)
|
7
|
53 elseif line =~ '^\s*\.\.'
|
3082
|
54 let ind -= 3
|
7
|
55 endif
|
|
56 endif
|
|
57
|
|
58 return ind
|
|
59 endfunction
|