Skip to content

Commit f2fd6dd

Browse files
committed
Rename/move py_folding to python/folding-ideas
1 parent c8113a7 commit f2fd6dd

File tree

2 files changed

+473
-0
lines changed

2 files changed

+473
-0
lines changed

folding-ideas/python.vim.1.13

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
" Vim syntax file
2+
" Language: Python
3+
" Maintainer: Neil Schemenauer <nas@python.ca>
4+
" Updated: $Date: 2003/01/12 14:17:34 $
5+
" Updated by: Dmitry Vasiliev <dima@hlabs.spb.ru>
6+
" Filenames: *.py
7+
" $Revision: 1.13 $
8+
"
9+
" Options:
10+
" For folded functions and classes:
11+
"
12+
" let python_folding = 1
13+
"
14+
" For highlighted builtin functions:
15+
"
16+
" let python_highlight_builtins = 1
17+
"
18+
" For highlighted standard exceptions:
19+
"
20+
" let python_highlight_exceptions = 1
21+
"
22+
" For highlighted string formatting:
23+
"
24+
" let python_highlight_string_formatting = 1
25+
"
26+
" If you want all possible Python highlighting:
27+
"
28+
" let python_highlight_all = 1
29+
"
30+
" TODO: Check more errors?
31+
32+
" For version 5.x: Clear all syntax items
33+
" For version 6.x: Quit when a syntax file was already loaded
34+
if version < 600
35+
syntax clear
36+
elseif exists("b:current_syntax")
37+
finish
38+
endif
39+
40+
if exists("python_highlight_all")
41+
let python_folding = 1
42+
let python_highlight_builtins = 1
43+
let python_highlight_exceptions = 1
44+
let python_highlight_string_formatting = 1
45+
endif
46+
47+
" Keywords
48+
syn keyword pythonStatement break continue del
49+
syn keyword pythonStatement exec return
50+
syn keyword pythonStatement pass print raise
51+
syn keyword pythonStatement global assert
52+
syn keyword pythonStatement lambda yield
53+
if exists("python_folding") && has("folding")
54+
syn match pythonStatement "\<\(def\|class\)\>" display nextgroup=pythonFunction skipwhite
55+
else
56+
syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
57+
endif
58+
syn match pythonFunction "\h\w*" display contained
59+
syn keyword pythonRepeat for while
60+
syn keyword pythonConditional if elif else
61+
syn keyword pythonImport import from as
62+
syn keyword pythonException try except finally
63+
syn keyword pythonOperator and in is not or
64+
65+
" Comments
66+
syn match pythonComment "#.*$" display contains=pythonTodo
67+
syn keyword pythonTodo TODO FIXME XXX contained
68+
69+
" Erroneous characters that cannont be in a python program
70+
syn match pythonError "[@$?]" display
71+
" Mixing spaces and tabs is bad
72+
syn match pythonIndentError "^\s*\(\t \| \t\)\s*" display
73+
74+
" Strings
75+
syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonEscape,pythonEscapeError
76+
syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonEscape,pythonEscapeError
77+
syn region pythonString start=+"""+ end=+"""+ contains=pythonEscape,pythonEscapeError
78+
syn region pythonString start=+'''+ end=+'''+ contains=pythonEscape,pythonEscapeError
79+
80+
syn match pythonEscape +\\[abfnrtv'"\\]+ display contained
81+
syn match pythonEscapeError +\\[^abfnrtv'"\\]+ display contained
82+
syn match pythonEscape "\\\o\o\=\o\=" display contained
83+
syn match pythonEscapeError "\\\o\{,2}[89]" display contained
84+
syn match pythonEscape "\\x\x\{2}" display contained
85+
syn match pythonEscapeError "\\x\x\=\X" display contained
86+
syn match pythonEscape "\\$"
87+
88+
" Unicode strings
89+
syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError
90+
syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError
91+
syn region pythonUniString start=+[uU]"""+ end=+"""+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError
92+
syn region pythonUniString start=+[uU]'''+ end=+'''+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError
93+
94+
syn match pythonUniEscape "\\u\x\{4}" display contained
95+
syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained
96+
syn match pythonUniEscape "\\U\x\{8}" display contained
97+
syn match pythonUniEscapeError "\\U\x\{,7}\X" display contained
98+
syn match pythonUniEscape "\\N{[A-Z ]\+}" display contained
99+
syn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained
100+
101+
" Raw strings
102+
syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonRawEscape
103+
syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonRawEscape
104+
syn region pythonRawString start=+[rR]"""+ end=+"""+
105+
syn region pythonRawString start=+[rR]'''+ end=+'''+
106+
107+
syn match pythonRawEscape +\\['"]+ display transparent contained
108+
109+
" Unicode raw strings
110+
syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError
111+
syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError
112+
syn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ contains=pythonUniRawEscape,pythonUniRawEscapeError
113+
syn region pythonUniRawString start=+[uU][rR]'''+ end=+'''+ contains=pythonUniRawEscape,pythonUniRawEscapeError
114+
115+
syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained
116+
syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained
117+
118+
if exists("python_highlight_string_formatting")
119+
" String formatting
120+
syn match pythonStrFormat "%\(([^)]\+)\)\=[-#0 +]\=\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString
121+
syn match pythonStrFormat "%[-#0 +]\=\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString
122+
endif
123+
124+
" Numbers (ints, longs, floats, complex)
125+
syn match pythonNumber "\<0[xX]\x\+[lL]\=\>" display
126+
syn match pythonNumber "\<\d\+[lLjJ]\=\>" display
127+
syn match pythonFloat "\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>" display
128+
syn match pythonFloat "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" display
129+
syn match pythonFloat "\<\d\+\.\d*\([eE][+-]\=\d\+\)\=[jJ]\=" display
130+
syn match pythonOctalError "\<0\o*[89]\d*[lLjJ]\=\>" display
131+
132+
if exists("python_highlight_builtins")
133+
" Builtin functions, types and objects, not really part of the syntax
134+
syn keyword pythonBuiltinObj True False Ellipsis None NotImplemented
135+
syn keyword pythonBuiltinFunc bool __import__ abs
136+
syn keyword pythonBuiltinFunc apply buffer callable chr classmethod cmp
137+
syn keyword pythonBuiltinFunc coerce compile complex delattr dict dir divmod
138+
syn keyword pythonBuiltinFunc eval execfile file filter float getattr globals
139+
syn keyword pythonBuiltinFunc hasattr hash hex id input int intern isinstance
140+
syn keyword pythonBuiltinFunc issubclass iter len list locals long map max
141+
syn keyword pythonBuiltinFunc min object oct open ord pow property range
142+
syn keyword pythonBuiltinFunc raw_input reduce reload repr round setattr
143+
syn keyword pythonBuiltinFunc slice staticmethod str super tuple type unichr
144+
syn keyword pythonBuiltinFunc unicode vars xrange zip
145+
endif
146+
147+
if exists("python_highlight_exceptions")
148+
" Builtin exceptions and warnings
149+
syn keyword pythonExClass ArithmeticError AssertionError AttributeError
150+
syn keyword pythonExClass DeprecationWarning EOFError EnvironmentError
151+
syn keyword pythonExClass Exception FloatingPointError IOError
152+
syn keyword pythonExClass ImportError IndentiationError IndexError
153+
syn keyword pythonExClass KeyError KeyboardInterrupt LookupError
154+
syn keyword pythonExClass MemoryError NameError NotImplementedError
155+
syn keyword pythonExClass OSError OverflowError OverflowWarning
156+
syn keyword pythonExClass ReferenceError RuntimeError RuntimeWarning
157+
syn keyword pythonExClass StandardError StopIteration SyntaxError
158+
syn keyword pythonExClass SyntaxWarning SystemError SystemExit TabError
159+
syn keyword pythonExClass TypeError UnboundLocalError UnicodeError
160+
syn keyword pythonExClass UserWarning ValueError Warning WindowsError
161+
syn keyword pythonExClass ZeroDivisionError
162+
endif
163+
164+
syn sync clear
165+
if exists("python_folding") && has("folding")
166+
syn sync fromstart
167+
168+
"syn match pythonFold "^\(\s*\)\(class\|def\)\s.*\(\(\n\s*\)*\n\1\s\+\S.*\)\+" transparent fold
169+
syn region pythonFold start="^\z(\s*\)\(class\|def\)\s" skip="^\z1\s\+\S" end="^\s*\S"me=s-1 transparent fold
170+
syn region pythonFold start="{" end="}" transparent fold
171+
syn region pythonFold start="\[" end="\]" transparent fold
172+
else
173+
" This is fast but code inside triple quoted strings screws it up. It
174+
" is impossible to fix because the only way to know if you are inside a
175+
" triple quoted string is to start from the beginning of the file. If
176+
" you have a fast machine you can try uncommenting the "sync minlines"
177+
" and commenting out the rest.
178+
syn sync match pythonSync grouphere NONE "):$"
179+
syn sync maxlines=200
180+
"syn sync minlines=2000
181+
endif
182+
183+
if version >= 508 || !exists("did_python_syn_inits")
184+
if version <= 508
185+
let did_python_syn_inits = 1
186+
command -nargs=+ HiLink hi link <args>
187+
else
188+
command -nargs=+ HiLink hi def link <args>
189+
endif
190+
191+
HiLink pythonStatement Statement
192+
HiLink pythonImport Statement
193+
HiLink pythonFunction Function
194+
HiLink pythonConditional Conditional
195+
HiLink pythonRepeat Repeat
196+
HiLink pythonException Exception
197+
HiLink pythonOperator Operator
198+
199+
HiLink pythonComment Comment
200+
HiLink pythonTodo Todo
201+
202+
HiLink pythonError Error
203+
HiLink pythonIndentError Error
204+
205+
HiLink pythonString String
206+
HiLink pythonUniString String
207+
HiLink pythonRawString String
208+
HiLink pythonUniRawString String
209+
210+
HiLink pythonEscape Special
211+
HiLink pythonEscapeError Error
212+
HiLink pythonUniEscape Special
213+
HiLink pythonUniEscapeError Error
214+
HiLink pythonUniRawEscape Special
215+
HiLink pythonUniRawEscapeError Error
216+
217+
if exists("python_highlight_string_formatting")
218+
HiLink pythonStrFormat Special
219+
endif
220+
221+
HiLink pythonNumber Number
222+
HiLink pythonFloat Float
223+
HiLink pythonOctalError Error
224+
225+
if exists("python_highlight_builtins")
226+
HiLink pythonBuiltinObj Structure
227+
HiLink pythonBuiltinFunc Function
228+
endif
229+
230+
if exists("python_highlight_exceptions")
231+
HiLink pythonExClass Structure
232+
endif
233+
234+
delcommand HiLink
235+
endif
236+
237+
let b:current_syntax = "python"

0 commit comments

Comments
 (0)