blob: f98e7556db0e08522fd51c3b32732df5ae701e7a [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
Bram Moolenaar42eeac32005-06-29 22:40:58 +00002" Language: reStructuredText Documentation Format
3" Maintainer: Nikolai Weibull <nikolai+work.vim@bitwi.se>
4" Latest Revision: 2005-06-29
Bram Moolenaar071d4272004-06-13 20:20:40 +00005
Bram Moolenaar071d4272004-06-13 20:20:40 +00006if exists("b:did_indent")
7 finish
8endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009let b:did_indent = 1
10
11setlocal indentexpr=GetRSTIndent()
Bram Moolenaar42eeac32005-06-29 22:40:58 +000012setlocal indentkeys=!^F,o,O
Bram Moolenaar071d4272004-06-13 20:20:40 +000013
Bram Moolenaar071d4272004-06-13 20:20:40 +000014if exists("*GetRSTIndent")
15 finish
16endif
17
18function GetRSTIndent()
19 let lnum = prevnonblank(v:lnum - 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +000020 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*', '', ''),
Bram Moolenaar42eeac32005-06-29 22:40:58 +000043 \ '\d\+\.\s\+')
Bram Moolenaar071d4272004-06-13 20:20:40 +000044 elseif line =~ '^\s*\.\.'
45 let ind = ind - 3
46 else
47 let ind = ind
48 endif
49 endif
50
51 return ind
52endfunction