Loading ...
Sorry, an error occurred while loading the content.

[bugreport][syntax] syntax/vim.vim shows unexpected behaviour when vim only compiled with python 3 support.

Expand Messages
  • Tianjiao Yin
    Hello, all: When vim only compiled with python 3 support, and we write something in test.vim like: python3
    Message 1 of 4 , Oct 15, 2012
    • 0 Attachment
      Hello, all:

      When vim only compiled with python 3 support, and we write something
      in test.vim like:

      python3 << EOF
      print("Hello, world")
      EOF

      The highlight is not what we want. I think following line in
      $VIMRUNTIME/syntax/vim.vim is wrong:

      if (g:vimsyn_embed =~ 'P' && has("python")) && filereadable(s:pythonpath)

      has("python") is false, although has("python3") is true. We should use
      (has("python") || has("python3")) instead. Another solution is just
      drop has("python"). I have wrote a patch for this which attached to
      the letter.

      Regards,
      Mizuchi



      diff -ru vim-7.3.661/runtime/syntax/vim.vim
      vim-7.3.661-new/runtime/syntax/vim.vim
      --- vim-7.3.661/runtime/syntax/vim.vim 2012-09-15 11:47:31.000000000 +0800
      +++ vim-7.3.661-new/runtime/syntax/vim.vim 2012-10-16 04:11:30.114323907 +0800
      @@ -629,7 +629,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'

      --
      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
    • Bram Moolenaar
      ... For syntax file updates, please check the maintainer in the file header and send the patch to that person. Cc ing vim_dev is OK. I don t include these
      Message 2 of 4 , Oct 15, 2012
      • 0 Attachment
        Mizuchi wrote:

        > Hello, all:
        >
        > When vim only compiled with python 3 support, and we write something
        > in test.vim like:
        >
        > python3 << EOF
        > print("Hello, world")
        > EOF
        >
        > The highlight is not what we want. I think following line in
        > $VIMRUNTIME/syntax/vim.vim is wrong:
        >
        > if (g:vimsyn_embed =~ 'P' && has("python")) && filereadable(s:pythonpath)
        >
        > has("python") is false, although has("python3") is true. We should use
        > (has("python") || has("python3")) instead. Another solution is just
        > drop has("python"). I have wrote a patch for this which attached to
        > the letter.

        For syntax file updates, please check the maintainer in the file header
        and send the patch to that person. Cc'ing vim_dev is OK. I don't
        include these patches, because the next version from the maintainer
        would undo them. And the maintainer needs to check that it's correct.

        --
        CART DRIVER: Bring out your dead!
        There are legs stick out of windows and doors. Two MEN are fighting in the
        mud - covered from head to foot in it. Another MAN is on his hands in
        knees shovelling mud into his mouth. We just catch sight of a MAN falling
        into a well.
        "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ an exciting new programming language -- http://www.Zimbu.org ///
        \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

        --
        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
      • ZyX
        ... I would rather suggest removing these has() checks at all and for all interpreters. Why are they there? syntax/python.vim does work without +python, same
        Message 3 of 4 , Oct 16, 2012
        • 0 Attachment
          > When vim only compiled with python 3 support, and we write something
          > in test.vim like:
          >
          > python3 << EOF
          > print("Hello, world")
          > EOF
          >
          > The highlight is not what we want. I think following line in
          >
          > $VIMRUNTIME/syntax/vim.vim is wrong:
          >
          > if (g:vimsyn_embed =~ 'P' && has("python")) && filereadable(s:pythonpath)
          >
          > has("python") is false, although has("python3") is true. We should use
          > (has("python") || has("python3")) instead. Another solution is just
          > drop has("python"). I have wrote a patch for this which attached to
          > the letter.

          I would rather suggest removing these has() checks at all and for all interpreters. Why are they there? syntax/python.vim does work without +python, same for perl, ruby, lua, tcl and mzscheme. There should not be more then one check for existence of syntax script.

          And check for existence is invalid everywhere: it first tries to use file in the same directory as the syntax/vim.vim, then assumes that there is only one syntax/{interp}.vim file in rtp which may be false. It is better to use

          if stridx(g:vimsyn_embed, 'l')!=-1
          try
          syntax include @vimLuaScript syntax/lua.vim
          let s:use_lua=1
          catch /^Vim(syntax):E484:/
          let s:use_lua=0
          endtry
          if s:use_lua
          " Lua stuff goes here
          endif
          endif
          . Will create the patch in the evening.

          --
          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
        • ZyX
          ... # HG changeset patch # User ZyX # Date 1350488709 -14400 # Node ID 5e7c747c555351b5923d82f3e8997befaedddf1f # Parent
          Message 4 of 4 , Oct 17, 2012
          • 0 Attachment
            > . Will create the patch in the evening.

            # HG changeset patch
            # User ZyX <kp-pav@...>
            # Date 1350488709 -14400
            # Node ID 5e7c747c555351b5923d82f3e8997befaedddf1f
            # Parent 3346d901546830f9d20ee456e86fc60b9e393ffc
            Fixed syntax/vim.vim embedded external languages support

            diff -r 3346d9015468 -r 5e7c747c5553 runtime/doc/syntax.txt
            --- a/runtime/doc/syntax.txt Sun Oct 14 05:19:47 2012 +0200
            +++ b/runtime/doc/syntax.txt Wed Oct 17 19:44:44 2012 +0400
            @@ -3023,20 +3023,16 @@
            embedded script highlighting they wish to have. >

            g:vimsyn_embed == 0 : don't embed any scripts
            - g:vimsyn_embed =~ 'm' : embed mzscheme (but only if vim supports it)
            - g:vimsyn_embed =~ 'p' : embed perl (but only if vim supports it)
            - g:vimsyn_embed =~ 'P' : embed python (but only if vim supports it)
            - g:vimsyn_embed =~ 'r' : embed ruby (but only if vim supports it)
            - g:vimsyn_embed =~ 't' : embed tcl (but only if vim supports it)
            + g:vimsyn_embed =~ 'm' : embed mzscheme
            + g:vimsyn_embed =~ 'p' : embed perl
            + g:vimsyn_embed =~ 'P' : embed python
            + g:vimsyn_embed =~ 'r' : embed ruby
            + g:vimsyn_embed =~ 't' : embed tcl
            <
            -By default, g:vimsyn_embed is "mpPr"; ie. syntax/vim.vim will support
            -highlighting mzscheme, perl, python, and ruby by default. Vim's has("tcl")
            -test appears to hang vim when tcl is not truly available. Thus, by default,
            -tcl is not supported for embedding (but those of you who like tcl embedded in
            -their vim syntax highlighting can simply include it in the g:vimembedscript
            -option).
            +By default, g:vimsyn_embed is "mpPrt"; ie. syntax/vim.vim will support
            +highlighting all of the supported languages.
            +
            *g:vimsyn_folding*
            -
            Some folding is now supported with syntax/vim.vim: >

            g:vimsyn_folding == 0 or doesn't exist: no syntax-based folding
            diff -r 3346d9015468 -r 5e7c747c5553 runtime/syntax/vim.vim
            --- a/runtime/syntax/vim.vim Sun Oct 14 05:19:47 2012 +0200
            +++ b/runtime/syntax/vim.vim Wed Oct 17 19:44:44 2012 +0400
            @@ -549,24 +549,27 @@
            " Allows users to specify the type of embedded script highlighting
            " they want: (perl/python/ruby/tcl support)
            " g:vimsyn_embed == 0 : don't embed any scripts
            -" g:vimsyn_embed ~= 'l' : embed lua (but only if vim supports it)
            -" g:vimsyn_embed ~= 'm' : embed mzscheme (but only if vim supports it)
            -" g:vimsyn_embed ~= 'p' : embed perl (but only if vim supports it)
            -" g:vimsyn_embed ~= 'P' : embed python (but only if vim supports it)
            -" g:vimsyn_embed ~= 'r' : embed ruby (but only if vim supports it)
            -" g:vimsyn_embed ~= 't' : embed tcl (but only if vim supports it)
            +" g:vimsyn_embed ~= 'l' : embed lua
            +" g:vimsyn_embed ~= 'm' : embed mzscheme
            +" g:vimsyn_embed ~= 'p' : embed perl
            +" g:vimsyn_embed ~= 'P' : embed python
            +" g:vimsyn_embed ~= 'r' : embed ruby
            +" g:vimsyn_embed ~= 't' : embed tcl
            if !exists("g:vimsyn_embed")
            - let g:vimsyn_embed= "lmpPr"
            + let g:vimsyn_embed= "lmpPrt"
            endif

            " [-- lua --] {{{3
            -let s:luapath= fnameescape(expand("<sfile>:p:h")."/lua.vim")
            -if !filereadable(s:luapath)
            - let s:luapath= fnameescape(globpath(&rtp,"syntax/lua.vim"))
            +let s:use_lua=0
            +if stridx(g:vimsyn_embed, 'l')!=-1
            + try
            + unlet! b:current_syntax
            + syntax include @vimLuaScript syntax/lua.vim
            + let s:use_lua=1
            + catch /^Vim(syntax):E484:/
            + endtry
            endif
            -if (g:vimsyn_embed =~ 'l' && has("lua")) && filereadable(s:luapath)
            - unlet! b:current_syntax
            - exe "syn include @vimLuaScript ".s:luapath
            +if s:use_lua
            if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'l'
            syn region vimLuaRegion fold matchgroup=vimScriptDelim start=+lua\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimLuaScript
            syn region vimLuaRegion fold matchgroup=vimScriptDelim start=+lua\s*<<\s*$+ end=+\.$+ contains=@vimLuaScript
            @@ -579,16 +582,19 @@
            syn region vimEmbedError start=+lua\s*<<\s*\z(.*\)$+ end=+^\z1$+
            syn region vimEmbedError start=+lua\s*<<\s*$+ end=+\.$+
            endif
            -unlet s:luapath
            +unlet s:use_lua

            " [-- perl --] {{{3
            -let s:perlpath= fnameescape(expand("<sfile>:p:h")."/perl.vim")
            -if !filereadable(s:perlpath)
            - let s:perlpath= fnameescape(globpath(&rtp,"syntax/perl.vim"))
            +let s:use_perl=0
            +if stridx(g:vimsyn_embed, 'p')!=-1
            + try
            + unlet! b:current_syntax
            + syntax include @vimPerlScript syntax/perl.vim
            + let s:use_perl=1
            + catch /^Vim(syntax):E484:/
            + endtry
            endif
            -if (g:vimsyn_embed =~ 'p' && has("perl")) && filereadable(s:perlpath)
            - unlet! b:current_syntax
            - exe "syn include @vimPerlScript ".s:perlpath
            +if s:use_perl
            if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'p'
            syn region vimPerlRegion fold matchgroup=vimScriptDelim start=+pe\%[rl]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimPerlScript
            syn region vimPerlRegion fold matchgroup=vimScriptDelim start=+pe\%[rl]\s*<<\s*$+ end=+\.$+ contains=@vimPerlScript
            @@ -601,16 +607,19 @@
            syn region vimEmbedError start=+pe\%[rl]\s*<<\s*\z(.*\)$+ end=+^\z1$+
            syn region vimEmbedError start=+pe\%[rl]\s*<<\s*$+ end=+\.$+
            endif
            -unlet s:perlpath
            +unlet s:use_perl

            " [-- ruby --] {{{3
            -let s:rubypath= fnameescape(expand("<sfile>:p:h")."/ruby.vim")
            -if !filereadable(s:rubypath)
            - let s:rubypath= fnameescape(globpath(&rtp,"syntax/ruby.vim"))
            +let s:use_ruby=0
            +if stridx(g:vimsyn_embed, 'r')!=-1
            + try
            + unlet! b:current_syntax
            + syntax include @vimRubyScript syntax/ruby.vim
            + let s:use_ruby=1
            + catch /^Vim(syntax):E484:/
            + endtry
            endif
            -if (g:vimsyn_embed =~ 'r' && has("ruby")) && filereadable(s:rubypath)
            - unlet! b:current_syntax
            - exe "syn include @vimRubyScript ".s:rubypath
            +if s:use_ruby
            if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'r'
            syn region vimRubyRegion fold matchgroup=vimScriptDelim start=+rub[y]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimRubyScript
            else
            @@ -622,16 +631,19 @@
            syn region vimEmbedError start=+rub[y]\s*<<\s*\z(.*\)$+ end=+^\z1$+
            syn region vimEmbedError start=+rub[y]\s*<<\s*$+ end=+\.$+
            endif
            -unlet s:rubypath
            +unlet s:use_ruby

            " [-- python --] {{{3
            -let s:pythonpath= fnameescape(expand("<sfile>:p:h")."/python.vim")
            -if !filereadable(s:pythonpath)
            - let s:pythonpath= fnameescape(globpath(&rtp,"syntax/python.vim"))
            +let s:use_python=0
            +if stridx(g:vimsyn_embed, 'P')!=-1
            + try
            + unlet! b:current_syntax
            + syntax include @vimPythonScript syntax/python.vim
            + let s:use_python=1
            + catch /^Vim(syntax):E484:/
            + endtry
            endif
            -if (g:vimsyn_embed =~ 'P' && has("python")) && filereadable(s:pythonpath)
            - unlet! b:current_syntax
            - exe "syn include @vimPythonScript ".s:pythonpath
            +if s:use_python
            if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'P'
            syn region vimPythonRegion fold matchgroup=vimScriptDelim start=+py\%[thon]3\=\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimPythonScript
            syn region vimPythonRegion fold matchgroup=vimScriptDelim start=+py\%[thon]3\=\s*<<\s*$+ end=+\.$+ contains=@vimPythonScript
            @@ -644,52 +656,49 @@
            syn region vimEmbedError start=+py\%[thon]3\=\s*<<\s*\z(.*\)$+ end=+^\z1$+
            syn region vimEmbedError start=+py\%[thon]3\=\s*<<\s*$+ end=+\.$+
            endif
            -unlet s:pythonpath
            +unlet s:use_python

            " [-- tcl --] {{{3
            -if has("win32") || has("win95") || has("win64") || has("win16")
            - " apparently has("tcl") has been hanging vim on some windows systems with cygwin
            - let s:trytcl= (&shell !~ '\<\%(bash\>\|4[nN][tT]\|\<zsh\)\>\%(\.exe\)\=$')
            -else
            - let s:trytcl= 1
            +let s:use_tcl=0
            +if stridx(g:vimsyn_embed, 't')!=-1
            + try
            + unlet! b:current_syntax
            + syntax include @vimTclScript syntax/tcl.vim
            + let s:use_tcl=1
            + catch /^Vim(syntax):E484:/
            + endtry
            endif
            -if s:trytcl
            - let s:tclpath= fnameescape(expand("<sfile>:p:h")."/tcl.vim")
            - if !filereadable(s:tclpath)
            - let s:tclpath= fnameescape(globpath(&rtp,"syntax/tcl.vim"))
            +if s:use_tcl
            + if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 't'
            + syn region vimTclRegion fold matchgroup=vimScriptDelim start=+tc[l]\=\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimTclScript
            + syn region vimTclRegion fold matchgroup=vimScriptDelim start=+tc[l]\=\s*<<\s*$+ end=+\.$+ contains=@vimTclScript
            + else
            + syn region vimTclRegion matchgroup=vimScriptDelim start=+tc[l]\=\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimTclScript
            + syn region vimTclRegion matchgroup=vimScriptDelim start=+tc[l]\=\s*<<\s*$+ end=+\.$+ contains=@vimTclScript
            endif
            - if (g:vimsyn_embed =~ 't' && has("tcl")) && filereadable(s:tclpath)
            - unlet! b:current_syntax
            - exe "syn include @vimTclScript ".s:tclpath
            - if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 't'
            - syn region vimTclRegion fold matchgroup=vimScriptDelim start=+tc[l]\=\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimTclScript
            - syn region vimTclRegion fold matchgroup=vimScriptDelim start=+tc[l]\=\s*<<\s*$+ end=+\.$+ contains=@vimTclScript
            - else
            - syn region vimTclRegion matchgroup=vimScriptDelim start=+tc[l]\=\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimTclScript
            - syn region vimTclRegion matchgroup=vimScriptDelim start=+tc[l]\=\s*<<\s*$+ end=+\.$+ contains=@vimTclScript
            - endif
            - syn cluster vimFuncBodyList add=vimTclScript
            - else
            - syn region vimEmbedError start=+tc[l]\=\s*<<\s*\z(.*\)$+ end=+^\z1$+
            - syn region vimEmbedError start=+tc[l]\=\s*<<\s*$+ end=+\.$+
            - endif
            - unlet s:tclpath
            + syn cluster vimFuncBodyList add=vimTclScript
            else
            syn region vimEmbedError start=+tc[l]\=\s*<<\s*\z(.*\)$+ end=+^\z1$+
            syn region vimEmbedError start=+tc[l]\=\s*<<\s*$+ end=+\.$+
            endif
            -unlet s:trytcl
            +unlet s:use_tcl

            " [-- mzscheme --] {{{3
            -let s:mzschemepath= fnameescape(expand("<sfile>:p:h")."/scheme.vim")
            -if !filereadable(s:mzschemepath)
            - let s:mzschemepath= fnameescape(globpath(&rtp,"syntax/scheme.vim"))
            +let s:use_mzscheme=0
            +if stridx(g:vimsyn_embed, 'm')!=-1
            + try
            + unlet! b:current_syntax
            + let iskKeep= &l:isk
            + try
            + syntax include @vimMzSchemeScript syntax/scheme.vim
            + finally
            + let &l:isk= iskKeep
            + endtry
            + let s:use_mzscheme=1
            + catch /^Vim(syntax):E484:/
            + endtry
            endif
            -if (g:vimsyn_embed =~ 'm' && has("mzscheme")) && filereadable(s:mzschemepath)
            - unlet! b:current_syntax
            - let iskKeep= &isk
            - exe "syn include @vimMzSchemeScript ".s:mzschemepath
            - let &isk= iskKeep
            +if s:use_mzscheme
            if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'm'
            syn region vimMzSchemeRegion fold matchgroup=vimScriptDelim start=+mz\%[scheme]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimMzSchemeScript
            syn region vimMzSchemeRegion fold matchgroup=vimScriptDelim start=+mz\%[scheme]\s*<<\s*$+ end=+\.$+ contains=@vimMzSchemeScript
            @@ -702,7 +711,7 @@
            syn region vimEmbedError start=+mz\%[scheme]\s*<<\s*\z(.*\)$+ end=+^\z1$+
            syn region vimEmbedError start=+mz\%[scheme]\s*<<\s*$+ end=+\.$+
            endif
            -unlet s:mzschemepath
            +unlet s:use_mzscheme

            " Synchronize (speed) {{{2
            "============

            --
            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
          Your message has been successfully submitted and would be delivered to recipients shortly.