mirror of
https://github.com/neovim/neovim.git
synced 2026-11-02 20:30:40 -06:00
vim-patch:632fd8b: runtime(python): Highlight built-in constants in Python
Also add syntax tests for those newly constants. closes: vim/vim#17788 closes: vim/vim#18922 https://github.com/vim/vim/commit/632fd8bb968b029d0a7c40a00101008ea5200b91 Co-authored-by: Rob B <github@0x7e.net>
This commit is contained in:
1 parent
d6fc5cbf55
commit
6543217afc
2 files changed
+22
-7
No files matched your search
@@ -2732,7 +2732,7 @@ Pascal. Use this if you don't use assembly and Pascal: >
|
||||
|
||||
PYTHON *ft-python-syntax*
|
||||
|
||||
There are six options to control Python syntax highlighting.
|
||||
There are seven options to control Python syntax highlighting.
|
||||
|
||||
For highlighted numbers: >
|
||||
:let python_no_number_highlight = 1
|
||||
@@ -2752,14 +2752,17 @@ The first option implies the second one.
|
||||
For highlighted trailing whitespace and mix of spaces and tabs: >
|
||||
:let python_space_error_highlight = 1
|
||||
|
||||
For highlighted built-in constants distinguished from other keywords:
|
||||
:let python_constant_highlight = 1
|
||||
|
||||
If you want all possible Python highlighting: >
|
||||
:let python_highlight_all = 1
|
||||
This has the same effect as setting python_space_error_highlight and
|
||||
unsetting all the other ones.
|
||||
This has the same effect as setting python_space_error_highlight,
|
||||
python_constant_highlight and unsetting all the other ones.
|
||||
|
||||
If you use Python 2 or straddling code (Python 2 and 3 compatible),
|
||||
you can enforce the use of an older syntax file with support for
|
||||
Python 2 and up to Python 3.5. >
|
||||
Python 2 and up to Python 3.5. >
|
||||
:let python_use_python2_syntax = 1
|
||||
This option will exclude all modern Python 3.6 or higher features.
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
" Last Change: 2025 Sep 08
|
||||
" 2025 Sep 25 by Vim Project: fix wrong type highlighting #18394
|
||||
" 2025 Dec 03 by Vim Project: highlight t-strings #18679
|
||||
" 2026 Jan 26 by Vim Project: highlight constants #18922
|
||||
" Credits: Neil Schemenauer <nas@python.ca>
|
||||
" Dmitry Vasiliev
|
||||
" Rob B
|
||||
@@ -34,6 +35,7 @@
|
||||
" let python_no_exception_highlight = 1
|
||||
" let python_no_number_highlight = 1
|
||||
" let python_space_error_highlight = 1
|
||||
" let python_constant_highlight = 1
|
||||
"
|
||||
" All the options above can be switched on together.
|
||||
"
|
||||
@@ -85,6 +87,7 @@ if exists("python_highlight_all")
|
||||
unlet python_no_number_highlight
|
||||
endif
|
||||
let python_space_error_highlight = 1
|
||||
let python_constant_highlight = 1
|
||||
endif
|
||||
|
||||
" Keep Python keywords in alphabetical order inside groups for easy
|
||||
@@ -97,7 +100,8 @@ endif
|
||||
"
|
||||
" python3 -c 'import keyword, pprint; pprint.pprint(keyword.kwlist + keyword.softkwlist, compact=True)'
|
||||
"
|
||||
syn keyword pythonStatement False None True
|
||||
syn keyword pythonBoolean False True
|
||||
syn keyword pythonConstant None
|
||||
syn keyword pythonStatement as assert break continue del global
|
||||
syn keyword pythonStatement lambda nonlocal pass return with yield
|
||||
syn keyword pythonStatement class nextgroup=pythonClass skipwhite
|
||||
@@ -296,8 +300,8 @@ endif
|
||||
if !exists("python_no_builtin_highlight")
|
||||
" built-in constants
|
||||
" 'False', 'True', and 'None' are also reserved words in Python 3
|
||||
syn keyword pythonBuiltin False True None
|
||||
syn keyword pythonBuiltin NotImplemented Ellipsis __debug__
|
||||
syn keyword pythonBoolean False True
|
||||
syn keyword pythonConstant None NotImplemented Ellipsis __debug__
|
||||
" constants added by the `site` module
|
||||
syn keyword pythonBuiltin quit exit copyright credits license
|
||||
" built-in functions
|
||||
@@ -391,6 +395,8 @@ endif
|
||||
syn sync match pythonSync grouphere NONE "^\%(def\|class\|async\s\+def\)\s\+\h\w*\s*[(:]"
|
||||
|
||||
" The default highlight links. Can be overridden later.
|
||||
hi def link pythonBoolean Statement
|
||||
hi def link pythonConstant Statement
|
||||
hi def link pythonStatement Statement
|
||||
hi def link pythonConditional Conditional
|
||||
hi def link pythonRepeat Repeat
|
||||
@@ -421,6 +427,8 @@ if !exists("python_no_number_highlight")
|
||||
hi def link pythonNumber Number
|
||||
endif
|
||||
if !exists("python_no_builtin_highlight")
|
||||
hi! def link pythonBoolean Function
|
||||
hi! def link pythonConstant Function
|
||||
hi def link pythonBuiltin Function
|
||||
hi def link pythonEllipsis pythonBuiltin
|
||||
endif
|
||||
@@ -434,6 +442,10 @@ if !exists("python_no_doctest_highlight")
|
||||
hi def link pythonDoctest Special
|
||||
hi def link pythonDoctestValue Define
|
||||
endif
|
||||
if exists("python_constant_highlight")
|
||||
hi! def link pythonBoolean Boolean
|
||||
hi! def link pythonConstant Constant
|
||||
endif
|
||||
|
||||
let b:current_syntax = "python"
|
||||
|
||||
|
||||
Reference in new issue
Block a user