@@ 1,32 1,14 @@
" Vim syntax file
" Language: Python
-" Maintainer: Zvezdan Petkovic <zpetkovic@acm.org>
-" Last Change: 2016 Oct 29
-" Credits: Neil Schemenauer <nas@python.ca>
+" Maintainer: Dominic Ricottone <me@dominic-ricottone.com>
+" Last Change: 2022 Sep 15
+" Credits: Zvezdan Petkovic <zpetkovic@acm.org>
+" Neil Schemenauer <nas@python.ca>
" Dmitry Vasiliev
"
-" This version is a major rewrite by Zvezdan Petkovic.
-"
-" - introduced highlighting of doctests
-" - updated keywords, built-ins, and exceptions
-" - corrected regular expressions for
-"
-" * functions
-" * decorators
-" * strings
-" * escapes
-" * numbers
-" * space error
-"
-" - corrected synchronization
-" - more highlighting is ON by default, except
-" - space error highlighting is OFF by default
-"
-" Optional highlighting can be controlled using these variables.
+" This version is a minor rewrite by Dominic Ricottone
"
" let python_no_builtin_highlight = 1
-" let python_no_doctest_code_highlight = 1
-" let python_no_doctest_highlight = 1
" let python_no_exception_highlight = 1
" let python_no_number_highlight = 1
" let python_space_error_highlight = 1
@@ 46,20 28,10 @@ endif
let s:cpo_save = &cpo
set cpo&vim
-if exists("python_no_doctest_highlight")
- let python_no_doctest_code_highlight = 1
-endif
-
if exists("python_highlight_all")
if exists("python_no_builtin_highlight")
unlet python_no_builtin_highlight
endif
- if exists("python_no_doctest_code_highlight")
- unlet python_no_doctest_code_highlight
- endif
- if exists("python_no_doctest_highlight")
- unlet python_no_doctest_highlight
- endif
if exists("python_no_exception_highlight")
unlet python_no_exception_highlight
endif
@@ 114,18 86,18 @@ syn match pythonDecoratorName "@\s*\h\%(\w\|\.\)*" display contains=pythonDeco
" Single line multiplication.
syn match pythonMatrixMultiply
\ "\%(\w\|[])]\)\s*@"
- \ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue
+ \ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction
\ transparent
" Multiplication continued on the next line after backslash.
syn match pythonMatrixMultiply
\ "[^\\]\\\s*\n\%(\s*\.\.\.\s\)\=\s\+@"
- \ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue
+ \ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction
\ transparent
" Multiplication in a parenthesized expression over multiple lines with @ at
" the start of each continued line; very similar to decorators and complex.
syn match pythonMatrixMultiply
\ "^\s*\%(\%(>>>\|\.\.\.\)\s\+\)\=\zs\%(\h\|\%(\h\|[[(]\).\{-}\%(\w\|[])]\)\)\s*\n\%(\s*\.\.\.\s\)\=\s\+@\%(.\{-}\n\%(\s*\.\.\.\s\)\=\s\+@\)*"
- \ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue
+ \ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction
\ transparent
syn match pythonFunction "\h\w*" display contained
@@ 133,19 105,19 @@ syn match pythonFunction "\h\w*" display contained
syn match pythonComment "#.*$" contains=pythonTodo,@Spell
syn keyword pythonTodo FIXME NOTE NOTES TODO XXX contained
-" Triple-quoted strings can contain doctests.
+" Triple-quoted strings are doc strings.
syn region pythonString matchgroup=pythonQuotes
\ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
\ contains=pythonEscape,@Spell
-syn region pythonString matchgroup=pythonTripleQuotes
- \ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend
- \ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell
+syn region pythonDocString matchgroup=pythonTripleQuotes
+ \ start=+[uU]\=\z('''\|"""\)+ skip=+\\["']+ end="\z1" keepend
+ \ contains=pythonEscape,pythonSpaceError,@Spell
syn region pythonRawString matchgroup=pythonQuotes
\ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
\ contains=@Spell
-syn region pythonRawString matchgroup=pythonTripleQuotes
+syn region pythonRawDocString matchgroup=pythonTripleQuotes
\ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend
- \ contains=pythonSpaceError,pythonDoctest,@Spell
+ \ contains=pythonSpaceError,@Spell
syn match pythonEscape +\\[abfnrtv'"\\]+ contained
syn match pythonEscape "\\\o\{1,3}" contained
@@ 275,24 247,6 @@ if exists("python_space_error_highlight")
syn match pythonSpaceError display "\t\+ "
endif
-" Do not spell doctests inside strings.
-" Notice that the end of a string, either ''', or """, will end the contained
-" doctest too. Thus, we do *not* need to have it as an end pattern.
-if !exists("python_no_doctest_highlight")
- if !exists("python_no_doctest_code_highlight")
- syn region pythonDoctest
- \ start="^\s*>>>\s" end="^\s*$"
- \ contained contains=ALLBUT,pythonDoctest,pythonFunction,@Spell
- syn region pythonDoctestValue
- \ start=+^\s*\%(>>>\s\|\.\.\.\s\|"""\|'''\)\@!\S\++ end="$"
- \ contained
- else
- syn region pythonDoctest
- \ start="^\s*>>>" end="^\s*$"
- \ contained contains=@NoSpell
- endif
-endif
-
" Sync at the beginning of class, function, or method definition.
syn sync match pythonSync grouphere NONE "^\%(def\|class\)\s\+\h\w*\s*[(:]"
@@ 311,8 265,10 @@ hi def link pythonComment Comment
hi def link pythonTodo Todo
hi def link pythonString String
hi def link pythonRawString String
+hi def link pythonDocString Comment
+hi def link pythonRawDocString Comment
hi def link pythonQuotes String
-hi def link pythonTripleQuotes pythonQuotes
+hi def link pythonTripleQuotes Comment
hi def link pythonEscape Special
if !exists("python_no_number_highlight")
hi def link pythonNumber Number
@@ 326,10 282,6 @@ endif
if exists("python_space_error_highlight")
hi def link pythonSpaceError Error
endif
-if !exists("python_no_doctest_highlight")
- hi def link pythonDoctest Special
- hi def link pythonDoctestValue Define
-endif
let b:current_syntax = "python"