syntax highlighting of embedded scripts

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

syntax highlighting of embedded scripts

Benjamin Fritz

Consider the following:

perl << EOF
some code that contains Vim keywords
EOF

If has("perl") is true, no problem! A syntax region is defined that
does not include any Vim groups, and the perl syntax is included
within the region.

If has("perl") is false, however, the code within perl << EOF to EOF
will be (incorrectly?) highlighted as if it were Vim code.

If has("perl") is false, Vim still tries to run the code as Perl code,
but will raise an error.

Therefore, I think that a containing region should be defined even if
has("perl") is false. However, if has("perl") is false, either the
entire region or at least the "perl << EOF" and the "EOF" should be
highlighted as errors.

The same applies to the other embeddable languages as well.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: syntax highlighting of embedded scripts

iler.ml
On Tue, Jul 8, 2008 at 8:14 PM, Ben Fritz <[hidden email]> wrote:

Consider the following:

perl << EOF
some code that contains Vim keywords
EOF

If has("perl") is true, no problem! A syntax region is defined that
does not include any Vim groups, and the perl syntax is included
within the region.

If has("perl") is false, however, the code within perl << EOF to EOF
will be (incorrectly?) highlighted as if it were Vim code.

If has("perl") is false, Vim still tries to run the code as Perl code,
but will raise an error.

Therefore, I think that a containing region should be defined even if
has("perl") is false. However, if has("perl") is false, either the
entire region or at least the "perl << EOF" and the "EOF" should be
highlighted as errors.

I agree

Yakov

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: syntax highlighting of embedded scripts

Benjamin Fritz



On Jul 9, 2:42 am, "Yakov Lerner" <[hidden email]> wrote:

> On Tue, Jul 8, 2008 at 8:14 PM, Ben Fritz <[hidden email]> wrote:
>
> > Consider the following:
>
> > perl << EOF
> > some code that contains Vim keywords
> > EOF
>
> > If has("perl") is true, no problem! A syntax region is defined that
> > does not include any Vim groups, and the perl syntax is included
> > within the region.
>
> > If has("perl") is false, however, the code within perl << EOF to EOF
> > will be (incorrectly?) highlighted as if it were Vim code.
>
> > If has("perl") is false, Vim still tries to run the code as Perl code,
> > but will raise an error.
>
> Therefore, I think that a containing region should be defined even if
>
> > has("perl") is false. However, if has("perl") is false, either the
> > entire region or at least the "perl << EOF" and the "EOF" should be
> > highlighted as errors.
>
> I agree
>
> Yakov

I made a simple patch against the version of vim.vim that I have to
add this functionality. Unfortunately, I believe that my version
(7.1-77) is outdated.

It will, regardless of the value of vimsym_embed, highlight the begin
and end markers of the aforementioned constructs using the vimWarn
group (but not if g:vimsyn_noerror exists). It will also prevent all
highlighting of the script itself if the language is not supported (is
this also desired if the user chooses not to highlight that embedded
script?)

This is my first patch ever, so be nice.

**********************************************************************

*** vim.vim Tue Jul 08 10:58:28 2008
--- U:\vimfiles\syntax\vim.vim Wed Jul 09 14:58:31 2008
***************
*** 537,576 ****
  endif

  " [-- perl --] {{{3
! if (g:vimsyn_embed =~ 'p' && has("perl")) &&
filereadable(expand("<sfile>:p:h")."/perl.vim")
!  unlet! b:current_syntax
!  syn include @vimPerlScript <sfile>:p:h/perl.vim
   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
   else
!   syn region vimPerlRegion matchgroup=vimScriptDelim start=+pe\%[rl]
\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimPerlScript
!   syn region vimPerlRegion matchgroup=vimScriptDelim start=+pe\%[rl]
\s*<<\s*$+ end=+\.$+ contains=@vimPerlScript
   endif
  endif

  " [-- ruby --] {{{3
! if (g:vimsyn_embed =~ 'r' && has("ruby")) &&
filereadable(expand("<sfile>:p:h")."/ruby.vim")
!  unlet! b:current_syntax
!  syn include @vimRubyScript <sfile>:p:h/ruby.vim
   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
!   syn region vimRubyRegion fold matchgroup=vimScriptDelim start=
+rub[y]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimRubyScript
   endif
!  syn region vimRubyRegion matchgroup=vimScriptDelim start=+rub[y]
\s*<<\s*$+ end=+\.$+ contains=@vimRubyScript
  endif

  " [-- python --] {{{3
! if (g:vimsyn_embed =~ 'P' && has("python")) &&
filereadable(expand("<sfile>:p:h")."/python.vim")
!  unlet! b:current_syntax
!  syn include @vimPythonScript <sfile>:p:h/python.vim
   if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'P'
!   syn region vimPythonRegion fold matchgroup=vimScriptDelim start=+py
\%[thon]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimPythonScript
!   syn region vimPythonRegion fold matchgroup=vimScriptDelim start=+py
\%[thon]\s*<<\s*$+ end=+\.$+ contains=@vimPythonScript
   else
!   syn region vimPythonRegion matchgroup=vimScriptDelim start=+py\%
[thon]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimPythonScript
!   syn region vimPythonRegion matchgroup=vimScriptDelim start=+py\%
[thon]\s*<<\s*$+ end=+\.$+ contains=@vimPythonScript
   endif
  endif

--- 537,608 ----
  endif

  " [-- perl --] {{{3
! if has("perl")
!  if g:vimsyn_embed =~ 'p' && filereadable(expand("<sfile>:p:h")."/
perl.vim")
!   unlet! b:current_syntax
!   syn include @vimPerlScript <sfile>:p:h/perl.vim
!   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
!   else
!    syn region vimPerlRegion matchgroup=vimScriptDelim start=+pe\%[rl]
\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimPerlScript
!    syn region vimPerlRegion matchgroup=vimScriptDelim start=+pe\%[rl]
\s*<<\s*$+ end=+\.$+ contains=@vimPerlScript
!   endif
!  endif
! else
!  " perl not supported
   if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'p'
!   syn region vimPerlRegion fold matchgroup=vimNotSupported start=+pe\
%[rl]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=NONE
!   syn region vimPerlRegion fold matchgroup=vimNotSupported start=+pe\
%[rl]\s*<<\s*$+ end=+\.$+ contains=NONE
   else
!   syn region vimPerlRegion matchgroup=vimNotSupported start=+pe\%[rl]
\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=NONE
!   syn region vimPerlRegion matchgroup=vimNotSupported start=+pe\%[rl]
\s*<<\s*$+ end=+\.$+ contains=NONE
   endif
  endif

  " [-- ruby --] {{{3
! if has("ruby")
!  if g:vimsyn_embed =~ 'r' && filereadable(expand("<sfile>:p:h")."/
ruby.vim")
!   unlet! b:current_syntax
!   syn include @vimRubyScript <sfile>:p:h/ruby.vim
!   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
!    syn region vimRubyRegion fold matchgroup=vimScriptDelim start=
+rub[y]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimRubyScript
!   endif
!   syn region vimRubyRegion matchgroup=vimScriptDelim start=+rub[y]
\s*<<\s*$+ end=+\.$+ contains=@vimRubyScript
!  endif
! else
!  " ruby not supported
   if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'r'
!   syn region vimRubyRegion fold matchgroup=vimNotSupported start=
+rub[y]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=NONE
   else
!   syn region vimRubyRegion fold matchgroup=vimNotSupported start=
+rub[y]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=NONE
   endif
!  syn region vimRubyRegion matchgroup=vimNotSupported start=+rub[y]
\s*<<\s*$+ end=+\.$+ contains=NONE
  endif

  " [-- python --] {{{3
! if has("python")
!  if g:vimsyn_embed =~ 'P' && filereadable(expand("<sfile>:p:h")."/
python.vim")
!   unlet! b:current_syntax
!   syn include @vimPythonScript <sfile>:p:h/python.vim
!   if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'P'
!    syn region vimPythonRegion fold matchgroup=vimScriptDelim start=
+py\%[thon]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimPythonScript
!    syn region vimPythonRegion fold matchgroup=vimScriptDelim start=
+py\%[thon]\s*<<\s*$+ end=+\.$+ contains=@vimPythonScript
!   else
!    syn region vimPythonRegion matchgroup=vimScriptDelim start=+py\%
[thon]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimPythonScript
!    syn region vimPythonRegion matchgroup=vimScriptDelim start=+py\%
[thon]\s*<<\s*$+ end=+\.$+ contains=@vimPythonScript
!   endif
!  endif
! else
!  " Python not supported
   if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'P'
!   syn region vimPythonRegion fold matchgroup=vimNotSupported start=
+py\%[thon]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=NONE
!   syn region vimPythonRegion fold matchgroup=vimNotSupported start=
+py\%[thon]\s*<<\s*$+ end=+\.$+ contains=NONE
   else
!   syn region vimPythonRegion matchgroup=vimNotSupported start=+py\%
[thon]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=NONE
!   syn region vimPythonRegion matchgroup=vimNotSupported start=+py\%
[thon]\s*<<\s*$+ end=+\.$+ contains=NONE
   endif
  endif

***************
*** 582,613 ****
   let trytcl= 1
  endif
  if trytcl
!  if (g:vimsyn_embed =~ 't' && has("tcl")) &&
filereadable(expand("<sfile>:p:h")."/tcl.vim")
!   unlet! b:current_syntax
!   syn include @vimTclScript <sfile>:p:h/tcl.vim
    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
   endif
  endif
  unlet trytcl

  " [-- mzscheme --] {{{3
! if (g:vimsyn_embed =~ 'm' && has("mzscheme")) &&
filereadable(expand("<sfile>:p:h")."/scheme.vim")
!  unlet! b:current_syntax
!  let iskKeep= &isk
!  syn include @vimMzSchemeScript <sfile>:p:h/scheme.vim
!  let &isk= iskKeep
!  if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 't'
!   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
   else
!   syn region vimMzSchemeRegion matchgroup=vimScriptDelim start=+mz\%
[scheme]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimMzSchemeScript
!   syn region vimMzSchemeRegion matchgroup=vimScriptDelim start=+mz\%
[scheme]\s*<<\s*$+ end=+\.$+ contains=@vimMzSchemeScript
   endif
  endif

--- 614,666 ----
   let trytcl= 1
  endif
  if trytcl
!  if has("tcl")
!   if g:vimsyn_embed =~ 't' && filereadable(expand("<sfile>:p:h")."/
tcl.vim")
!    unlet! b:current_syntax
!    syn include @vimTclScript <sfile>:p:h/tcl.vim
!    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
!   endif
!  else
!   " tcl not supported
    if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 't'
!    syn region vimTclRegion fold matchgroup=vimNotSupported start=
+tc[l]\=\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=NONE
!    syn region vimTclRegion fold matchgroup=vimNotSupported start=
+tc[l]\=\s*<<\s*$+ end=+\.$+ contains=NONE
    else
!    syn region vimTclRegion matchgroup=vimNotSupported start=+tc[l]\=
\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=NONE
!    syn region vimTclRegion matchgroup=vimNotSupported start=+tc[l]\=
\s*<<\s*$+ end=+\.$+ contains=NONE
    endif
   endif
  endif
  unlet trytcl

  " [-- mzscheme --] {{{3
! if has("mzscheme")
!  if g:vimsyn_embed =~ 'm' && filereadable(expand("<sfile>:p:h")."/
scheme.vim")
!   unlet! b:current_syntax
!   let iskKeep= &isk
!   syn include @vimMzSchemeScript <sfile>:p:h/scheme.vim
!   let &isk= iskKeep
!   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
!   else
!    syn region vimMzSchemeRegion matchgroup=vimScriptDelim start=+mz\%
[scheme]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimMzSchemeScript
!    syn region vimMzSchemeRegion matchgroup=vimScriptDelim start=+mz\%
[scheme]\s*<<\s*$+ end=+\.$+ contains=@vimMzSchemeScript
!   endif
!  endif
! else
!  if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'm'
!   syn region vimMzSchemeRegion fold matchgroup=vimNotSupported start=
+mz\%[scheme]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=NONE
!   syn region vimMzSchemeRegion fold matchgroup=vimNotSupported start=
+mz\%[scheme]\s*<<\s*$+ end=+\.$+ contains=NONE
   else
!   syn region vimMzSchemeRegion matchgroup=vimNotSupported start=+mz\%
[scheme]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=NONE
!   syn region vimMzSchemeRegion matchgroup=vimNotSupported start=+mz\%
[scheme]\s*<<\s*$+ end=+\.$+ contains=NONE
   endif
  endif

***************
*** 646,651 ****
--- 699,705 ----
   hi def link vimSubstFlagErr vimError
   hi def link vimSynCaseError vimError
   hi def link vimBufnrWarn vimWarn
+  hi def link vimNotSupported vimWarn
  endif

  hi def link vimAddress vimMark

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: syntax highlighting of embedded scripts

Tony Mechelynck

On 09/07/08 22:13, Ben Fritz wrote:
[...]
> I made a simple patch against the version of vim.vim that I have to
> add this functionality. Unfortunately, I believe that my version
> (7.1-77) is outdated.
[...]

The latest published syntax/vim.vim on the Vim site is version 7.2-78
dated July 01, 2008.

Best regards,
Tony.
--
This is a test of the emergency cunnilingus system. If this had been an
actual emergency, you would have known it!

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: syntax highlighting of embedded scripts

Benjamin Fritz



On Jul 10, 3:07 am, Tony Mechelynck <[hidden email]>
wrote:

> On 09/07/08 22:13, Ben Fritz wrote:
> [...]> I made a simple patch against the version of vim.vim that I have to
> > add this functionality. Unfortunately, I believe that my version
> > (7.1-77) is outdated.
>
> [...]
>
> The latest published syntax/vim.vim on the Vim site is version 7.2-78
> dated July 01, 2008.
>
> Best regards,
> Tony.
> --
> This is a test of the emergency cunnilingus system. If this had been an
> actual emergency, you would have known it!

Bah, it looks like this issue is fixed in 7.2-79. Maybe in 7.2-78 as
well...not sure.

Guess I should have checked first. Sorry, all.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---