7
|
1 " Vim indent file
|
375
|
2 " Language: reStructuredText Documentation Format
|
|
3 " Maintainer: Nikolai Weibull <nikolai+work.vim@bitwi.se>
|
|
4 " Latest Revision: 2005-06-29
|
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
|
7
|
13
|
|
14 if exists("*GetRSTIndent")
|
|
15 finish
|
|
16 endif
|
|
17
|
|
18 function GetRSTIndent()
|
|
19 let lnum = prevnonblank(v:lnum - 1)
|
|
20 if lnum == 0
|
|
21 return 0
|
|
22 endif
|
|
23
|
|
24 let ind = indent(lnum)
|
|
25 let line = getline(lnum)
|
|
26
|
|
27 if line =~ '^\s*[-*+]\s'
|
|
28 let ind = ind + 2
|
|
29 elseif line =~ '^\s*\d\+.\s'
|
|
30 let ind = ind + matchend(substitute(line, '^\s*', '', ''), '\d\+.\s\+')
|
|
31 endif
|
|
32
|
|
33 let line = getline(v:lnum - 1)
|
|
34
|
|
35 if line =~ '^\s*$'
|
|
36 execute lnum
|
|
37 call search('^\s*\%([-*+]\s\|\d\+.\s\|\.\.\|$\)', 'bW')
|
|
38 let line = getline('.')
|
|
39 if line =~ '^\s*[-*+]'
|
|
40 let ind = ind - 2
|
|
41 elseif line =~ '^\s*\d\+\.\s'
|
|
42 let ind = ind - matchend(substitute(line, '^\s*', '', ''),
|
375
|
43 \ '\d\+\.\s\+')
|
7
|
44 elseif line =~ '^\s*\.\.'
|
|
45 let ind = ind - 3
|
|
46 else
|
|
47 let ind = ind
|
|
48 endif
|
|
49 endif
|
|
50
|
|
51 return ind
|
|
52 endfunction
|