7
|
1 " Vim indent file
|
19968
|
2 " Vim reST indent file
|
|
3 " Language: reStructuredText Documentation Format
|
|
4 " Maintainer: Marshall Ward <marshall.ward@gmail.com>
|
|
5 " Previous Maintainer: Nikolai Weibull <now@bitwi.se>
|
|
6 " Latest Revision: 2020-03-31
|
7
|
7
|
|
8 if exists("b:did_indent")
|
|
9 finish
|
|
10 endif
|
|
11 let b:did_indent = 1
|
|
12
|
|
13 setlocal indentexpr=GetRSTIndent()
|
375
|
14 setlocal indentkeys=!^F,o,O
|
1216
|
15 setlocal nosmartindent
|
7
|
16
|
|
17 if exists("*GetRSTIndent")
|
|
18 finish
|
|
19 endif
|
|
20
|
3082
|
21 let s:itemization_pattern = '^\s*[-*+]\s'
|
|
22 let s:enumeration_pattern = '^\s*\%(\d\+\|#\)\.\s\+'
|
19968
|
23 let s:note_pattern = '^\.\. '
|
|
24
|
|
25 function! 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
|
|
28 endfunction
|
3082
|
29
|
7
|
30 function 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
|
19968
|
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
|
3082
|
46 if line =~ s:itemization_pattern
|
|
47 let ind += 2
|
|
48 elseif line =~ s:enumeration_pattern
|
|
49 let ind += matchend(line, s:enumeration_pattern)
|
7
|
50 endif
|
|
51
|
|
52 let line = getline(v:lnum - 1)
|
|
53
|
3082
|
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
|
7
|
60 if line =~ '^\s*$'
|
|
61 execute lnum
|
3082
|
62 call search('^\s*\%([-*+]\s\|\%(\d\+\|#\)\.\s\|\.\.\|$\)', 'bW')
|
7
|
63 let line = getline('.')
|
3082
|
64 if line =~ s:itemization_pattern
|
|
65 let ind -= 2
|
|
66 elseif line =~ s:enumeration_pattern
|
|
67 let ind -= matchend(line, s:enumeration_pattern)
|
7
|
68 elseif line =~ '^\s*\.\.'
|
3082
|
69 let ind -= 3
|
7
|
70 endif
|
|
71 endif
|
|
72
|
|
73 return ind
|
|
74 endfunction
|