annotate runtime/indent/rst.vim @ 35042:efef66876fb4

Added tag v9.1.0370 for changeset e671080ef0e2e8d92a05044905761b1414755cf5
author Christian Brabandt <cb@256bit.org>
date Thu, 25 Apr 2024 21:30:12 +0200
parents 5c220cf30f1f
children
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
33052
5c220cf30f1f runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents: 19968
diff changeset
7 " 2023 Aug 28 by Vim Project (undo_indent)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 setlocal indentexpr=GetRSTIndent()
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
15 setlocal indentkeys=!^F,o,O
1216
35a1d7bd6191 updated for version 7.1b
vimboss
parents: 856
diff changeset
16 setlocal nosmartindent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
33052
5c220cf30f1f runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents: 19968
diff changeset
18 let b:undo_indent = "setlocal indentexpr< indentkeys< smartindent<"
5c220cf30f1f runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents: 19968
diff changeset
19
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 if exists("*GetRSTIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
24 let s:itemization_pattern = '^\s*[-*+]\s'
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
25 let s:enumeration_pattern = '^\s*\%(\d\+\|#\)\.\s\+'
19968
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
26 let s:note_pattern = '^\.\. '
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
27
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
28 function! s:get_paragraph_start()
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
29 let paragraph_mark_start = getpos("'{")[1]
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
30 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
31 endfunction
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
32
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 function GetRSTIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 let lnum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 let line = getline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
19968
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
42 let psnum = s:get_paragraph_start()
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
43 if psnum != 0
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
44 if getline(psnum) =~ s:note_pattern
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
45 let ind = 3
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
46 endif
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
47 endif
1908e92b02fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11062
diff changeset
48
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
49 if line =~ s:itemization_pattern
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
50 let ind += 2
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
51 elseif line =~ s:enumeration_pattern
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
52 let ind += matchend(line, s:enumeration_pattern)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 let line = getline(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
57 " 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
58 " if the text ends with a sent-ender.
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
59 if line =~ '^:.\+:\s\{-1,\}\S.\+[^.!?:]$'
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
60 return matchend(line, '^:.\{-1,}:\s\+')
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
61 endif
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
62
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 if line =~ '^\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 execute lnum
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
65 call search('^\s*\%([-*+]\s\|\%(\d\+\|#\)\.\s\|\.\.\|$\)', 'bW')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 let line = getline('.')
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
67 if line =~ s:itemization_pattern
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
68 let ind -= 2
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
69 elseif line =~ s:enumeration_pattern
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
70 let ind -= matchend(line, s:enumeration_pattern)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 elseif line =~ '^\s*\.\.'
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1216
diff changeset
72 let ind -= 3
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 endfunction