blob: c1ef8c995785de7d41f11ce00d8212f6f8532bd1 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
Bram Moolenaar214641f2017-03-05 17:04:09 +01002" Language: reStructuredText Documentation Format
3" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
4" Latest Revision: 2011-08-03
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
Bram Moolenaar5302d9e2011-09-14 17:55:08 +020019let s:itemization_pattern = '^\s*[-*+]\s'
20let s:enumeration_pattern = '^\s*\%(\d\+\|#\)\.\s\+'
21
Bram Moolenaar071d4272004-06-13 20:20:40 +000022function GetRSTIndent()
23 let lnum = prevnonblank(v:lnum - 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +000024 if lnum == 0
25 return 0
26 endif
27
28 let ind = indent(lnum)
29 let line = getline(lnum)
30
Bram Moolenaar5302d9e2011-09-14 17:55:08 +020031 if line =~ s:itemization_pattern
32 let ind += 2
33 elseif line =~ s:enumeration_pattern
34 let ind += matchend(line, s:enumeration_pattern)
Bram Moolenaar071d4272004-06-13 20:20:40 +000035 endif
36
37 let line = getline(v:lnum - 1)
38
Bram Moolenaar5302d9e2011-09-14 17:55:08 +020039 " Indent :FIELD: lines. Don’t match if there is no text after the field or
40 " if the text ends with a sent-ender.
41 if line =~ '^:.\+:\s\{-1,\}\S.\+[^.!?:]$'
42 return matchend(line, '^:.\{-1,}:\s\+')
43 endif
44
Bram Moolenaar071d4272004-06-13 20:20:40 +000045 if line =~ '^\s*$'
46 execute lnum
Bram Moolenaar5302d9e2011-09-14 17:55:08 +020047 call search('^\s*\%([-*+]\s\|\%(\d\+\|#\)\.\s\|\.\.\|$\)', 'bW')
Bram Moolenaar071d4272004-06-13 20:20:40 +000048 let line = getline('.')
Bram Moolenaar5302d9e2011-09-14 17:55:08 +020049 if line =~ s:itemization_pattern
50 let ind -= 2
51 elseif line =~ s:enumeration_pattern
52 let ind -= matchend(line, s:enumeration_pattern)
Bram Moolenaar071d4272004-06-13 20:20:40 +000053 elseif line =~ '^\s*\.\.'
Bram Moolenaar5302d9e2011-09-14 17:55:08 +020054 let ind -= 3
Bram Moolenaar071d4272004-06-13 20:20:40 +000055 endif
56 endif
57
58 return ind
59endfunction