blob: f936c9b2f60554da425cdcbdc150f3565ce56ee7 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
Bram Moolenaar335437b2007-05-10 18:32:52 +00002" Language: reStructuredText Documentation Format
Bram Moolenaar57657d82006-04-21 22:12:41 +00003" Maintainer: Nikolai Weibull <now@bitwi.se>
Bram Moolenaar335437b2007-05-10 18:32:52 +00004" Latest Revision: 2006-12-20
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 Moolenaar335437b2007-05-10 18:32:52 +000013setlocal nosmartindent
Bram Moolenaar071d4272004-06-13 20:20:40 +000014
Bram Moolenaar071d4272004-06-13 20:20:40 +000015if exists("*GetRSTIndent")
16 finish
17endif
18
19function GetRSTIndent()
20 let lnum = prevnonblank(v:lnum - 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +000021 if lnum == 0
22 return 0
23 endif
24
25 let ind = indent(lnum)
26 let line = getline(lnum)
27
28 if line =~ '^\s*[-*+]\s'
29 let ind = ind + 2
30 elseif line =~ '^\s*\d\+.\s'
31 let ind = ind + matchend(substitute(line, '^\s*', '', ''), '\d\+.\s\+')
32 endif
33
34 let line = getline(v:lnum - 1)
35
36 if line =~ '^\s*$'
37 execute lnum
38 call search('^\s*\%([-*+]\s\|\d\+.\s\|\.\.\|$\)', 'bW')
39 let line = getline('.')
40 if line =~ '^\s*[-*+]'
41 let ind = ind - 2
42 elseif line =~ '^\s*\d\+\.\s'
43 let ind = ind - matchend(substitute(line, '^\s*', '', ''),
Bram Moolenaar335437b2007-05-10 18:32:52 +000044 \ '\d\+\.\s\+')
Bram Moolenaar071d4272004-06-13 20:20:40 +000045 elseif line =~ '^\s*\.\.'
46 let ind = ind - 3
47 else
48 let ind = ind
49 endif
50 endif
51
52 return ind
53endfunction