سؤال

From this, I would like to highlight the string in triple single quotes as comments (or better is for these others that are not the first thing in class/function/module).

I'm using jedi-vim. Here's the content of the file after/syntax/python.vim:

syn match pythonComment "#.*$" contains=pythonTodo,@Spell,jediFunction
syn region pythonString
    \ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
    \ contains=pythonEscape,@Spell,jediFunction
syn region pythonString
    \ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend
    \ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell,jediFunction
syn region pythonRawString
    \ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
    \ contains=@Spell,jediFunction
syn region pythonRawString
    \ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend
    \ contains=pythonSpaceError,pythonDoctest,@Spell,jediFunction

I have tried to remove the triple single quotes in the pythonString line, and add the one of the following:

syn region Comment start=/'''/ end=/'''/
syn region pythonDocstring  start=+^\s*[uU]\?[rR]\?'''+ end=+'''+ keepend excludenl contains=pythonEscape,@Spell,pythonDoctest,pythonDocTest2,pythonSpaceError

as suggested in this topic, but it didn't work (string in both triple single and double quotes are highlighted as docstring).


UPDATE Fri Feb 14 08:29:00 ICT 2014

@benjifisher

I'm sure that it is being recognized as pythonString because :echo synIDattr(synID(line("."), col("."), 1), "name") talked me that.

:syn list pythonString

--- Syntax items ---
pythonString   xxx start=/[uU]\=\z(['"]\)/ skip=/\\\\\|\\\z1/ end=/\z1/  contains=pythonEscape,@Spell
                   start=/[uU]\=\z("""\)/ end=/\z1/  keepend contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell
                   start=/[uU]\=\z(['"]\)/ skip=/\\\\\|\\\z1/ end=/\z1/  contains=pythonEscape,@Spell,jediFunction
                   start=/[uU]\=\z("""\)/ end=/\z1/  keepend contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell,jediFunction
                   links to String

:syn list pythonComment

--- Syntax items ---
pythonComment  xxx match /#.*$/  contains=pythonTodo,@Spell
                   match /#.*$/  contains=pythonTodo,@Spell,jediFunction
                   start=/'''/ end=/'''/
                   start=/[uU]\=\z('''\)/ end=/\z1/  keepend contains=pythonTodo,@Spell,jediFunction
                   start=/^\s*[uU]\?[rR]\?'''/ end=/'''/  keepend excludenl contains=pythonEscape,@Spell,pythonDoctest,pythonDocTest2,pythonSpaceError
                   links to Comment
هل كانت مفيدة؟

المحلول

Oh, sorry, my fault.

Since I added the suggested line after the first line (pythonComment), I also have to remove the single quote at the second line:

syn match pythonComment "#.*$" contains=pythonTodo,@Spell,jediFunction
syn region pythonComment start=/'''/ end=/'''/
syn region pythonString
    \ start=+[uU]\=\z(["]\)+ end="\z1" skip="\\\\\|\\\z1"
    \ contains=pythonEscape,@Spell,jediFunction

The lesson is: I should add it at the end of file at the next time :D.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top