summaryrefslogtreecommitdiff
path: root/runtime/syntax/rst.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-07-29 15:07:52 +0200
committerBram Moolenaar <Bram@vim.org>2018-07-29 15:07:52 +0200
commit91f84f6e11cd879d43d651c0903d85bff95f0716 (patch)
tree3c38a15ec4665ac5ed69454e41bd3347f41e800e /runtime/syntax/rst.vim
parentfdd7155fab3447b38280035c66178330f8f041e7 (diff)
downloadvim-git-91f84f6e11cd879d43d651c0903d85bff95f0716.tar.gz
Update runtime files.
Diffstat (limited to 'runtime/syntax/rst.vim')
-rw-r--r--runtime/syntax/rst.vim108
1 files changed, 89 insertions, 19 deletions
diff --git a/runtime/syntax/rst.vim b/runtime/syntax/rst.vim
index 232d2a7de..d620d91f4 100644
--- a/runtime/syntax/rst.vim
+++ b/runtime/syntax/rst.vim
@@ -3,7 +3,7 @@
" Maintainer: Marshall Ward <marshall.ward@gmail.com>
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
" Website: https://github.com/marshallward/vim-restructuredtext
-" Latest Revision: 2016-08-18
+" Latest Revision: 2018-07-23
if exists("b:current_syntax")
finish
@@ -50,7 +50,10 @@ syn cluster rstDirectives contains=rstFootnote,rstCitation,
syn match rstExplicitMarkup '^\s*\.\.\_s'
\ nextgroup=@rstDirectives,rstComment,rstSubstitutionDefinition
-let s:ReferenceName = '[[:alnum:]]\+\%([_.-][[:alnum:]]\+\)*'
+" "Simple reference names are single words consisting of alphanumerics plus
+" isolated (no two adjacent) internal hyphens, underscores, periods, colons
+" and plus signs."
+let s:ReferenceName = '[[:alnum:]]\%([-_.:+]\?[[:alnum:]]\+\)*'
syn keyword rstTodo contained FIXME TODO XXX NOTE
@@ -83,7 +86,7 @@ execute 'syn region rstExDirective contained matchgroup=rstDirective' .
\ ' end=+^\s\@!+ contains=@rstCruft,rstLiteralBlock'
execute 'syn match rstSubstitutionDefinition contained' .
- \ ' /|' . s:ReferenceName . '|\_s\+/ nextgroup=@rstDirectives'
+ \ ' /|.*|\_s\+/ nextgroup=@rstDirectives'
function! s:DefineOneInlineMarkup(name, start, middle, end, char_left, char_right)
execute 'syn region rst' . a:name .
@@ -107,10 +110,10 @@ function! s:DefineInlineMarkup(name, start, middle, end)
call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '’', '’')
" TODO: Additional Unicode Pd, Po, Pi, Pf, Ps characters
- call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '\%(^\|\s\|[/:]\)', '')
+ call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '\%(^\|\s\|\%ua0\|[/:]\)', '')
execute 'syn match rst' . a:name .
- \ ' +\%(^\|\s\|[''"([{</:]\)\zs' . a:start .
+ \ ' +\%(^\|\s\|\%ua0\|[''"([{</:]\)\zs' . a:start .
\ '[^[:space:]' . a:start[strlen(a:start) - 1] . ']'
\ a:end . '\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+'
@@ -124,14 +127,31 @@ call s:DefineInlineMarkup('InlineLiteral', '``', "", '``')
call s:DefineInlineMarkup('SubstitutionReference', '|', '|', '|_\{0,2}')
call s:DefineInlineMarkup('InlineInternalTargets', '_`', '`', '`')
-syn match rstSections "^\%(\([=`:.'"~^_*+#-]\)\1\+\n\)\=.\+\n\([=`:.'"~^_*+#-]\)\2\+$"
+" Sections are identified through their titles, which are marked up with
+" adornment: "underlines" below the title text, or underlines and matching
+" "overlines" above the title. An underline/overline is a single repeated
+" punctuation character that begins in column 1 and forms a line extending at
+" least as far as the right edge of the title text.
+"
+" It is difficult to count characters in a regex, but we at least special-case
+" the case where the title has at least three characters to require the
+" adornment to have at least three characters as well, in order to handle
+" properly the case of a literal block:
+"
+" this is the end of a paragraph
+" ::
+" this is a literal block
+syn match rstSections "\v^%(([=`:.'"~^_*+#-])\1+\n)?.{1,2}\n([=`:.'"~^_*+#-])\2+$"
+ \ contains=@Spell
+syn match rstSections "\v^%(([=`:.'"~^_*+#-])\1{2,}\n)?.{3,}\n([=`:.'"~^_*+#-])\2{2,}$"
+ \ contains=@Spell
" TODO: Can’t remember why these two can’t be defined like the ones above.
execute 'syn match rstFootnoteReference contains=@NoSpell' .
- \ ' +\[\%(\d\+\|#\%(' . s:ReferenceName . '\)\=\|\*\)\]_+'
+ \ ' +\%(\s\|^\)\[\%(\d\+\|#\%(' . s:ReferenceName . '\)\=\|\*\)\]_+'
execute 'syn match rstCitationReference contains=@NoSpell' .
- \ ' +\[' . s:ReferenceName . '\]_\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+'
+ \ ' +\%(\s\|^\)\[' . s:ReferenceName . '\]_\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+'
execute 'syn match rstHyperlinkReference' .
\ ' /\<' . s:ReferenceName . '__\=\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)/'
@@ -140,28 +160,69 @@ syn match rstStandaloneHyperlink contains=@NoSpell
\ "\<\%(\%(\%(https\=\|file\|ftp\|gopher\)://\|\%(mailto\|news\):\)[^[:space:]'\"<>]\+\|www[[:alnum:]_-]*\.[[:alnum:]_-]\+\.[^[:space:]'\"<>]\+\)[[:alnum:]/]"
syn region rstCodeBlock contained matchgroup=rstDirective
- \ start=+\%(sourcecode\|code\%(-block\)\=\)::\s\+\w*\_s*\n\ze\z(\s\+\)+
+ \ start=+\%(sourcecode\|code\%(-block\)\=\)::\s\+.*\_s*\n\ze\z(\s\+\)+
\ skip=+^$+
\ end=+^\z1\@!+
\ contains=@NoSpell
syn cluster rstDirectives add=rstCodeBlock
if !exists('g:rst_syntax_code_list')
- let g:rst_syntax_code_list = ['vim', 'java', 'cpp', 'lisp', 'php',
- \ 'python', 'perl', 'sh']
+ " A mapping from a Vim filetype to a list of alias patterns (pattern
+ " branches to be specific, see ':help /pattern'). E.g. given:
+ "
+ " let g:rst_syntax_code_list = {
+ " \ 'cpp': ['cpp', 'c++'],
+ " \ }
+ "
+ " then the respective contents of the following two rST directives:
+ "
+ " .. code:: cpp
+ "
+ " auto i = 42;
+ "
+ " .. code:: C++
+ "
+ " auto i = 42;
+ "
+ " will both be highlighted as C++ code. As shown by the latter block
+ " pattern matching will be case-insensitive.
+ let g:rst_syntax_code_list = {
+ \ 'vim': ['vim'],
+ \ 'java': ['java'],
+ \ 'cpp': ['cpp', 'c++'],
+ \ 'lisp': ['lisp'],
+ \ 'php': ['php'],
+ \ 'python': ['python'],
+ \ 'perl': ['perl'],
+ \ 'sh': ['sh'],
+ \ }
+elseif type(g:rst_syntax_code_list) == type([])
+ " backward compatibility with former list format
+ let s:old_spec = g:rst_syntax_code_list
+ let g:rst_syntax_code_list = {}
+ for s:elem in s:old_spec
+ let g:rst_syntax_code_list[s:elem] = [s:elem]
+ endfor
endif
-for code in g:rst_syntax_code_list
+for s:filetype in keys(g:rst_syntax_code_list)
unlet! b:current_syntax
" guard against setting 'isk' option which might cause problems (issue #108)
let prior_isk = &l:iskeyword
- exe 'syn include @rst'.code.' syntax/'.code.'.vim'
- exe 'syn region rstDirective'.code.' matchgroup=rstDirective fold'
- \.' start=#\%(sourcecode\|code\%(-block\)\=\)::\s\+'.code.'\_s*\n\ze\z(\s\+\)#'
+ let s:alias_pattern = ''
+ \.'\%('
+ \.join(g:rst_syntax_code_list[s:filetype], '\|')
+ \.'\)'
+
+ exe 'syn include @rst'.s:filetype.' syntax/'.s:filetype.'.vim'
+ exe 'syn region rstDirective'.s:filetype
+ \.' matchgroup=rstDirective fold'
+ \.' start="\c\%(sourcecode\|code\%(-block\)\=\)::\s\+'.s:alias_pattern.'\_s*\n\ze\z(\s\+\)"'
\.' skip=#^$#'
\.' end=#^\z1\@!#'
- \.' contains=@NoSpell,@rst'.code
- exe 'syn cluster rstDirectives add=rstDirective'.code
+ \.' contains=@NoSpell,@rst'.s:filetype
+ exe 'syn cluster rstDirectives add=rstDirective'.s:filetype
+
" reset 'isk' setting, if it has been changed
if &l:iskeyword !=# prior_isk
let &l:iskeyword = prior_isk
@@ -169,6 +230,9 @@ for code in g:rst_syntax_code_list
unlet! prior_isk
endfor
+" Enable top level spell checking
+syntax spell toplevel
+
" TODO: Use better syncing.
syn sync minlines=50 linebreaks=2
@@ -189,8 +253,6 @@ hi def link rstHyperlinkTarget String
hi def link rstExDirective String
hi def link rstSubstitutionDefinition rstDirective
hi def link rstDelimiter Delimiter
-hi def rstEmphasis ctermfg=13 term=italic cterm=italic gui=italic
-hi def rstStrongEmphasis ctermfg=1 term=bold cterm=bold gui=bold
hi def link rstInterpretedTextOrHyperlinkReference Identifier
hi def link rstInlineLiteral String
hi def link rstSubstitutionReference PreProc
@@ -200,6 +262,14 @@ hi def link rstCitationReference Identifier
hi def link rstHyperLinkReference Identifier
hi def link rstStandaloneHyperlink Identifier
hi def link rstCodeBlock String
+if exists('g:rst_use_emphasis_colors')
+ " TODO: Less arbitrary color selection
+ hi def rstEmphasis ctermfg=13 term=italic cterm=italic gui=italic
+ hi def rstStrongEmphasis ctermfg=1 term=bold cterm=bold gui=bold
+else
+ hi def rstEmphasis term=italic cterm=italic gui=italic
+ hi def rstStrongEmphasis term=bold cterm=bold gui=bold
+endif
let b:current_syntax = "rst"