2012-10-30

I'm a perl programmer and a new emacs user. I'm under Windows, using cperl-mode for editing perl. Emacs version is 24.2.1. Here's a screenshot with some sample code:



Obvious bug: it highlights arrays, hashes and non-quoted literal values in ( a => "b" ) style lists inside comments

One more bug: it highligts the first word in a regular expression as an array because of non-default quote symbol

Not a bug, but looks weird: it highlights arrays and hashes any time when they are used (even in comments, huh), but scalars are highlighted only when declared

Not a bug, but looks weird: same story with functions: highlighted when declared, not when called

Not a bug, but looks weird: why do "print", "say" and "system" have different colors?

I could keep going, but I hope that explains the word "broken" pretty well.

Then I learned the magic C-u C-x = key combination, which shows, among other stuff, the text properties for the text under the cursor, hoping to make a better coloring scheme of my own. At this point it started making even less sense.

"print" has cperl-nonoverridable-face. "die" has font-lock-keyword-face. Meanwhile, both are functions and can be (and often are) overrided. "system" has font-lock-type-face. Why? Function declarations have font-lock-function-name-face - that's OK, but so do the arguments of "use". Why? Function calls and scalars don't have face property at all and can't be highlighted. Why? Etc, Etc. Again, I could keep going.

Is there a way to fix all that? Is there some config where I can remap lexical units to some other font-faces, or some other way to make the syntax highlight less crazy?

To avoid the "perl is unparsible" talk, here's a screenshot of the editor I'm migrating from, with the very same code: http://breqwas.net/dropbox/perlsyn_pn.png. Looks much more reasonable.

Upd: By now (3 weeks after asking this question here) I did not find a cure. All perl programmers who use emacs I know just ignore these problems. No better perl highlighters for emacs seem to exist. Reading cperl-mode docs provides some explanations (the choice of faces for various elements seems less crazy now), but does not provide any answers. I wrote an email to cperl-mode maintainer with these questions and some more digging I did, but got no reply.

Yep, you got that right: seems like emacs community was not able to make a good perl syntax highligting in 25 years that perl is around. That's a sad story.

Show more