On Thu, 26 Oct 2006, A. S. Budden wrote:
> On 26/10/06, Hugh Sasse <[EMAIL PROTECTED]> wrote:
> [snip]
> > So, we run into a problem: how does one syntax highlight mixed
> > language code?
> [snip]
>
> I don't know whether this is of any use, but I have often found
> situations where I need to embed code from one language in the comments
> of another. For example, I have Matlab code that scans through its own
> source for some perl code, writes it to disk and then uses it to process
> text files (as Perl is MUCH better at text file handling). This saves
Interesting idea.
> having multiple scripts for a single (relatively simple task). In
> .vim/after/syntax/matlab.vim, I have (three lines):
>
> unlet! b:current_syntax
> syn include @matlabPerlScript $VIMRUNTIME/syntax/perl.vim
> syn region matlabPerlRegion matchgroup=matlabScriptDelim start=+^%
> PERL\d*: +hs=s+8 end=+$+ [EMAIL PROTECTED]
OK, this seems to make sense to me from what I have read so far.
>
> So any lines starting "% PERL: " (with an optional number after PERL)
> are highlighted as perl code. The number allows me to have multiple
matching to the end of the line. yes..
> perl scripts embedded in a single Matlab script. I have done similar
> things for C and others.
Well, in my .vimrc I now have:
" To MetaProgram C using Ruby
function RubyMetaC()
:unlet! b:current_syntax
:syntax include @CSTUFF syntax/c.vim
:syntax region rubyC1 matchgroup=String start=+%Q{+ end=+}+ keepend [EMAIL
PROTECTED]
:syntax region rubyC2 matchgroup=String start=+%Q(+ end=+)+ keepend [EMAIL
PROTECTED]
:syntax region rubyC3 matchgroup=String start=+%Q<+ end=+>+ keepend [EMAIL
PROTECTED]
:syntax on
endfunction
The three :syntax region lines are needed to distinguish %Q<>, %Q() and
%Q{} all of which are quoted strings in ruby. I could not figure out
how to use \z to let me find the matching {angle,round,curly} bracket
for the one I'd opened. I suspect that is possible....
Without the syntax on line, the contents of the quoted string show up
as white, unhighlighted, when I do
:call RubyMetaC()
Adding the syntax on line just gave me Ruby string quoting, and no
C highlighting at all. I was back at square 1.
Adding the :unlet! line made no difference at that stage.
I am now somewhat confused, but feel that I am nearer than I was.
I saw in the tip#856 (earlier in the thread) the use of :hi-link,
but can't figure out what to link it to so that it picks up all
C code as C.
>
> Hope that is of some interest,
>
> Al
>
Thank you
Hugh