blob: e6fe2b554d61c1b93bda7a6f96cc2a773e21caf1 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00002" Language: reStructuredText Documentation Format
Bram Moolenaar57657d82006-04-21 22:12:41 +00003" Maintainer: Nikolai Weibull <now@bitwi.se>
4" Latest Revision: 2006-04-19
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 Moolenaarc9b4b052006-04-30 18:54:39 +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