6

I would like to highlight all the HereDocs in a particular perl file as perl code. For example, I'd like to apply the normal perl highlighting to the subroutine in this HereDoc:

my $code = <<'CODE';
   sub test {
      say "this is a test";
   };
CODE

I thought I could do this with something like:

syn region perlHereDocPL    start=+<<\s*'\z([^\\']*\%(\\.[^\\']*\)*\)'+ matchgroup=perlSnip end=+^\z1$+ contains=@perlTop

But apparently this doesn't work like I thought it did. Thanks!

Mark Grimes
  • 201
  • 1
  • 6

1 Answers1

4

It looks like I found a solution. I was able to adapt config that formatted heredoc as SQL:

" .vim/after/syntax/perl/heredoc-perl.vim
runtime! syntax/perl.vim
unlet b:current_syntax
syntax include @Perl syntax/perl.vim

syntax region sqlSnip matchgroup=Snip start=+<<['"]RAW['"].*;\s*$+ end=+^\s*RAW$+ contains=@Perl
syntax region sqlSnip matchgroup=Snip start=+<<['"]TIDIED['"].*;\s*$+ end=+^\s*TIDIED$+ contains=@Perl

This only applies to heredocs that are identified by RAW or TIDIED, but that is perfect for my purposes.

Mark Grimes
  • 201
  • 1
  • 6
  • 1
    I think you can lose the first two lines here (runtime! syntax/sql.vim, unlet b:current_syntax)? As you're not doing anything with the SQL syntax... – Martin Tournoij Mar 14 '16 at 23:25
  • Thanks. That should have been runtime! syntax/perl.vim instead of runtime! syntax/sql.vim. That probably isn't necessary either since the rest of the file is using the perl syntax. – Mark Grimes Mar 15 '16 at 12:51