Skip to content

Commit 31f669d

Browse files
committed
Improve builtin-func highlighting
* Make them highlighted only when used as in the global namespace. (e.g., `id` in `something.id` is not highlighted) * Also add self and cls to builtin objects
1 parent 67c13cf commit 31f669d

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

syntax/python.vim

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ if s:Enabled("g:python_highlight_builtin_objs")
415415
if s:Python2Syntax()
416416
syn keyword pythonBuiltinObj None False True
417417
endif
418-
syn keyword pythonBuiltinObj Ellipsis NotImplemented
418+
syn keyword pythonBuiltinObj Ellipsis NotImplemented self cls
419419
syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__
420420
endif
421421

@@ -425,28 +425,28 @@ endif
425425

426426
if s:Enabled("g:python_highlight_builtin_funcs")
427427
if s:Python2Syntax()
428-
syn keyword pythonBuiltinFunc apply basestring buffer callable coerce
429-
syn keyword pythonBuiltinFunc execfile file help intern long raw_input
430-
syn keyword pythonBuiltinFunc reduce reload unichr unicode xrange
428+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(apply|basestring|buffer|callable|coerce)>'
429+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(execfile|file|help|intern|long|raw_input)>'
430+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(reduce|reload|unichr|unicode|xrange)>'
431431
if s:Enabled("g:python_print_as_function")
432-
syn keyword pythonBuiltinFunc print
432+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(print)>'
433433
endif
434434
else
435-
syn keyword pythonBuiltinFunc ascii exec memoryview print
435+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(ascii|exec|memoryview|print)>'
436436
endif
437-
syn keyword pythonBuiltinFunc __import__ abs all any
438-
syn keyword pythonBuiltinFunc bin bool bytearray bytes
439-
syn keyword pythonBuiltinFunc chr classmethod cmp compile complex
440-
syn keyword pythonBuiltinFunc delattr dict dir divmod enumerate eval
441-
syn keyword pythonBuiltinFunc filter float format frozenset getattr
442-
syn keyword pythonBuiltinFunc globals hasattr hash hex id
443-
syn keyword pythonBuiltinFunc input int isinstance
444-
syn keyword pythonBuiltinFunc issubclass iter len list locals map max
445-
syn keyword pythonBuiltinFunc min next object oct open ord
446-
syn keyword pythonBuiltinFunc pow property range
447-
syn keyword pythonBuiltinFunc repr reversed round set setattr
448-
syn keyword pythonBuiltinFunc slice sorted staticmethod str sum super tuple
449-
syn keyword pythonBuiltinFunc type vars zip
437+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(__import__|abs|all|any)>'
438+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(bin|bool|bytearray|bytes)>'
439+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(chr|classmethod|cmp|compile|complex)>'
440+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(delattr|dict|dir|divmod|enumerate|eval)>'
441+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(filter|float|format|frozenset|getattr)>'
442+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(globals|hasattr|hash|hex|id)>'
443+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(input|int|isinstance)>'
444+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(issubclass|iter|len|list|locals|map|max)>'
445+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(min|next|object|oct|open|ord)>'
446+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(pow|property|range)>'
447+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(repr|reversed|round|set|setattr)>'
448+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(slice|sorted|staticmethod|str|sum|super|tuple)>'
449+
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(type|vars|zip)>'
450450
endif
451451

452452
"

0 commit comments

Comments
 (0)