mirror of
https://github.com/gryf/python-syntax.git
synced 2025-12-19 12:28:13 +01:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69f8e12a46 | ||
|
|
21a2e84df6 | ||
|
|
9ccbd6196b | ||
|
|
6f6f10ff54 | ||
|
|
a0d21acc1c | ||
|
|
ebbdd093b7 | ||
|
|
fc6a66bf80 | ||
|
|
e344f212b6 | ||
|
|
91eaa32bea | ||
|
|
2860070a9d | ||
|
|
40456e7708 | ||
|
|
16f0987559 |
25
CHANGES.txt
25
CHANGES.txt
@@ -1,3 +1,28 @@
|
||||
Revision 3.3.5 (2013-08-31):
|
||||
|
||||
- Highlight 'import', 'from' and 'as' as include statements.
|
||||
Patch by pydave at GitHub.
|
||||
- Added new option 'python_highlight_file_headers_as_comments' (disabled by
|
||||
default) to highlight shebang and coding file headers as comments.
|
||||
Proposed by pydave at GitHub.
|
||||
|
||||
Revision 3.3.4 (2013-08-11):
|
||||
|
||||
- Highlight True and False as booleans. Patch by Yuri Habrusiev.
|
||||
|
||||
Revision 3.3.3 (2013-06-02):
|
||||
|
||||
- More lightweight syntax reloading. Patch by Will Gray.
|
||||
|
||||
Revision 3.3.2 (2013-06-01):
|
||||
|
||||
- Fixed behaviour of b:python_version_2 variable. Reported by Will Gray.
|
||||
|
||||
Revision 3.3.1 (2013-05-12):
|
||||
|
||||
- The script was moved to its own repository at
|
||||
https://github.com/hdima/python-syntax
|
||||
|
||||
Revision 3.3.0 (2013-03-10):
|
||||
|
||||
- Merge Python 2 and Python 3 script versions into the single python.vim
|
||||
|
||||
142
README.rst
Normal file
142
README.rst
Normal file
@@ -0,0 +1,142 @@
|
||||
Python syntax highlighting script for Vim
|
||||
=========================================
|
||||
|
||||
.. contents::
|
||||
|
||||
About
|
||||
-----
|
||||
|
||||
Enhanced version of the original Python syntax highlighting script. Based on
|
||||
``python.vim`` from Vim 6.1 distribution by Neil Schemenauer (nas at python dot
|
||||
ca). Check also `python.vim page on vim.org
|
||||
<http://www.vim.org/scripts/script.php?script_id=790>`_.
|
||||
|
||||
Please use the following channels for reporting bugs, offering suggestions or
|
||||
feedback:
|
||||
|
||||
- python.vim issue tracker: https://github.com/hdima/python-syntax/issues
|
||||
- Email: Dmitry Vasiliev (dima at hlabs.org)
|
||||
- Send a message or follow me for updates on Twitter: `@hdima
|
||||
<https://twitter.com/hdima>`__
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
Changes from the original ``python.vim`` are:
|
||||
|
||||
- Added support for Python 3 syntax highlighting
|
||||
- Added ``:Python2Syntax`` and ``:Python3Syntax`` commands which allow to
|
||||
switch between Python 2 and Python 3 syntaxes respectively without
|
||||
reloads/restarts
|
||||
- Updated strings highlighting
|
||||
- Enhanced special symbols highlighting inside strings
|
||||
- Enhanced highlighting of numeric constants
|
||||
- Added optional highlighting for %-formatting inside strings
|
||||
- Added highlighting for magic comments: source code encoding and #!
|
||||
(executable) strings
|
||||
- Added highlighting for new exceptions and builtins
|
||||
- Added highlighting for doctests
|
||||
- Added highlighting for new ``@decorator`` syntax introduced in Python 2.4a2
|
||||
- Added highlighting for the following errors:
|
||||
|
||||
- invalid symbols in source file
|
||||
- mixing spaces and tabs
|
||||
- invalid numeric constants
|
||||
- invalid %-formatting inside strings
|
||||
- invalid variable names
|
||||
- trailing spaces (triggered by the ``python_highlight_space_errors`` option)
|
||||
|
||||
Some of these features was later backported into the original ``python.vim``.
|
||||
|
||||
How to install
|
||||
--------------
|
||||
|
||||
The easiest installation method is to place `syntax/python.vim
|
||||
<https://github.com/hdima/python-syntax/blob/master/syntax/python.vim>`_ script
|
||||
into your ``~/.vim/syntax/`` directory.
|
||||
|
||||
You can also use `Pathogen <https://github.com/tpope/vim-pathogen>`_ or `Vundle
|
||||
<https://github.com/gmarik/vundle>`_ plugin managers in which case you can
|
||||
install the whole `python.vim repository
|
||||
<https://github.com/hdima/python-syntax>`_ into the corresponding plugins
|
||||
directory.
|
||||
|
||||
Script options
|
||||
--------------
|
||||
|
||||
There are two commands to enable or disable an option:
|
||||
|
||||
``:let OPTION_NAME = 1``
|
||||
Enable option
|
||||
``:let OPTION_NAME = 0``
|
||||
Disable option
|
||||
|
||||
For example to enable all syntax highlighting features you can place the
|
||||
following command in your ``~/.vimrc`` script::
|
||||
|
||||
let python_highlight_all = 1
|
||||
|
||||
Option and commands to select Python version
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
``python_version_2``
|
||||
Enable highlighting for Python 2 (Python 3 highlighting is enabled by
|
||||
default). Can also be set as a local to buffer ``b:python_version_2``
|
||||
variable.
|
||||
|
||||
The following local to buffer commands can be used to switch between two
|
||||
highlighting modes:
|
||||
|
||||
``:Python2Syntax``
|
||||
Switch to Python 2 highlighting mode
|
||||
``:Python3Syntax``
|
||||
Switch to Python 3 highlighting mode
|
||||
|
||||
Options used by the script
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
``python_highlight_builtins``
|
||||
Highlight builtin functions and objects
|
||||
``python_highlight_builtin_objs``
|
||||
Highlight builtin objects only
|
||||
``python_highlight_builtin_funcs``
|
||||
Highlight builtin functions only
|
||||
``python_highlight_exceptions``
|
||||
Highlight standard exceptions
|
||||
``python_highlight_string_formatting``
|
||||
Highlight ``%`` string formatting
|
||||
``python_highlight_string_format``
|
||||
Highlight syntax of ``str.format`` syntax
|
||||
``python_highlight_string_templates``
|
||||
Highlight syntax of ``string.Template``
|
||||
``python_highlight_indent_errors``
|
||||
Highlight indentation errors
|
||||
``python_highlight_space_errors``
|
||||
Highlight trailing spaces
|
||||
``python_highlight_doctests``
|
||||
Highlight doc-tests
|
||||
``python_print_as_function``
|
||||
Highlight ``print`` statement as function for Python 2
|
||||
``python_highlight_file_headers_as_comments``
|
||||
Highlight shebang and coding headers as comments
|
||||
``python_highlight_all``
|
||||
Enable all the options above. *NOTE: This option don't override any
|
||||
previously set options*
|
||||
``python_slow_sync``
|
||||
Can be set to 0 for slow machines
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
List of the contributors in alphabetical order:
|
||||
|
||||
- Andrea Riciputi
|
||||
- Anton Butanaev
|
||||
- Caleb Adamantine
|
||||
- Jeroen Ruigrok van der Werven
|
||||
- John Eikenberry
|
||||
- Marc Weber
|
||||
- Pedro Algarvio
|
||||
- pydave at GitHub
|
||||
- Will Gray
|
||||
- Yuri Habrusiev
|
||||
@@ -1,33 +1,37 @@
|
||||
" Vim syntax file
|
||||
" Language: Python
|
||||
" Maintainer: Dmitry Vasiliev <dima at hlabs dot org>
|
||||
" URL: https://github.com/hdima/vim-scripts/blob/master/syntax/python/python.vim
|
||||
" Last Change: 2013-03-10
|
||||
" URL: https://github.com/hdima/python-syntax
|
||||
" Last Change: 2013-08-31
|
||||
" Filenames: *.py
|
||||
" Version: 3.3.0
|
||||
" Version: 3.3.5
|
||||
"
|
||||
" Based on python.vim (from Vim 6.1 distribution)
|
||||
" by Neil Schemenauer <nas at python dot ca>
|
||||
"
|
||||
" Bugs and feature requests can be reported through email
|
||||
" <dima at hlabs dot org>, GitHub at:
|
||||
"
|
||||
" https://github.com/hdima/vim-scripts/issues
|
||||
"
|
||||
" , or Twitter:
|
||||
"
|
||||
" https://twitter.com/hdima
|
||||
" Please use the following channels for reporting bugs, offering suggestions or
|
||||
" feedback:
|
||||
|
||||
" - python.vim issue tracker: https://github.com/hdima/python-syntax/issues
|
||||
" - Email: Dmitry Vasiliev (dima at hlabs.org)
|
||||
" - Send a message or follow me for updates on Twitter: `@hdima
|
||||
" <https://twitter.com/hdima>`__
|
||||
"
|
||||
" Contributors
|
||||
" ============
|
||||
"
|
||||
" Jeroen Ruigrok van der Werven
|
||||
" Pedro Algarvio
|
||||
" John Eikenberry
|
||||
" Caleb Adamantine
|
||||
" List of the contributors in alphabetical order:
|
||||
"
|
||||
" Andrea Riciputi
|
||||
" Anton Butanaev
|
||||
" Caleb Adamantine
|
||||
" Jeroen Ruigrok van der Werven
|
||||
" John Eikenberry
|
||||
" Marc Weber
|
||||
" Pedro Algarvio
|
||||
" pydave at GitHub
|
||||
" Will Gray
|
||||
" Yuri Habrusiev
|
||||
"
|
||||
" Options
|
||||
" =======
|
||||
@@ -69,6 +73,9 @@
|
||||
" python_highlight_doctests Highlight doc-tests
|
||||
" python_print_as_function Highlight 'print' statement as
|
||||
" function for Python 2
|
||||
" python_highlight_file_headers_as_comments
|
||||
" Highlight shebang and coding
|
||||
" headers as comments
|
||||
"
|
||||
" python_highlight_all Enable all the options above
|
||||
" NOTE: This option don't override
|
||||
@@ -88,8 +95,8 @@ endif
|
||||
"
|
||||
" Commands
|
||||
"
|
||||
command! -buffer Python2Syntax let b:python_version_2 = 1 | if exists("g:syntax_on") | syn off | endif | syn enable
|
||||
command! -buffer Python3Syntax let b:python_version_2 = 0 | if exists("g:syntax_on") | syn off | endif | syn enable
|
||||
command! -buffer Python2Syntax let b:python_version_2 = 1 | let &syntax=&syntax
|
||||
command! -buffer Python3Syntax let b:python_version_2 = 0 | let &syntax=&syntax
|
||||
|
||||
" Enable option if it's not defined
|
||||
function! s:EnableByDefault(name)
|
||||
@@ -100,12 +107,15 @@ endfunction
|
||||
|
||||
" Check if option is enabled
|
||||
function! s:Enabled(name)
|
||||
return exists(a:name) && {a:name} != 0
|
||||
return exists(a:name) && {a:name}
|
||||
endfunction
|
||||
|
||||
" Is it Python 2 syntax?
|
||||
function! s:Python2Syntax()
|
||||
return s:Enabled("b:python_version_2") || s:Enabled("g:python_version_2")
|
||||
if exists("b:python_version_2")
|
||||
return b:python_version_2
|
||||
endif
|
||||
return s:Enabled("g:python_version_2")
|
||||
endfunction
|
||||
|
||||
"
|
||||
@@ -143,7 +153,7 @@ syn keyword pythonStatement with
|
||||
syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
|
||||
syn keyword pythonRepeat for while
|
||||
syn keyword pythonConditional if elif else
|
||||
syn keyword pythonPreCondit import from
|
||||
syn keyword pythonImport import from
|
||||
syn keyword pythonException try except finally
|
||||
syn keyword pythonOperator and in is not or
|
||||
|
||||
@@ -151,10 +161,11 @@ if s:Python2Syntax()
|
||||
if !s:Enabled("g:python_print_as_function")
|
||||
syn keyword pythonStatement print
|
||||
endif
|
||||
syn keyword pythonPreCondit as
|
||||
syn keyword pythonImport as
|
||||
syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained
|
||||
else
|
||||
syn keyword pythonStatement as nonlocal False None True
|
||||
syn keyword pythonStatement as nonlocal None
|
||||
syn keyword pythonBoolean True False
|
||||
syn match pythonFunction "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
|
||||
endif
|
||||
|
||||
@@ -171,8 +182,10 @@ syn match pythonDot "\." display containedin=pythonDottedName
|
||||
"
|
||||
|
||||
syn match pythonComment "#.*$" display contains=pythonTodo,@Spell
|
||||
syn match pythonRun "\%^#!.*$"
|
||||
syn match pythonCoding "\%^.*\%(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
|
||||
if !s:Enabled("g:python_highlight_file_headers_as_comments")
|
||||
syn match pythonRun "\%^#!.*$"
|
||||
syn match pythonCoding "\%^.*\%(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
|
||||
endif
|
||||
syn keyword pythonTodo TODO FIXME XXX contained
|
||||
|
||||
"
|
||||
@@ -365,7 +378,8 @@ syn match pythonFloat "\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=" display
|
||||
|
||||
if s:Enabled("g:python_highlight_builtin_objs")
|
||||
if s:Python2Syntax()
|
||||
syn keyword pythonBuiltinObj True False None
|
||||
syn keyword pythonBuiltinObj None
|
||||
syn keyword pythonBoolean True False
|
||||
endif
|
||||
syn keyword pythonBuiltinObj Ellipsis NotImplemented
|
||||
syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__
|
||||
@@ -461,7 +475,7 @@ if version >= 508 || !exists("did_python_syn_inits")
|
||||
endif
|
||||
|
||||
HiLink pythonStatement Statement
|
||||
HiLink pythonPreCondit Statement
|
||||
HiLink pythonImport Include
|
||||
HiLink pythonFunction Function
|
||||
HiLink pythonConditional Conditional
|
||||
HiLink pythonRepeat Repeat
|
||||
@@ -473,8 +487,10 @@ if version >= 508 || !exists("did_python_syn_inits")
|
||||
HiLink pythonDot Normal
|
||||
|
||||
HiLink pythonComment Comment
|
||||
if !s:Enabled("g:python_highlight_file_headers_as_comments")
|
||||
HiLink pythonCoding Special
|
||||
HiLink pythonRun Special
|
||||
endif
|
||||
HiLink pythonTodo Todo
|
||||
|
||||
HiLink pythonError Error
|
||||
@@ -518,6 +534,8 @@ if version >= 508 || !exists("did_python_syn_inits")
|
||||
HiLink pythonHexError Error
|
||||
HiLink pythonBinError Error
|
||||
|
||||
HiLink pythonBoolean Boolean
|
||||
|
||||
HiLink pythonBuiltinObj Structure
|
||||
HiLink pythonBuiltinFunc Function
|
||||
|
||||
Reference in New Issue
Block a user