annotate runtime/indent/rst.vim @ 30422:52b7188f13b1

Added tag v9.0.0546 for changeset 425b686c5244788b67d1205e696f6d04bedb0f24
author Bram Moolenaar <Bram@vim.org>
date Thu, 22 Sep 2022 17:15:04 +0200
parents 1908e92b02fd
children 5c220cf30f1f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim indent file
19968
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
2 " Vim reST indent file
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
3 " Language: reStructuredText Documentation Format
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
4 " Maintainer: Marshall Ward <marshall.ward@gmail.com>
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
5 " Previous Maintainer: Nikolai Weibull <now@bitwi.se>
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
6 " Latest Revision: 2020-03-31
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 setlocal indentexpr=GetRSTIndent()
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
14 setlocal indentkeys=!^F,o,O
1216
35a1d7bd6191 updated for version 7.1b
vimboss
parents: 856
diff changeset
15 setlocal nosmartindent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 if exists("*GetRSTIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
21 let s:itemization_pattern = '^\s*[-*+]\s'
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
22 let s:enumeration_pattern = '^\s*\%(\d\+\|#\)\.\s\+'
19968
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
23 let s:note_pattern = '^\.\. '
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
24
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
25 function! s:get_paragraph_start()
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
26 let paragraph_mark_start = getpos("'{")[1]
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
27 return getline(paragraph_mark_start) =~ '\S' ? paragraph_mark_start : paragraph_mark_start + 1
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
28 endfunction
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
29
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 function GetRSTIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 let lnum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 let line = getline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38
19968
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
39 let psnum = s:get_paragraph_start()
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
40 if psnum != 0
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
41 if getline(psnum) =~ s:note_pattern
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
42 let ind = 3
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
43 endif
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
44 endif
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
45
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
46 if line =~ s:itemization_pattern
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
47 let ind += 2
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
48 elseif line =~ s:enumeration_pattern
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
49 let ind += matchend(line, s:enumeration_pattern)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 let line = getline(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
54 " Indent :FIELD: lines. Don’t match if there is no text after the field or
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
55 " if the text ends with a sent-ender.
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
56 if line =~ '^:.\+:\s\{-1,\}\S.\+[^.!?:]$'
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
57 return matchend(line, '^:.\{-1,}:\s\+')
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
58 endif
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
59
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 if line =~ '^\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 execute lnum
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
62 call search('^\s*\%([-*+]\s\|\%(\d\+\|#\)\.\s\|\.\.\|$\)', 'bW')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 let line = getline('.')
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
64 if line =~ s:itemization_pattern
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
65 let ind -= 2
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
66 elseif line =~ s:enumeration_pattern
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
67 let ind -= matchend(line, s:enumeration_pattern)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 elseif line =~ '^\s*\.\.'
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
69 let ind -= 3
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 endfunction