On 08/19/2011 10:29 PM, Bram Moolenaar wrote:
Roland Puntaier wrote:

E836: This Vim cannot execute :python after using :py3
This happened to me several times already when changing to a buffer with
python code, e.g. to my .vimrc file. The reason was that omnifunc was
set to pythoncomplete#Complete.
Correction: the reason was that has("python") issued the error if I had used :py3.

Python 2.6 and python 2.7 have had changes to make it more compatible
with python3. It is now quite easy to write code that works for both,
python2.x and python3.x.
You mean Python 2.6, 2.7 and 3.x.  Not for Python 2.5 and earlier.

With the error message triggering and the latter thought I tried to go
for the following: forward to the other python command.

- The first time vim realizes that it cannot run python (py3) because of
the RTLD problem this error message is issued:

          E836: This Vim cannot execute :python after using :py3. Will
forward future calls to :py3.
or
          E837: This Vim cannot execute :py3 after using :python. Will
forward future calls to python.

    (Of course, I've not changed the translations of the these messages.)
- The second time the python command is forwarded to the other python
command
- If the system/python version allows both, python 2.x and python 3.x,
there is no forwarding.
- This applies only if vim is configure for both python versions

If somebody has a script, which uses either :py3 or :python, the
following sequence in the .vimrc as first python interaction will
redirect all calls to :py3.

      "redirect :python to :py3
      py3 3
      python 2
      "argument has no meaning

If the order is changed :py3 calls will be redirected to :python.

@Bram: If you agree, please merge it to the main vim line.

@Aaron: Since the changes in python3complete.vim do work for python 2.6
and python 2.7 (I've test it), I have moved it to pythoncomplete.vim.
The patch contains this move. The original pythoncomplete.vim I've moved
to python25complete.vim with according internal renaming. It is attached.
Do you agree with this proceeding?
I'm moving to ArchLinux and in the vim package there pythoncomplete.vim
is separate. The same version is already included in the vim sources.
I know quite a few people use Python 2.4, because some scripts don't
work with later versions.
This is about my change in pythoncomplete.vim.
I agree.

@Aaron: No change regarding pythoncomplete.vim and python3complete.vim.

I don't like getting an error only the first time something goes wrong,
it can easily be missed.

Why not add a way to ask Vim what Python versions are available.  This
can use PYTHON_API_VERSION or PY_VERSION_HEX.  Depending on that a
script can try loading the version it wants and check with has() if it's
actually available.  Then define a user command with :py3 or :python, as
desired.  Or give an error message if the Python version is not
supported.

Something like:

      if pythonversion() =~ '2\.[67]'&&  has('python')
        command Pyt python
      elseif pythonversion() =~ '3\.'&&  has('python3')
        command Pyt py3
      else
        echoerr "No usable Python version"
      endif

A function like
interpreter_version('lua'|'mzscheme'|'perl'|'python'|'python3'|'ruby'|'tcl')
wouldn't harm, but it's not needed.
If we know whether Python2 or Python3 then the rest can be found out by a Python script. The same is true for the other interpreters, else such a function would have been missed.

It is enough when has() takes into account the case where
both 2.x and 3.x are configured but only one can be active per VIM instance. *Then has() should return true only for the active one and not issue an error.*

The change in has() and some little adaptations in vim files are attached.

Thanks.
- Roland

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff -r 3edc4535acfa runtime/ftplugin/python.vim
--- a/runtime/ftplugin/python.vim       Wed Aug 10 18:36:54 2011 +0200
+++ b/runtime/ftplugin/python.vim       Sat Aug 20 16:59:28 2011 +0200
@@ -14,7 +14,11 @@
 setlocal comments-=:%
 setlocal commentstring=#%s
 
-setlocal omnifunc=pythoncomplete#Complete
+if has("python")
+    setlocal omnifunc=pythoncomplete#Complete
+elseif has("python3")
+    setlocal omnifunc=python3complete#Complete
+endif
 
 set wildignore+=*.pyc
 
diff -r 3edc4535acfa runtime/syntax/aap.vim
--- a/runtime/syntax/aap.vim    Wed Aug 10 18:36:54 2011 +0200
+++ b/runtime/syntax/aap.vim    Sat Aug 20 16:59:28 2011 +0200
@@ -118,9 +118,9 @@
 " A Python line starts with @.  Can be continued with a trailing backslash.
 syn region aapPythonRegion start="\s*@" skip='\\$' end=+$+ 
contains=@aapPythonScript keepend
 "
-" A Python block starts with ":python" and continues so long as the indent is
+" A Python block starts with ":python" or ":py3" and continues so long as the 
indent is
 " bigger.
-syn region aapPythonRegion matchgroup=aapCommand start="\z(\s*\):python" 
skip='\n\z1\s\|\n\s*\n' end=+$+ contains=@aapPythonScript
+syn region aapPythonRegion matchgroup=aapCommand 
start="\z(\s*\)\(:python\|:py3\)" skip='\n\z1\s\|\n\s*\n' end=+$+ 
contains=@aapPythonScript
 
 " A Python expression is enclosed in backticks.
 syn region aapPythonRegion start="`" skip="``" end="`" 
contains=@aapPythonScript
diff -r 3edc4535acfa runtime/syntax/vim.vim
--- a/runtime/syntax/vim.vim    Wed Aug 10 18:36:54 2011 +0200
+++ b/runtime/syntax/vim.vim    Sat Aug 20 16:59:28 2011 +0200
@@ -619,7 +619,7 @@
 if !filereadable(s:pythonpath)
  let s:pythonpath= fnameescape(globpath(&rtp,"syntax/python.vim"))
 endif
-if (g:vimsyn_embed =~ 'P' && has("python")) && filereadable(s:pythonpath)
+if (g:vimsyn_embed =~ 'P' && (has("python") || has("python3"))) && 
filereadable(s:pythonpath)
  unlet! b:current_syntax
  exe "syn include @vimPythonScript ".s:pythonpath
  if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'P'
diff -r 3edc4535acfa src/eval.c
--- a/src/eval.c        Wed Aug 10 18:36:54 2011 +0200
+++ b/src/eval.c        Sat Aug 20 16:59:28 2011 +0200
@@ -12304,13 +12304,34 @@
 #ifdef FEAT_PYTHON
 #ifdef DYNAMIC_PYTHON
        else if (STRICMP(name, "python") == 0)
-           n = python_enabled(FALSE);
+        {
+#if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && 
defined(UNIX) && defined(FEAT_PYTHON3)
+            /* Can't have Python and Python3 loaded at the same time.
+             * It cause a crash, because RTLD_GLOBAL is needed for
+             * standard C extension libraries of one or both python versions. 
*/
+            if (python3_loaded())
+                n = FAIL;
+            else
+#endif
+                n = python_enabled(FALSE);
+        }
 #endif
 #endif
 #ifdef FEAT_PYTHON3
 #ifdef DYNAMIC_PYTHON3
        else if (STRICMP(name, "python3") == 0)
-           n = python3_enabled(FALSE);
+        {
+
+# if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && 
defined(UNIX) && defined(FEAT_PYTHON)
+            /* Can't have Python and Python3 loaded at the same time.
+             * It cause a crash, because RTLD_GLOBAL is needed for
+             * standard C extension libraries of one or both python versions. 
*/
+            if (python_loaded())
+                n = FAIL;
+            else
+# endif
+                n = python3_enabled(FALSE);
+        }
 #endif
 #endif
 #ifdef DYNAMIC_PERL

Raspunde prin e-mail lui