From 3b960bac774c431a1dd456bb46af2457dee56643 Mon Sep 17 00:00:00 2001 From: Dmitry Vasiliev Date: Thu, 18 Sep 2008 12:23:33 +0400 Subject: [PATCH] Removed old SVN stuff --- CHANGES.txt | 84 ++++++++++++++ TODO.txt | 9 ++ python.vim | 307 ++++++++++++++++++++++++++++++++++++++++++++++++++++ test.py | 107 ++++++++++++++++++ 4 files changed, 507 insertions(+) create mode 100644 CHANGES.txt create mode 100644 TODO.txt create mode 100644 python.vim create mode 100644 test.py diff --git a/CHANGES.txt b/CHANGES.txt new file mode 100644 index 0000000..09c47a0 --- /dev/null +++ b/CHANGES.txt @@ -0,0 +1,84 @@ +Revision 2.5.6 (2007-02-04): + + - Applied patch by Pedro Algarvio to enable spell checking only for + the right spots (strings and comments); + +Revision 2.5.5 (2006-09-26): + + - added new warnings (ImportWarning, UnicodeWarning) + introduced in Python 2.5; + +Revision 2.5.4 (2006-05-11): + + - added highlighting for erroneous operators: &&, ||, ++, --, === + (inspired by http://www.vim.org/tips/tip.php?tip_id=969, thanks + Jeroen Ruigrok van der Werven for the link); + - added highlighting for new 'with' statement and 'BaseException', + 'GeneratorExit' exceptions introduced in Python 2.5; + - added highlighting for 'OverflowWarning' exception which had been + forgotten; + - returned more robust recognition for function names; + +Revision 2.5.3: + + - fixed %-formatting highlighting for raw unicode strings; + +Revision 2.5.2: + + - slightly simplified option handling; + - fixed regexp for indentation errors; + - fixed highlighting for backslashed symbols inside strings; + - added highlighting for trailing-space errors (triggered by new + option: python_highlight_space_errors); + - added highlighting for variable name errors; + - added highlighting for hex number errors; + +Revision 2.5.1 (2005-03-13): + + - added new builtins 'all' and 'any' (Python 2.5a0) + +Revision 2.4.2 (2004-08-05): + + - added highlighting for new @decorator syntax introduced in python 2.4a2 + +Revision 2.4.1 (2004-03-17): + + - new versioning scheme (based on python version numbers); + - added highlighting for new types/builtins introduced in python 2.4 + (set, frozenset, reversed, sorted); + - new option added: python_slow_sync (set this for slow but more + robust syntax synchronization); + - added highlighting for doctests; + +Revision 1.19: + + - new option added: python_highlight_indent_errors; + - python_highlight_all now not override previously set options, + for example code: + let python_highlight_indent_errors = 0 + let python_highlight_all = 1 + set all highlight options except indentation errors highlighting option; + +Revision 1.17: + + - changed header, "Based on..." string added; + +Revision 1.16: + + - added basestring builtin; + +Revision 1.15 (first public revision). + + The changes since the original (vim6.1) python.vim are: + + - changed string highlighting; + - enhanced special symbols highlighting inside strings; + - enhanced constant numbers highlighting; + - added optional highlighting for %-formatting inside strings; + - added highlighting for error conditions (wrong symbols in source file, + mixing spaces and tabs, wrong number values, + wrong %-formatting inside strings); + - added highlighting for magic comments: source code encoding + and #! (executable) strings; + - added highlighting for new exceptions and builtins introduced + in python 2.3; diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 0000000..6a325e5 --- /dev/null +++ b/TODO.txt @@ -0,0 +1,9 @@ +- Integer literal support + +- Python 3.0 string formatting + +- Need more accurate way to handle indentation errors. For example + mixing spaces and tabs may be used for pretty formatting; + +- Need more checks for errors like: absent brackets, absent quotes, + back slash at the end of strings; diff --git a/python.vim b/python.vim new file mode 100644 index 0000000..521cfda --- /dev/null +++ b/python.vim @@ -0,0 +1,307 @@ +" Vim syntax file +" Language: Python +" Maintainer: Dmitry Vasiliev +" URL: http://www.hlabs.spb.ru/vim/python.vim +" Last Change: $Date$ +" Filenames: *.py +" Version: 2.6.1 +" $Rev$ +" +" Based on python.vim (from Vim 6.1 distribution) +" by Neil Schemenauer +" +" Thanks: +" +" Jeroen Ruigrok van der Werven +" for the idea of highlighting for erroneous operators +" Pedro Algarvio +" for the patch to enable spell checking only for the right spots +" (strings and comments) +" John Eikenberry +" for the patch fixing small typo + +" +" Options: +" +" For set option do: let OPTION_NAME = 1 +" For clear option do: let OPTION_NAME = 0 +" +" Option names: +" +" For highlight builtin functions: +" python_highlight_builtins +" +" For highlight standard exceptions: +" python_highlight_exceptions +" +" For highlight string formatting: +" python_highlight_string_formatting +" +" For highlight indentation errors: +" python_highlight_indent_errors +" +" For highlight trailing spaces: +" python_highlight_space_errors +" +" For highlight doc-tests: +" python_highlight_doctests +" +" If you want all possible Python highlighting: +" (This option not override previously set options) +" python_highlight_all +" +" For fast machines: +" python_slow_sync +" + +" For version 5.x: Clear all syntax items +" For version 6.x: Quit when a syntax file was already loaded +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +if exists("python_highlight_all") && python_highlight_all != 0 + " Not override previously set options + if !exists("python_highlight_builtins") + let python_highlight_builtins = 1 + endif + if !exists("python_highlight_exceptions") + let python_highlight_exceptions = 1 + endif + if !exists("python_highlight_string_formatting") + let python_highlight_string_formatting = 1 + endif + if !exists("python_highlight_indent_errors") + let python_highlight_indent_errors = 1 + endif + if !exists("python_highlight_space_errors") + let python_highlight_space_errors = 1 + endif + if !exists("python_highlight_doctests") + let python_highlight_doctests = 1 + endif +endif + +" Keywords +syn keyword pythonStatement break continue del +syn keyword pythonStatement exec return +syn keyword pythonStatement pass raise +syn keyword pythonStatement global assert +syn keyword pythonStatement lambda yield +syn keyword pythonStatement with +syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite +syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained +syn keyword pythonRepeat for while +syn keyword pythonConditional if elif else +syn keyword pythonImport import from as +syn keyword pythonException try except finally +syn keyword pythonOperator and in is not or + +" Decorators (new in Python 2.4) +syn match pythonDecorator "@" display nextgroup=pythonFunction skipwhite + +" Comments +syn match pythonComment "#.*$" display contains=pythonTodo,@Spell +syn match pythonRun "\%^#!.*$" +syn match pythonCoding "\%^.*\(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$" +syn keyword pythonTodo TODO FIXME XXX contained + +" Errors +syn match pythonError "\<\d\+\D\+\>" display +syn match pythonError "[$?]" display +syn match pythonError "[-+&|]\{2,}" display +syn match pythonError "[=]\{3,}" display + +" TODO: Mixing spaces and tabs also may be used for pretty formatting multiline +" statements. For now I don't know how to work around this. +if exists("python_highlight_indent_errors") && python_highlight_indent_errors != 0 + syn match pythonIndentError "^\s*\( \t\|\t \)\s*\S"me=e-1 display +endif + +" Trailing space errors +if exists("python_highlight_space_errors") && python_highlight_space_errors != 0 + syn match pythonSpaceError "\s\+$" display +endif + +" Strings +syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell +syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell +syn region pythonString start=+"""+ end=+"""+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest2,pythonSpaceError,@Spell +syn region pythonString start=+'''+ end=+'''+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest,pythonSpaceError,@Spell + +syn match pythonEscape +\\[abfnrtv'"\\]+ display contained +syn match pythonEscape "\\\o\o\=\o\=" display contained +syn match pythonEscapeError "\\\o\{,2}[89]" display contained +syn match pythonEscape "\\x\x\{2}" display contained +syn match pythonEscapeError "\\x\x\=\X" display contained +syn match pythonEscape "\\$" + +" Unicode strings +syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell +syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell +syn region pythonUniString start=+[uU]"""+ end=+"""+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell +syn region pythonUniString start=+[uU]'''+ end=+'''+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell + +syn match pythonUniEscape "\\u\x\{4}" display contained +syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained +syn match pythonUniEscape "\\U\x\{8}" display contained +syn match pythonUniEscapeError "\\U\x\{,7}\X" display contained +syn match pythonUniEscape "\\N{[A-Z ]\+}" display contained +syn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained + +" Raw strings +syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell +syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell +syn region pythonRawString start=+[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell +syn region pythonRawString start=+[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell + +syn match pythonRawEscape +\\['"]+ display transparent contained + +" Unicode raw strings +syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell +syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell +syn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell +syn region pythonUniRawString start=+[uU][rR]'''+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell + +syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained +syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained + +if exists("python_highlight_string_formatting") && python_highlight_string_formatting != 0 + " String formatting + syn match pythonStrFormat "%\(([^)]\+)\)\=[-#0 +]*\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString + syn match pythonStrFormat "%[-#0 +]*\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString +endif + +if exists("python_highlight_doctests") && python_highlight_doctests != 0 + " DocTests + syn region pythonDocTest start="^\s*>>>" end=+'''+he=s-1 end="^\s*$" contained + syn region pythonDocTest2 start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" contained +endif + +" Numbers (ints, longs, floats, complex) +syn match pythonHexNumber "\<0[xX]\x\+[lL]\=\>" display +syn match pythonHexNumber "\<0[xX]\>" display +syn match pythonNumber "\<\d\+[lLjJ]\=\>" display +syn match pythonFloat "\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>" display +syn match pythonFloat "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" display +syn match pythonFloat "\<\d\+\.\d*\([eE][+-]\=\d\+\)\=[jJ]\=" display + +syn match pythonOctalError "\<0\o*[89]\d*[lL]\=\>" display +syn match pythonHexError "\<0[xX]\X\+[lL]\=\>" display + +if exists("python_highlight_builtins") && python_highlight_builtins != 0 + " Builtin functions, types and objects + syn keyword pythonBuiltinObj True False Ellipsis None NotImplemented __debug__ + + syn keyword pythonBuiltinFunc __import__ abs all any apply + syn keyword pythonBuiltinFunc basestring bool buffer callable + syn keyword pythonBuiltinFunc chr classmethod cmp coerce compile complex + syn keyword pythonBuiltinFunc delattr dict dir divmod enumerate eval + syn keyword pythonBuiltinFunc execfile file filter float frozenset getattr + syn keyword pythonBuiltinFunc globals hasattr hash help hex id + syn keyword pythonBuiltinFunc input int intern isinstance + syn keyword pythonBuiltinFunc issubclass iter len list locals long map max + syn keyword pythonBuiltinFunc min next object oct open ord + syn keyword pythonBuiltinFunc pow print property range + syn keyword pythonBuiltinFunc raw_input reduce reload repr + syn keyword pythonBuiltinFunc reversed round set setattr + syn keyword pythonBuiltinFunc slice sorted staticmethod str sum super tuple + syn keyword pythonBuiltinFunc type unichr unicode vars xrange zip +endif + +if exists("python_highlight_exceptions") && python_highlight_exceptions != 0 + " Builtin exceptions and warnings + syn keyword pythonExClass BaseException + syn keyword pythonExClass Exception StandardError ArithmeticError + syn keyword pythonExClass LookupError EnvironmentError + + syn keyword pythonExClass AssertionError AttributeError EOFError + syn keyword pythonExClass FloatingPointError GeneratorExit IOError + syn keyword pythonExClass ImportError IndexError KeyError + syn keyword pythonExClass KeyboardInterrupt MemoryError NameError + syn keyword pythonExClass NotImplementedError OSError OverflowError + syn keyword pythonExClass ReferenceError RuntimeError StopIteration + syn keyword pythonExClass SyntaxError IndentationError TabError + syn keyword pythonExClass SystemError SystemExit TypeError + syn keyword pythonExClass UnboundLocalError UnicodeError + syn keyword pythonExClass UnicodeEncodeError UnicodeDecodeError + syn keyword pythonExClass UnicodeTranslateError ValueError + syn keyword pythonExClass WindowsError ZeroDivisionError + + syn keyword pythonExClass Warning UserWarning DeprecationWarning + syn keyword pythonExClass PendingDepricationWarning SyntaxWarning + syn keyword pythonExClass RuntimeWarning FutureWarning + syn keyword pythonExClass ImportWarning UnicodeWarning +endif + +if exists("python_slow_sync") && python_slow_sync != 0 + syn sync minlines=2000 +else + " This is fast but code inside triple quoted strings screws it up. It + " is impossible to fix because the only way to know if you are inside a + " triple quoted string is to start from the beginning of the file. + syn sync match pythonSync grouphere NONE "):$" + syn sync maxlines=200 +endif + +if version >= 508 || !exists("did_python_syn_inits") + if version <= 508 + let did_python_syn_inits = 1 + command -nargs=+ HiLink hi link + else + command -nargs=+ HiLink hi def link + endif + + HiLink pythonStatement Statement + HiLink pythonImport Statement + HiLink pythonFunction Function + HiLink pythonConditional Conditional + HiLink pythonRepeat Repeat + HiLink pythonException Exception + HiLink pythonOperator Operator + + HiLink pythonDecorator Define + + HiLink pythonComment Comment + HiLink pythonCoding Special + HiLink pythonRun Special + HiLink pythonTodo Todo + + HiLink pythonError Error + HiLink pythonIndentError Error + HiLink pythonSpaceError Error + + HiLink pythonString String + HiLink pythonUniString String + HiLink pythonRawString String + HiLink pythonUniRawString String + + HiLink pythonEscape Special + HiLink pythonEscapeError Error + HiLink pythonUniEscape Special + HiLink pythonUniEscapeError Error + HiLink pythonUniRawEscape Special + HiLink pythonUniRawEscapeError Error + + HiLink pythonStrFormat Special + + HiLink pythonDocTest Special + HiLink pythonDocTest2 Special + + HiLink pythonNumber Number + HiLink pythonHexNumber Number + HiLink pythonFloat Float + HiLink pythonOctalError Error + HiLink pythonHexError Error + + HiLink pythonBuiltinObj Structure + HiLink pythonBuiltinFunc Function + + HiLink pythonExClass Structure + + delcommand HiLink +endif + +let b:current_syntax = "python" diff --git a/test.py b/test.py new file mode 100644 index 0000000..d807c15 --- /dev/null +++ b/test.py @@ -0,0 +1,107 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# Above the run-comment and file encoding comment. + +# Comments. + +# TODO FIXME XXX + +# Keywords. + +with break continue del exec return pass print raise global assert lambda yield +for while if elif else import from as try except finally and in is not or +def functionname +class classname + +# Builtin objects. + +True False Ellipsis None NotImplemented + +# Builtin function and types. + +__import__ abs all any apply basestring bool buffer callable chr classmethod +cmp coerce compile complex delattr dict dir divmod enumerate eval execfile file +filter float frozenset getattr globals hasattr hash help hex id input int +intern isinstance issubclass iter len list locals long map max min object oct +open ord pow property range raw_input reduce reload repr reversed round set +setattr slice sorted staticmethod str sum super tuple type unichr unicode vars +xrange zip + +# Builtin exceptions and warnings. + +BaseException Exception StandardError ArithmeticError LookupError +EnvironmentError + +AssertionError AttributeError EOFError FloatingPointError GeneratorExit IOError +ImportError IndexError KeyError KeyboardInterrupt MemoryError NameError +NotImplementedError OSError OverflowError ReferenceError RuntimeError +StopIteration SyntaxError IndentationError TabError SystemError SystemExit +TypeError UnboundLocalError UnicodeError UnicodeEncodeError UnicodeDecodeError +UnicodeTranslateError ValueError WindowsError ZeroDivisionError + +Warning UserWarning DeprecationWarning PendingDepricationWarning SyntaxWarning +RuntimeWarning FutureWarning OverflowWarning ImportWarning UnicodeWarning + +# Decorators. + +@ decoratorname + +# Numbers + +0 0x 0x1f 077 .3 12.34 100L 0j 0j 34.2E-3 + +# Erroneous numbers + +08 0xk + +# Strings + +" test " ' test ' +""" + test +""" +''' + test +''' + +" \a\b\c\"\'\n\r \x34\077 \08 \xag" +r" \" \' " + +# Doctests. + +""" + Test: + >>> a = 5 + >>> a + 5 + + Test +""" + +''' + Test: + >>> a = 5 + >>> a + 5 + + Test +''' + +# Erroneous symbols or bad variable names. + +$ ? 6xav + +&& || ++ -- === + +# Indentation errors. + + break + +# Trailing space errors. + + + break +""" + + test +"""