Browse Source

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
Joongi Kim 7 years ago
parent
commit
31f669d00d
1 changed files with 19 additions and 19 deletions
  1. 19
    19
      syntax/python.vim

+ 19
- 19
syntax/python.vim View File

@@ -415,7 +415,7 @@ if s:Enabled("g:python_highlight_builtin_objs")
415 415
   if s:Python2Syntax()
416 416
     syn keyword pythonBuiltinObj	None False True
417 417
   endif
418
-  syn keyword pythonBuiltinObj	Ellipsis NotImplemented
418
+  syn keyword pythonBuiltinObj	Ellipsis NotImplemented self cls
419 419
   syn keyword pythonBuiltinObj	__debug__ __doc__ __file__ __name__ __package__
420 420
 endif
421 421
 
@@ -425,28 +425,28 @@ endif
425 425
 
426 426
 if s:Enabled("g:python_highlight_builtin_funcs")
427 427
   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)>'
431 431
     if s:Enabled("g:python_print_as_function")
432
-      syn keyword pythonBuiltinFunc	print
432
+      syn match pythonBuiltinFunc	'\v(\.)@<!\zs<(print)>'
433 433
     endif
434 434
   else
435
-    syn keyword pythonBuiltinFunc	ascii exec memoryview print
435
+    syn match pythonBuiltinFunc	'\v(\.)@<!\zs<(ascii|exec|memoryview|print)>'
436 436
   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)>'
450 450
 endif
451 451
 
452 452
 "