├── LICENSE.txt ├── README.md ├── ftplugin └── cython.vim ├── plugin └── cython.vim └── syntax └── cython.vim /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Gabriel Pettier 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | vim-cython 2 | ========== 3 | 4 | Just a vim syntax file for cython i found in the wild, and the 5 | boilerplate to make it easy to use, plus some bonus when i find them. 6 | Nothing fancy (yet?), just easy to use with pathogen, install the usual 7 | way, and be done with it. 8 | -------------------------------------------------------------------------------- /ftplugin/cython.vim: -------------------------------------------------------------------------------- 1 | setlocal makeprg=cython\ -a\ %\ &&\ xdg-open\ '%<.html' 2 | -------------------------------------------------------------------------------- /plugin/cython.vim: -------------------------------------------------------------------------------- 1 | au BufRead,BufNewFile *.pxd,*.pxi,*.pyx set filetype=cython 2 | -------------------------------------------------------------------------------- /syntax/cython.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: Cython 3 | " Maintainer: Neil Schemenauer 4 | " Last Change: 2009-10-13 5 | " Credits: Zvezdan Petkovic 6 | " Neil Schemenauer 7 | " Dmitry Vasiliev, Dusan Maliarik 8 | " 9 | " This version is a major rewrite by Zvezdan Petkovic. 10 | " 11 | " - introduced highlighting of doctests 12 | " - updated keywords, built-ins, and exceptions 13 | " - corrected regular expressions for 14 | " 15 | " * functions 16 | " * decorators 17 | " * strings 18 | " * escapes 19 | " * numbers 20 | " * space error 21 | " 22 | " - corrected synchronization 23 | " - more highlighting is ON by default, except 24 | " - space error highlighting is OFF by default 25 | " 26 | " Optional highlighting can be controlled using these variables. 27 | " 28 | " let python_no_builtin_highlight = 1 29 | " let python_no_doctest_code_highlight = 1 30 | " let python_no_doctest_highlight = 1 31 | " let python_no_exception_highlight = 1 32 | " let python_no_number_highlight = 1 33 | " let python_space_error_highlight = 1 34 | " 35 | " All the options above can be switched on together. 36 | " 37 | " let python_highlight_all = 1 38 | " 39 | 40 | " For version 5.x: Clear all syntax items. 41 | " For version 6.x: Quit when a syntax file was already loaded. 42 | if version < 600 43 | syntax clear 44 | elseif exists("b:current_syntax") 45 | finish 46 | endif 47 | 48 | " Keep Python keywords in alphabetical order inside groups for easy 49 | " comparison with the table in the 'Python Language Reference' 50 | " http://docs.python.org/reference/lexical_analysis.html#keywords. 51 | " Groups are in the order presented in NAMING CONVENTIONS in syntax.txt. 52 | " Exceptions come last at the end of each group (class and def below). 53 | " 54 | " Keywords 'with' and 'as' are new in Python 2.6 55 | " (use 'from __future__ import with_statement' in Python 2.5). 56 | " 57 | " Some compromises had to be made to support both Python 3.0 and 2.6. 58 | " We include Python 3.0 features, but when a definition is duplicated, 59 | " the last definition takes precedence. 60 | " 61 | " - 'False', 'None', and 'True' are keywords in Python 3.0 but they are 62 | " built-ins in 2.6 and will be highlighted as built-ins below. 63 | " - 'exec' is a built-in in Python 3.0 and will be highlighted as 64 | " built-in below. 65 | " - 'nonlocal' is a keyword in Python 3.0 and will be highlighted. 66 | " - 'print' is a built-in in Python 3.0 and will be highlighted as 67 | " built-in below (use 'from __future__ import print_function' in 2.6) 68 | " 69 | syn keyword pythonStatement False, None, True 70 | syn keyword pythonStatement as assert break continue del exec global 71 | syn keyword pythonStatement lambda nonlocal pass print return with yield 72 | syn keyword pythonStatement class cdef cpdef ctypedef cppclass def nextgroup=pythonFunction skipwhite 73 | syn keyword pythonConditional elif else if 74 | syn keyword pythonRepeat for while 75 | syn keyword pythonOperator and in is not or 76 | syn keyword pythonException except finally raise try 77 | syn keyword pythonInclude from import cimport include 78 | 79 | " Decorators (new in Python 2.4) 80 | syn match pythonDecorator "@" display nextgroup=pythonFunction skipwhite 81 | " The zero-length non-grouping match before the function name is 82 | " extremely important in pythonFunction. Without it, everything is 83 | " interpreted as a function inside the contained environment of 84 | " doctests. 85 | " A dot must be allowed because of @MyClass.myfunc decorators. 86 | syn match pythonFunction 87 | \ "\%(\%(def\s\|class\s\|cppclass\s\|ctypedef\s\|cpdef\s\|cdef\s\|@\)\s*\)\@<=\h\%(\w\|\.\)*" contained 88 | 89 | syn match pythonComment "#.*$" contains=pythonTodo,@Spell 90 | syn keyword pythonTodo FIXME NOTE NOTES TODO XXX contained 91 | 92 | " Triple-quoted strings can contain doctests. 93 | syn region pythonString 94 | \ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" 95 | \ contains=pythonEscape,@Spell 96 | syn region pythonString 97 | \ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend 98 | \ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell 99 | syn region pythonRawString 100 | \ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" 101 | \ contains=@Spell 102 | syn region pythonRawString 103 | \ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend 104 | \ contains=pythonSpaceError,pythonDoctest,@Spell 105 | 106 | syn match pythonEscape +\\[abfnrtv'"\\]+ contained 107 | syn match pythonEscape "\\\o\{1,3}" contained 108 | syn match pythonEscape "\\x\x\{2}" contained 109 | syn match pythonEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained 110 | " Python allows case-insensitive Unicode IDs: http://www.unicode.org/charts/ 111 | syn match pythonEscape "\\N{\a\+\%(\s\a\+\)*}" contained 112 | syn match pythonEscape "\\$" 113 | 114 | if exists("python_highlight_all") 115 | if exists("python_no_builtin_highlight") 116 | unlet python_no_builtin_highlight 117 | endif 118 | if exists("python_no_doctest_code_highlight") 119 | unlet python_no_doctest_code_highlight 120 | endif 121 | if exists("python_no_doctest_highlight") 122 | unlet python_no_doctest_highlight 123 | endif 124 | if exists("python_no_exception_highlight") 125 | unlet python_no_exception_highlight 126 | endif 127 | if exists("python_no_number_highlight") 128 | unlet python_no_number_highlight 129 | endif 130 | let python_space_error_highlight = 1 131 | endif 132 | 133 | " It is very important to understand all details before changing the 134 | " regular expressions below or their order. 135 | " The word boundaries are *not* the floating-point number boundaries 136 | " because of a possible leading or trailing decimal point. 137 | " The expressions below ensure that all valid number literals are 138 | " highlighted, and invalid number literals are not. For example, 139 | " 140 | " - a decimal point in '4.' at the end of a line is highlighted, 141 | " - a second dot in 1.0.0 is not highlighted, 142 | " - 08 is not highlighted, 143 | " - 08e0 or 08j are highlighted, 144 | " 145 | " and so on, as specified in the 'Python Language Reference'. 146 | " http://docs.python.org/reference/lexical_analysis.html#numeric-literals 147 | if !exists("python_no_number_highlight") 148 | " numbers (including longs and complex) 149 | syn match pythonNumber "\<0[oO]\=\o\+[Ll]\=\>" 150 | syn match pythonNumber "\<0[xX]\x\+[Ll]\=\>" 151 | syn match pythonNumber "\<0[bB][01]\+[Ll]\=\>" 152 | syn match pythonNumber "\<\%([1-9]\d*\|0\)[Ll]\=\>" 153 | syn match pythonNumber "\<\d\+[jJ]\>" 154 | syn match pythonNumber "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" 155 | syn match pythonNumber 156 | \ "\<\d\+\.\%([eE][+-]\=\d\+\)\=[jJ]\=\%(\W\|$\)\@=" 157 | syn match pythonNumber 158 | \ "\%(^\|\W\)\@<=\d*\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>" 159 | endif 160 | 161 | " Group the built-ins in the order in the 'Python Library Reference' for 162 | " easier comparison. 163 | " http://docs.python.org/library/constants.html 164 | " http://docs.python.org/library/functions.html 165 | " http://docs.python.org/library/functions.html#non-essential-built-in-functions 166 | " Python built-in functions are in alphabetical order. 167 | if !exists("python_no_builtin_highlight") 168 | " built-in constants 169 | " 'False', 'True', and 'None' are also reserved words in Python 3.0 170 | syn keyword pythonBuiltin False True None 171 | syn keyword pythonBuiltin NotImplemented Ellipsis __debug__ 172 | " built-in functions 173 | syn keyword pythonBuiltin abs all any bin bool chr classmethod 174 | syn keyword pythonBuiltin compile complex delattr dict dir divmod 175 | syn keyword pythonBuiltin enumerate eval filter float format 176 | syn keyword pythonBuiltin frozenset getattr globals hasattr hash 177 | syn keyword pythonBuiltin help hex id input int isinstance 178 | syn keyword pythonBuiltin issubclass iter len list locals map max 179 | syn keyword pythonBuiltin min next object oct open ord pow print 180 | syn keyword pythonBuiltin property range repr reversed round set 181 | syn keyword pythonBuiltin setattr slice sorted staticmethod str 182 | syn keyword pythonBuiltin sum super tuple type vars zip __import__ 183 | " Python 2.6 only 184 | syn keyword pythonBuiltin basestring callable cmp execfile file 185 | syn keyword pythonBuiltin long raw_input reduce reload unichr 186 | syn keyword pythonBuiltin unicode xrange 187 | " Python 3.0 only 188 | syn keyword pythonBuiltin ascii bytearray bytes exec memoryview 189 | " non-essential built-in functions; Python 2.6 only 190 | syn keyword pythonBuiltin apply buffer coerce intern 191 | " Cython types " 192 | syn keyword pythonBuiltin void NULL bint int short double float unsigned operator 193 | syn keyword pythonBuiltin struct union enum 194 | endif 195 | 196 | " From the 'Python Library Reference' class hierarchy at the bottom. 197 | " http://docs.python.org/library/exceptions.html 198 | if !exists("python_no_exception_highlight") 199 | " builtin base exceptions (only used as base classes for other exceptions) 200 | syn keyword pythonExceptions BaseException Exception 201 | syn keyword pythonExceptions ArithmeticError EnvironmentError 202 | syn keyword pythonExceptions LookupError 203 | " builtin base exception removed in Python 3.0 204 | syn keyword pythonExceptions StandardError 205 | " builtin exceptions (actually raised) 206 | syn keyword pythonExceptions AssertionError AttributeError BufferError 207 | syn keyword pythonExceptions EOFError FloatingPointError GeneratorExit 208 | syn keyword pythonExceptions IOError ImportError IndentationError 209 | syn keyword pythonExceptions IndexError KeyError KeyboardInterrupt 210 | syn keyword pythonExceptions MemoryError NameError NotImplementedError 211 | syn keyword pythonExceptions OSError OverflowError ReferenceError 212 | syn keyword pythonExceptions RuntimeError StopIteration SyntaxError 213 | syn keyword pythonExceptions SystemError SystemExit TabError TypeError 214 | syn keyword pythonExceptions UnboundLocalError UnicodeError 215 | syn keyword pythonExceptions UnicodeDecodeError UnicodeEncodeError 216 | syn keyword pythonExceptions UnicodeTranslateError ValueError VMSError 217 | syn keyword pythonExceptions WindowsError ZeroDivisionError 218 | " builtin warnings 219 | syn keyword pythonExceptions BytesWarning DeprecationWarning FutureWarning 220 | syn keyword pythonExceptions ImportWarning PendingDeprecationWarning 221 | syn keyword pythonExceptions RuntimeWarning SyntaxWarning UnicodeWarning 222 | syn keyword pythonExceptions UserWarning Warning 223 | endif 224 | 225 | if exists("python_space_error_highlight") 226 | " trailing whitespace 227 | syn match pythonSpaceError display excludenl "\s\+$" 228 | " mixed tabs and spaces 229 | syn match pythonSpaceError display " \+\t" 230 | syn match pythonSpaceError display "\t\+ " 231 | endif 232 | 233 | " Do not spell doctests inside strings. 234 | " Notice that the end of a string, either ''', or """, will end the contained 235 | " doctest too. Thus, we do *not* need to have it as an end pattern. 236 | if !exists("python_no_doctest_highlight") 237 | if !exists("python_no_doctest_code_higlight") 238 | syn region pythonDoctest 239 | \ start="^\s*>>>\s" end="^\s*$" 240 | \ contained contains=ALLBUT,pythonDoctest,@Spell 241 | syn region pythonDoctestValue 242 | \ start=+^\s*\%(>>>\s\|\.\.\.\s\|"""\|'''\)\@!\S\++ end="$" 243 | \ contained 244 | else 245 | syn region pythonDoctest 246 | \ start="^\s*>>>" end="^\s*$" 247 | \ contained contains=@NoSpell 248 | endif 249 | endif 250 | 251 | " Sync at the beginning of class, function, or method definition. 252 | syn sync match pythonSync grouphere NONE "^\s*\%(def\|class\|ctypedef\|cppclass\|cpdef\|cdef\)\s\+\h\w*\s*(" 253 | 254 | if version >= 508 || !exists("did_python_syn_inits") 255 | if version <= 508 256 | let did_python_syn_inits = 1 257 | command -nargs=+ HiLink hi link 258 | else 259 | command -nargs=+ HiLink hi def link 260 | endif 261 | 262 | " The default highlight links. Can be overridden later. 263 | HiLink pythonStatement Statement 264 | HiLink pythonConditional Conditional 265 | HiLink pythonRepeat Repeat 266 | HiLink pythonOperator Operator 267 | HiLink pythonException Exception 268 | HiLink pythonInclude Include 269 | HiLink pythonDecorator Define 270 | HiLink pythonFunction Function 271 | HiLink pythonComment Comment 272 | HiLink pythonTodo Todo 273 | HiLink pythonString String 274 | HiLink pythonRawString String 275 | HiLink pythonEscape Special 276 | if !exists("python_no_number_highlight") 277 | HiLink pythonNumber Number 278 | endif 279 | if !exists("python_no_builtin_highlight") 280 | HiLink pythonBuiltin Function 281 | endif 282 | if !exists("python_no_exception_highlight") 283 | HiLink pythonExceptions Structure 284 | endif 285 | if exists("python_space_error_highlight") 286 | HiLink pythonSpaceError Error 287 | endif 288 | if !exists("python_no_doctest_highlight") 289 | HiLink pythonDoctest Special 290 | HiLink pythonDoctestValue Define 291 | endif 292 | 293 | delcommand HiLink 294 | endif 295 | 296 | let b:current_syntax = "python" 297 | 298 | " vim:set sw=2 sts=2 ts=8 noet: 299 | --------------------------------------------------------------------------------