On Tue, 6 Jul 2010, Charles Campbell wrote:

> Benjamin R. Haskell wrote:
> > On Mon, 5 Jul 2010, Peng  Yu wrote:
> > 
> >    
> > > No. You misunderstood me. I think that the vim can recognized the 
> > > file type by the suffix of the filename. There is no need to ":set 
> > > filetype=sql" explicitly.
> > > 
> > > But the default syntax highlight facility in vim doesn't reliably 
> > > syntax highlight SQL code embedded in a bash script. In the 
> > > following example, the SQL code after "*.txt" is not recognized 
> > > correctly.
> > >      
> > The syntax highlighting for PHP handles highlighting other languages 
> > within heredocs.  Perhaps you can find a solution somewhere in 
> > there.
> > 
> > I believe it 'detects' the language via the heredoc label, though, 
> > so you might need to use <<SQL
> > SQL
> > instead of <<EOF
> > EOF
> > 
> > See also:
> > 
> > :help :syn-include
> >    
> 
> As I see it, the script is being highlighted correctly from sh's 
> viewpoint, as a heredoc is essentially just a long string.
> 
> What you appear to want is for the sh syntax script to recognize 
> sqlite3 in the command and highlight the following heredoc using that 
> other syntax.  As Ben H pointed out, it is possible to use the 
> syn-include approach to get what you want.  I suggest writing a bit of 
> extra syntax handling for this purpose and put it in your 
> .vim/after/syntax/sh.vim file.  Such a region would be recognized at 
> the outset with sqlite3, etc.  However, I don't think sh.vim is the 
> place to try to recognize every possible language that heredoc strings 
> might be using.

Yep.  That's what I was suggesting.  And I agree that it shouldn't be in 
the general 'syntax/sh.vim'.  The following worksforme:

==> ~/.vim/after/syntax/sh.vim <==
unlet b:current_syntax
syntax include @sql syntax/sql.vim
syn region shHereDoc matchgroup=shRedir start=/<<\s*\\\=\z(\S*\)/ 
end=/^\z1\s*$/ contai...@shdblquotelist,@sql
==================================

I got the pattern for the last line by looking at the patterns already 
in the 'sh' filetype (With a 'sh' file open, run :syn).  If it doesn't 
work right for how you style your heredocs, you might want to try a 
different one.  (Not sure what the subtleties are that the many similar 
matches are trying to capture, other than the contains-quoted-items 
dichotomy.)  You should also add the 'fold' flag if you use 
g:sh_fold_enabled.

-- 
Best,
Ben

-- 
You received this message from the "vim_use" 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

Reply via email to