I am trying to add a comment feature to Pod documentation for Perl scripts, and I would like to highligh Pod comments with a special face. A simple prototype Perl script could be:
#! /usr/bin/env perl use strict; use warnings; print "Hello\n"; # a Perl comment /* hello */ __END__ =head1 SYNOPSIS my_program <arg1> [OPTIONS] /* this is a Pod comment */
As we see, a Pod comment is surronded by
/* */ as in C programming language. However, only the part below the line
__END__ is Pod documentation. The part above that line is regular Perl code. Now, if I try to add syntax highlighting to the Pod comment using for example (called from
(font-lock-add-keywords nil '(("\\(/\\*.*?\\*/\\)" 1 'font-lock-warning-face t)))
I get the following using
cperl-mode as major mode:
So Pod comments are highlighted also in a regular Perl comment (a Perl comment starts with a
# character), which is not desired (Pod comments should only be highlighted in Pod sections, not in regular Perl code).
For simplicity, for this question, we can assume that the Pod documentation is confined to the end of the document, starting with the lines after the
__END__ tag. Is it possible to check the position of the current comment and relate that to the position of the
__END__ line, and from that information determine if we are inside a Pod block or not (and then add syntax highlighting only if we are inside a Pod block) when running the font lock code?