Mercurial > vim
annotate runtime/syntax/rst.vim @ 20423:8c98c74176ac v8.2.0766
patch 8.2.0766: display error when using 'number' and 'breakindent'
Commit: https://github.com/vim/vim/commit/e882f7a73c8fa48707de71035eb0a7ccc6ac8548
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat May 16 14:07:39 2020 +0200
patch 8.2.0766: display error when using 'number' and 'breakindent'
Problem: Display error when using 'number' and 'breakindent'.
Solution: Adjust extra spaces in the first row. (Ken Takata, closes https://github.com/vim/vim/issues/6089,
closes #5986)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 16 May 2020 14:15:06 +0200 |
parents | 1908e92b02fd |
children |
rev | line source |
---|---|
19968 | 1 " Vim reST syntax file |
6292
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
2 " Language: reStructuredText documentation format |
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
3 " Maintainer: Marshall Ward <marshall.ward@gmail.com> |
6159 | 4 " Previous Maintainer: Nikolai Weibull <now@bitwi.se> |
9908
2b6654519a7c
commit https://github.com/vim/vim/commit/7571d55f7dcc009a375b2124cce2c8b21f361234
Christian Brabandt <cb@256bit.org>
parents:
9319
diff
changeset
|
5 " Website: https://github.com/marshallward/vim-restructuredtext |
19968 | 6 " Latest Revision: 2020-03-31 |
7 | 7 |
375 | 8 if exists("b:current_syntax") |
7 | 9 finish |
10 endif | |
11 | |
375 | 12 let s:cpo_save = &cpo |
13 set cpo&vim | |
14 | |
7 | 15 syn case ignore |
16 | |
2034 | 17 syn match rstTransition /^[=`:.'"~^_*+#-]\{4,}\s*$/ |
825 | 18 |
19 syn cluster rstCruft contains=rstEmphasis,rstStrongEmphasis, | |
20 \ rstInterpretedText,rstInlineLiteral,rstSubstitutionReference, | |
21 \ rstInlineInternalTargets,rstFootnoteReference,rstHyperlinkReference | |
7 | 22 |
825 | 23 syn region rstLiteralBlock matchgroup=rstDelimiter |
19968 | 24 \ start='\(^\z(\s*\).*\)\@<=::\n\s*\n' skip='^\s*$' end='^\(\z1\s\+\)\@!' |
825 | 25 \ contains=@NoSpell |
7 | 26 |
825 | 27 syn region rstQuotedLiteralBlock matchgroup=rstDelimiter |
28 \ start="::\_s*\n\ze\z([!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]\)" | |
29 \ end='^\z1\@!' contains=@NoSpell | |
30 | |
31 syn region rstDoctestBlock oneline display matchgroup=rstDelimiter | |
32 \ start='^>>>\s' end='^$' | |
33 | |
34 syn region rstTable transparent start='^\n\s*+[-=+]\+' end='^$' | |
35 \ contains=rstTableLines,@rstCruft | |
36 syn match rstTableLines contained display '|\|+\%(=\+\|-\+\)\=' | |
375 | 37 |
825 | 38 syn region rstSimpleTable transparent |
39 \ start='^\n\%(\s*\)\@>\%(\%(=\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(=\+\)\@>\%(\s*\)\@>\)\+\)\@>$' | |
40 \ end='^$' | |
41 \ contains=rstSimpleTableLines,@rstCruft | |
42 syn match rstSimpleTableLines contained display | |
43 \ '^\%(\s*\)\@>\%(\%(=\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(=\+\)\@>\%(\s*\)\@>\)\+\)\@>$' | |
44 syn match rstSimpleTableLines contained display | |
45 \ '^\%(\s*\)\@>\%(\%(-\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(-\+\)\@>\%(\s*\)\@>\)\+\)\@>$' | |
46 | |
47 syn cluster rstDirectives contains=rstFootnote,rstCitation, | |
48 \ rstHyperlinkTarget,rstExDirective | |
49 | |
6159 | 50 syn match rstExplicitMarkup '^\s*\.\.\_s' |
825 | 51 \ nextgroup=@rstDirectives,rstComment,rstSubstitutionDefinition |
52 | |
14421 | 53 " "Simple reference names are single words consisting of alphanumerics plus |
54 " isolated (no two adjacent) internal hyphens, underscores, periods, colons | |
55 " and plus signs." | |
56 let s:ReferenceName = '[[:alnum:]]\%([-_.:+]\?[[:alnum:]]\+\)*' | |
7 | 57 |
825 | 58 syn keyword rstTodo contained FIXME TODO XXX NOTE |
59 | |
60 execute 'syn region rstComment contained' . | |
61 \ ' start=/.*/' | |
15334 | 62 \ ' skip=+^$+' . |
825 | 63 \ ' end=/^\s\@!/ contains=rstTodo' |
64 | |
65 execute 'syn region rstFootnote contained matchgroup=rstDirective' . | |
66 \ ' start=+\[\%(\d\+\|#\%(' . s:ReferenceName . '\)\=\|\*\)\]\_s+' . | |
67 \ ' skip=+^$+' . | |
68 \ ' end=+^\s\@!+ contains=@rstCruft,@NoSpell' | |
69 | |
70 execute 'syn region rstCitation contained matchgroup=rstDirective' . | |
71 \ ' start=+\[' . s:ReferenceName . '\]\_s+' . | |
72 \ ' skip=+^$+' . | |
73 \ ' end=+^\s\@!+ contains=@rstCruft,@NoSpell' | |
74 | |
75 syn region rstHyperlinkTarget contained matchgroup=rstDirective | |
76 \ start='_\%(_\|[^:\\]*\%(\\.[^:\\]*\)*\):\_s' skip=+^$+ end=+^\s\@!+ | |
7 | 77 |
825 | 78 syn region rstHyperlinkTarget contained matchgroup=rstDirective |
79 \ start='_`[^`\\]*\%(\\.[^`\\]*\)*`:\_s' skip=+^$+ end=+^\s\@!+ | |
80 | |
81 syn region rstHyperlinkTarget matchgroup=rstDirective | |
82 \ start=+^__\_s+ skip=+^$+ end=+^\s\@!+ | |
83 | |
84 execute 'syn region rstExDirective contained matchgroup=rstDirective' . | |
85 \ ' start=+' . s:ReferenceName . '::\_s+' . | |
86 \ ' skip=+^$+' . | |
7100
f717d96a39b3
commit https://github.com/vim/vim/commit/12969c04fe7bd27dc0cbf37709eb40a86d4a27f9
Christian Brabandt <cb@256bit.org>
parents:
6292
diff
changeset
|
87 \ ' end=+^\s\@!+ contains=@rstCruft,rstLiteralBlock' |
7 | 88 |
825 | 89 execute 'syn match rstSubstitutionDefinition contained' . |
14421 | 90 \ ' /|.*|\_s\+/ nextgroup=@rstDirectives' |
7 | 91 |
825 | 92 function! s:DefineOneInlineMarkup(name, start, middle, end, char_left, char_right) |
19968 | 93 " Only escape the first char of a multichar delimiter (e.g. \* inside **) |
94 if a:start[0] == '\' | |
95 let first = a:start[0:1] | |
96 else | |
97 let first = a:start[0] | |
98 endif | |
99 | |
100 execute 'syn match rstEscape'.a:name.' +\\\\\|\\'.first.'+'.' contained' | |
101 | |
825 | 102 execute 'syn region rst' . a:name . |
103 \ ' start=+' . a:char_left . '\zs' . a:start . | |
1224 | 104 \ '\ze[^[:space:]' . a:char_right . a:start[strlen(a:start) - 1] . ']+' . |
825 | 105 \ a:middle . |
19968 | 106 \ ' end=+' . a:end . '\ze\%($\|\s\|[''"’)\]}>/:.,;!?\\-]\)+' . |
107 \ ' contains=rstEscape' . a:name | |
108 | |
109 execute 'hi def link rstEscape'.a:name.' Special' | |
825 | 110 endfunction |
111 | |
112 function! s:DefineInlineMarkup(name, start, middle, end) | |
113 let middle = a:middle != "" ? | |
19968 | 114 \ (' skip=+\\\\\|\\' . a:middle . '\|\s' . a:middle . '+') : |
825 | 115 \ "" |
7 | 116 |
825 | 117 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, "'", "'") |
6159 | 118 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '"', '"') |
119 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '(', ')') | |
120 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '\[', '\]') | |
121 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '{', '}') | |
122 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '<', '>') | |
9908
2b6654519a7c
commit https://github.com/vim/vim/commit/7571d55f7dcc009a375b2124cce2c8b21f361234
Christian Brabandt <cb@256bit.org>
parents:
9319
diff
changeset
|
123 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '’', '’') |
2b6654519a7c
commit https://github.com/vim/vim/commit/7571d55f7dcc009a375b2124cce2c8b21f361234
Christian Brabandt <cb@256bit.org>
parents:
9319
diff
changeset
|
124 " TODO: Additional Unicode Pd, Po, Pi, Pf, Ps characters |
7 | 125 |
14421 | 126 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '\%(^\|\s\|\%ua0\|[/:]\)', '') |
825 | 127 |
128 execute 'syn match rst' . a:name . | |
14421 | 129 \ ' +\%(^\|\s\|\%ua0\|[''"([{</:]\)\zs' . a:start . |
825 | 130 \ '[^[:space:]' . a:start[strlen(a:start) - 1] . ']' |
131 \ a:end . '\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+' | |
132 | |
133 execute 'hi def link rst' . a:name . 'Delimiter' . ' rst' . a:name | |
134 endfunction | |
7 | 135 |
825 | 136 call s:DefineInlineMarkup('Emphasis', '\*', '\*', '\*') |
137 call s:DefineInlineMarkup('StrongEmphasis', '\*\*', '\*', '\*\*') | |
138 call s:DefineInlineMarkup('InterpretedTextOrHyperlinkReference', '`', '`', '`_\{0,2}') | |
139 call s:DefineInlineMarkup('InlineLiteral', '``', "", '``') | |
140 call s:DefineInlineMarkup('SubstitutionReference', '|', '|', '|_\{0,2}') | |
141 call s:DefineInlineMarkup('InlineInternalTargets', '_`', '`', '`') | |
142 | |
14421 | 143 " Sections are identified through their titles, which are marked up with |
144 " adornment: "underlines" below the title text, or underlines and matching | |
145 " "overlines" above the title. An underline/overline is a single repeated | |
146 " punctuation character that begins in column 1 and forms a line extending at | |
147 " least as far as the right edge of the title text. | |
148 " | |
149 " It is difficult to count characters in a regex, but we at least special-case | |
150 " the case where the title has at least three characters to require the | |
151 " adornment to have at least three characters as well, in order to handle | |
152 " properly the case of a literal block: | |
153 " | |
154 " this is the end of a paragraph | |
155 " :: | |
156 " this is a literal block | |
157 syn match rstSections "\v^%(([=`:.'"~^_*+#-])\1+\n)?.{1,2}\n([=`:.'"~^_*+#-])\2+$" | |
158 \ contains=@Spell | |
159 syn match rstSections "\v^%(([=`:.'"~^_*+#-])\1{2,}\n)?.{3,}\n([=`:.'"~^_*+#-])\2{2,}$" | |
160 \ contains=@Spell | |
7597
3012eaddb6b2
commit https://github.com/vim/vim/commit/345efa013dc6d1754ba06e5596a26c48c9935937
Christian Brabandt <cb@256bit.org>
parents:
7100
diff
changeset
|
161 |
825 | 162 " TODO: Can’t remember why these two can’t be defined like the ones above. |
163 execute 'syn match rstFootnoteReference contains=@NoSpell' . | |
14421 | 164 \ ' +\%(\s\|^\)\[\%(\d\+\|#\%(' . s:ReferenceName . '\)\=\|\*\)\]_+' |
7 | 165 |
825 | 166 execute 'syn match rstCitationReference contains=@NoSpell' . |
14421 | 167 \ ' +\%(\s\|^\)\[' . s:ReferenceName . '\]_\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+' |
825 | 168 |
169 execute 'syn match rstHyperlinkReference' . | |
1224 | 170 \ ' /\<' . s:ReferenceName . '__\=\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)/' |
375 | 171 |
825 | 172 syn match rstStandaloneHyperlink contains=@NoSpell |
173 \ "\<\%(\%(\%(https\=\|file\|ftp\|gopher\)://\|\%(mailto\|news\):\)[^[:space:]'\"<>]\+\|www[[:alnum:]_-]*\.[[:alnum:]_-]\+\.[^[:space:]'\"<>]\+\)[[:alnum:]/]" | |
7 | 174 |
3920 | 175 syn region rstCodeBlock contained matchgroup=rstDirective |
19968 | 176 \ start=+\%(sourcecode\|code\%(-block\)\=\)::\s*\(\S*\)\?\s*\n\%(\s*:.*:\s*.*\s*\n\)*\n\ze\z(\s\+\)+ |
3920 | 177 \ skip=+^$+ |
6159 | 178 \ end=+^\z1\@!+ |
3920 | 179 \ contains=@NoSpell |
180 syn cluster rstDirectives add=rstCodeBlock | |
181 | |
182 if !exists('g:rst_syntax_code_list') | |
14421 | 183 " A mapping from a Vim filetype to a list of alias patterns (pattern |
184 " branches to be specific, see ':help /pattern'). E.g. given: | |
185 " | |
186 " let g:rst_syntax_code_list = { | |
187 " \ 'cpp': ['cpp', 'c++'], | |
188 " \ } | |
189 " | |
190 " then the respective contents of the following two rST directives: | |
191 " | |
192 " .. code:: cpp | |
193 " | |
194 " auto i = 42; | |
195 " | |
196 " .. code:: C++ | |
197 " | |
198 " auto i = 42; | |
199 " | |
200 " will both be highlighted as C++ code. As shown by the latter block | |
201 " pattern matching will be case-insensitive. | |
202 let g:rst_syntax_code_list = { | |
203 \ 'vim': ['vim'], | |
204 \ 'java': ['java'], | |
205 \ 'cpp': ['cpp', 'c++'], | |
206 \ 'lisp': ['lisp'], | |
207 \ 'php': ['php'], | |
208 \ 'python': ['python'], | |
209 \ 'perl': ['perl'], | |
210 \ 'sh': ['sh'], | |
211 \ } | |
212 elseif type(g:rst_syntax_code_list) == type([]) | |
213 " backward compatibility with former list format | |
214 let s:old_spec = g:rst_syntax_code_list | |
215 let g:rst_syntax_code_list = {} | |
216 for s:elem in s:old_spec | |
217 let g:rst_syntax_code_list[s:elem] = [s:elem] | |
218 endfor | |
3920 | 219 endif |
220 | |
14421 | 221 for s:filetype in keys(g:rst_syntax_code_list) |
3920 | 222 unlet! b:current_syntax |
6292
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
223 " guard against setting 'isk' option which might cause problems (issue #108) |
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
224 let prior_isk = &l:iskeyword |
14421 | 225 let s:alias_pattern = '' |
226 \.'\%(' | |
227 \.join(g:rst_syntax_code_list[s:filetype], '\|') | |
228 \.'\)' | |
229 | |
230 exe 'syn include @rst'.s:filetype.' syntax/'.s:filetype.'.vim' | |
231 exe 'syn region rstDirective'.s:filetype | |
232 \.' matchgroup=rstDirective fold' | |
233 \.' start="\c\%(sourcecode\|code\%(-block\)\=\)::\s\+'.s:alias_pattern.'\_s*\n\ze\z(\s\+\)"' | |
9319
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
7597
diff
changeset
|
234 \.' skip=#^$#' |
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
7597
diff
changeset
|
235 \.' end=#^\z1\@!#' |
14421 | 236 \.' contains=@NoSpell,@rst'.s:filetype |
237 exe 'syn cluster rstDirectives add=rstDirective'.s:filetype | |
238 | |
6292
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
239 " reset 'isk' setting, if it has been changed |
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
240 if &l:iskeyword !=# prior_isk |
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
241 let &l:iskeyword = prior_isk |
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
242 endif |
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
243 unlet! prior_isk |
3920 | 244 endfor |
245 | |
14421 | 246 " Enable top level spell checking |
247 syntax spell toplevel | |
248 | |
4780 | 249 " TODO: Use better syncing. |
250 syn sync minlines=50 linebreaks=2 | |
251 | |
825 | 252 hi def link rstTodo Todo |
253 hi def link rstComment Comment | |
3750 | 254 hi def link rstSections Title |
255 hi def link rstTransition rstSections | |
825 | 256 hi def link rstLiteralBlock String |
257 hi def link rstQuotedLiteralBlock String | |
258 hi def link rstDoctestBlock PreProc | |
259 hi def link rstTableLines rstDelimiter | |
260 hi def link rstSimpleTableLines rstTableLines | |
261 hi def link rstExplicitMarkup rstDirective | |
262 hi def link rstDirective Keyword | |
263 hi def link rstFootnote String | |
264 hi def link rstCitation String | |
265 hi def link rstHyperlinkTarget String | |
266 hi def link rstExDirective String | |
267 hi def link rstSubstitutionDefinition rstDirective | |
268 hi def link rstDelimiter Delimiter | |
269 hi def link rstInterpretedTextOrHyperlinkReference Identifier | |
270 hi def link rstInlineLiteral String | |
271 hi def link rstSubstitutionReference PreProc | |
272 hi def link rstInlineInternalTargets Identifier | |
273 hi def link rstFootnoteReference Identifier | |
274 hi def link rstCitationReference Identifier | |
275 hi def link rstHyperLinkReference Identifier | |
276 hi def link rstStandaloneHyperlink Identifier | |
3920 | 277 hi def link rstCodeBlock String |
14421 | 278 if exists('g:rst_use_emphasis_colors') |
279 " TODO: Less arbitrary color selection | |
280 hi def rstEmphasis ctermfg=13 term=italic cterm=italic gui=italic | |
281 hi def rstStrongEmphasis ctermfg=1 term=bold cterm=bold gui=bold | |
282 else | |
283 hi def rstEmphasis term=italic cterm=italic gui=italic | |
284 hi def rstStrongEmphasis term=bold cterm=bold gui=bold | |
285 endif | |
7 | 286 |
287 let b:current_syntax = "rst" | |
288 | |
375 | 289 let &cpo = s:cpo_save |
290 unlet s:cpo_save |