roadrider has asked for the wisdom of the Perl Monks concerning the following question:

Has anyone else seen this with emacs cperl-mode (v 5.23)?

my $foo; #gets syntax highlighting $foo = 1; #not highlighted

In perl-mode, all references to the variable are highlighted but apparently not so in cperl-mode where only the original reference is.

I have (global-font-lock-mode 1) in my .emacs.

Is this the intended behavior? If not, is there a way to fix it?

Replies are listed 'Best First'.
Re: cperl-mode inconsistent syntax highlighting
by LanX (Saint) on Mar 06, 2012 at 21:28 UTC
    No such problem, but I use cperl-mode 6.2

    Text content at position 37: There are text properties here: face font-lock-variable-name-face fontified t
    And the first thing that Ilya would ask you (also concerning the other problem you posted on gnu.emacs.help) is why you didn't try updating your cperl-mode version.

    Cheers Rolf

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: cperl-mode inconsistent syntax highlighting
by choroba (Cardinal) on Mar 07, 2012 at 10:19 UTC
    In more recent versions of cperl, you can (setq cperl-highlight-variables-indiscriminately t).
      ++ correct answer! :)

      I'm now sitting at a new system and experiencing the same effect with emacs 23.2.1 and cperl 6.2.

      But this line has to be executed at startup in init.el (or .emacsrc or whatever) ...

      Note that that variable is only read at initialization time for the variable `cperl-font-lock-keywords-2', so changing it after you +'ve entered CPerl mode the first time will have no effect.

      This setting can also be done per GUI with M-x customize-group RET cperl, so no need to edit init.el manually.

      Cheers Rolf

        You might also want to apply my patch to cperl that highlights variables with explicit package names, too (it is a simplification, but works for correct code).