Skip to content

Commit ccddc04

Browse files
committed
Proof of concept docstring highlighting
1 parent 2cc00ba commit ccddc04

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

syntax/python.vim

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ syn match pythonDot '\.' display containedin=pythonDottedName
133133
"
134134
" Comments
135135
"
136-
137136
syn match pythonComment '#.*$' display contains=pythonTodo,@Spell
138137
if !s:Enabled('g:python_highlight_file_headers_as_comments')
139138
syn match pythonRun '\%^#!.*$'
@@ -193,6 +192,7 @@ syn match pythonUniEscapeError '\\U\x\{,7}\X' display contained
193192
syn match pythonUniEscape '\\N{[A-Z ]\+}' display contained
194193
syn match pythonUniEscapeError '\\N{[^A-Z ]\+}' display contained
195194

195+
196196
if s:Python2Syntax()
197197
" Python 2 Unicode strings
198198
syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
@@ -203,15 +203,16 @@ else
203203
" Python 3 strings
204204
syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
205205
syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
206-
syn region pythonString start=+'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
207-
syn region pythonString start=+"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
206+
syn region pythonMultiString start=+'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
207+
syn region pythonMultiString start=+"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
208208

209209
syn region pythonFString start=+[fF]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
210210
syn region pythonFString start=+[fF]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
211211
syn region pythonFString start=+[fF]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
212212
syn region pythonFString start=+[fF]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
213213
endif
214214

215+
215216
if s:Python2Syntax()
216217
" Python 2 Unicode raw strings
217218
syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
@@ -290,6 +291,17 @@ if s:Enabled('g:python_highlight_doctests')
290291
syn region pythonDocTest2 start='^\s*>>>' skip=+\\"+ end=+"""+he=s-1 end='^\s*$' contained
291292
endif
292293

294+
" Docstrings
295+
syn match pythonColon ':' nextgroup=pythonDocString skipempty
296+
syn match pythonStartFile +\%^+ nextgroup=pythonDocString skipempty
297+
syn region pythonDocString start=+^\s*'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
298+
syn region pythonDocString start=+^\s*"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
299+
syn region pythonMultiString start=+^\s*'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
300+
syn region pythonMultiString start=+^\s*"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
301+
syn region pythonDocString start=+\%^\s*'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
302+
syn region pythonDocString start=+\%^\s*"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
303+
304+
293305
"
294306
" Numbers (ints, longs, floats, complex)
295307
"
@@ -479,6 +491,9 @@ if v:version >= 508 || !exists('did_python_syn_inits')
479491
HiLink pythonStrFormat Special
480492
HiLink pythonStrTemplate Special
481493

494+
HiLink pythonMultiString String
495+
HiLink pythonDocString Comment
496+
482497
HiLink pythonDocTest Special
483498
HiLink pythonDocTest2 Special
484499

0 commit comments

Comments
 (0)