diff options
author | David Jimenez <dvejmz@users.noreply.github.com> | 2019-01-02 13:51:03 +0000 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-01-02 14:51:03 +0100 |
commit | 8f288698e4730f6cc91240fe899e93921aff9d71 (patch) | |
tree | 638a46ca5a47d9613ad9957ae5498605817e2404 /runtime | |
parent | 5a11e553588f90f3c945222d89ee3ff80cfc3fc7 (diff) | |
download | rneovim-8f288698e4730f6cc91240fe899e93921aff9d71.tar.gz rneovim-8f288698e4730f6cc91240fe899e93921aff9d71.tar.bz2 rneovim-8f288698e4730f6cc91240fe899e93921aff9d71.zip |
vim-patch:8.0.0251: not easy to select Python 2 or 3 (#9173)
Problem: It is not so easy to write a script that works with both Python 2 and Python 3, even when the Python code works with both.
Solution: Add 'pyxversion', :pyx, etc. (Marc Weber, Ken Takata)
https://github.com/vim/vim/commit/f42dd3c3901ea0ba38e67a616aea9953cae81b8d
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/eval.txt | 8 | ||||
-rw-r--r-- | runtime/doc/if_pyth.txt | 54 | ||||
-rw-r--r-- | runtime/doc/index.txt | 4 | ||||
-rw-r--r-- | runtime/doc/options.txt | 24 | ||||
-rw-r--r-- | runtime/doc/quickref.txt | 1 | ||||
-rw-r--r-- | runtime/optwin.vim | 6 |
6 files changed, 96 insertions, 1 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index e9579d5c86..7b463aa6ca 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2209,6 +2209,7 @@ printf({fmt}, {expr1}...) String format text pumvisible() Number whether popup menu is visible pyeval({expr}) any evaluate |Python| expression py3eval({expr}) any evaluate |python3| expression +pyxeval({expr}) any evaluate |python_x| expression range({expr} [, {max} [, {stride}]]) List items from {expr} to {max} readfile({fname} [, {binary} [, {max}]]) @@ -6146,6 +6147,12 @@ pyeval({expr}) *pyeval()* non-string keys result in error. {only available when compiled with the |+python| feature} +pyxeval({expr}) *pyxeval()* + Evaluate Python expression {expr} and return its result + converted to Vim data structures. + Uses Python 2 or 3, see |python_x| and 'pyxversion'. + See also: |pyeval()|, |py3eval()| + *E726* *E727* range({expr} [, {max} [, {stride}]]) *range()* Returns a |List| with Numbers: @@ -8517,6 +8524,7 @@ printer Compiled with |:hardcopy| support. profile Compiled with |:profile| support. python Legacy Vim Python 2.x API is available. |has-python| python3 Legacy Vim Python 3.x API is available. |has-python| +pythonx Compiled with |python_x| interface. |has-pythonx| quickfix Compiled with |quickfix| support. reltime Compiled with |reltime()| support. rightleft Compiled with 'rightleft' support. diff --git a/runtime/doc/if_pyth.txt b/runtime/doc/if_pyth.txt index 2da2e5147b..df4b54ef76 100644 --- a/runtime/doc/if_pyth.txt +++ b/runtime/doc/if_pyth.txt @@ -692,6 +692,7 @@ vim.Function object *python-Function* To facilitate bi-directional interface, you can use |pyeval()| and |py3eval()| functions to evaluate Python expressions and pass their values to Vim script. +|pyxeval()| is also available. ============================================================================== 9. Python 3 *python3* @@ -723,4 +724,57 @@ You can test what Python version is available with: > endif ============================================================================== +10. Python X *python_x* *pythonx* + +Because most python code can be written so that it works with Python 2.6+ and +Python 3, the pyx* functions and commands have been written. They work the +same as the Python 2 and 3 variants, but select the Python version using the +'pyxversion' setting. + +Set 'pyxversion' in your |vimrc| to prefer Python 2 or Python 3 for Python +commands. Changing this setting at runtime risks losing the state of plugins +(such as initialization). + +If you want to use a module, you can put it in the {rtp}/pythonx directory. +See |pythonx-directory|. + + *:pyx* *:pythonx* +`:pyx` and `:pythonx` work similar to `:python`. To check if `:pyx` works: > + :pyx print("Hello") + +To see what version of Python is being used: > + :pyx import sys + :pyx print(sys.version) +< + *:pyxfile* *python_x-special-comments* +`:pyxfile` works similar to `:pyfile`. But you can add a "shebang" comment to +force Vim to use `:pyfile` or `:py3file`: > + #!/any string/python2 " Shebang. Must be the first line of the file. + #!/any string/python3 " Shebang. Must be the first line of the file. + # requires python 2.x " Maximum lines depend on 'modelines'. + # requires python 3.x " Maximum lines depend on 'modelines'. +Unlike normal modelines, the bottom of the file is not checked. +If none of them are found, the 'pyxversion' option is used. + *W20* *W21* +If Vim does not support the selected Python version a silent message will be +printed. Use `:messages` to read them. + + *:pyxdo* +`:pyxdo` works similar to `:pydo`. + + *has-pythonx* +To check if pyx* functions and commands are available: > + if has('pythonx') + echo 'pyx* commands are available. (Python ' . &pyx . ')' + endif + +If you prefer Python 2 and want to fallback to Python 3, set 'pyxversion' +explicitly in your |.vimrc|. Example: > + if has('python') + set pyx=2 + elseif has('python3') + set pyx=3 + endif + +============================================================================== vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/runtime/doc/index.txt b/runtime/doc/index.txt index 7024a57333..63ded3152f 100644 --- a/runtime/doc/index.txt +++ b/runtime/doc/index.txt @@ -1418,6 +1418,10 @@ tag command action ~ |:python| :py[thon] execute Python command |:pydo| :pyd[o] execute Python command for each line |:pyfile| :pyf[ile] execute Python script file +|:pyx| :pyx execute |python_x| command +|:pythonx| :pythonx same as :pyx +|:pyxdo| :pyxd[o] execute |python_x| command for each line +|:pyxfile| :pyxf[ile] execute |python_x| script file |:quit| :q[uit] quit current window (when one window quit Vim) |:quitall| :quita[ll] quit Vim |:qall| :qa[ll] quit Vim diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 534b2025cd..bcefa1f56b 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -4471,6 +4471,30 @@ A jump table for the options with a short description can be found at |Q_op|. Insert mode completion. When zero as much space as available is used. |ins-completion-menu|. + *'pyxversion'* *'pyx'* +'pyxversion' 'pyx' number (default depends on the build) + global + Specifies the python version used for pyx* functions and commands + |python_x|. The default value is as follows: + + |provider| installed Default ~ + |+python| and |+python3| 0 + only |+python| 2 + only |+python3| 3 + + Available values are 0, 2 and 3. + If 'pyxversion' is 0, it is set to 2 or 3 after the first execution of + any python2/3 commands or functions. E.g. `:py` sets to 2, and `:py3` + sets to 3. `:pyx` sets it to 3 if Python 3 is available, otherwise sets + to 2 if Python 2 is available. + See also: |has-pythonx| + + If only |+python| or |+python3| are available, + 'pyxversion' has no effect. The pyx* functions and commands are + always the same as the installed version. + + This option cannot be set from a |modeline| or in the |sandbox|, for + security reasons. *'quoteescape'* *'qe'* 'quoteescape' 'qe' string (default "\") diff --git a/runtime/doc/quickref.txt b/runtime/doc/quickref.txt index cf0efd7a75..98a5244345 100644 --- a/runtime/doc/quickref.txt +++ b/runtime/doc/quickref.txt @@ -813,6 +813,7 @@ Short explanation of each option: *option-list* 'pumwidth' 'pw' minimum width of the popup menu 'pythondll' name of the Python 2 dynamic library 'pythonthreedll' name of the Python 3 dynamic library +'pyxversion' 'pyx' Python version used for pyx* commands 'quoteescape' 'qe' escape characters used in a string 'readonly' 'ro' disallow writing the buffer 'redrawtime' 'rdt' timeout for 'hlsearch' and |:match| highlighting diff --git a/runtime/optwin.vim b/runtime/optwin.vim index 1742c64c3e..2e9f4723dd 100644 --- a/runtime/optwin.vim +++ b/runtime/optwin.vim @@ -905,7 +905,7 @@ if has("folding") call append("$", "foldmarker\tmarkers used when 'foldmethod' is \"marker\"") call append("$", "\t(local to window)") call <SID>OptionL("fmr") - call append("$", "foldnestmax\tmaximum fold depth for when 'foldmethod is \"indent\" or \"syntax\"") + call append("$", "foldnestmax\tmaximum fold depth for when 'foldmethod' is \"indent\" or \"syntax\"") call append("$", "\t(local to window)") call <SID>OptionL("fdn") endif @@ -1295,6 +1295,10 @@ if exists("&mzschemedll") call append("$", "mzschemegcdll\tname of the Tcl GC dynamic library") call <SID>OptionG("mzschemegcdll", &mzschemegcdll) endif +if has('pythonx') + call append("$", "pyxversion\twhether to use Python 2 or 3") + call append("$", " \tset pyx=" . &wd) +endif " Install autocommands to enable mappings in option-window noremap <silent> <buffer> <CR> <C-\><C-N>:call <SID>CR()<CR> |