2

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
Community
  • 1
  • 1
quanta
  • 3,960
  • 4
  • 40
  • 75
  • `'''Docstrings'''` are not `# comments`. – romainl Feb 13 '14 at 17:29
  • 1
    I am not sure why you use Comment instead of pythonComment, but maybe it does not matter much. Are you sure you are getting docstring, and by that do you mean pythonDocstring? See the example under `:help synID()` for how to check. If `"""this"""` really is being recognized as pythonDocstring, what does `:syn list pythonDocstring` tell you? – benjifisher Feb 13 '14 at 19:01
  • @romainl: `'''string'''` will be considered as multiple lines comment if it is NOT the first thing in the class/function/module. @benjifisher: updated my question. – quanta Feb 14 '14 at 01:43

1 Answers1

0

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.

quanta
  • 3,960
  • 4
  • 40
  • 75