Emacs perl syntax highlighting broken, is there a fix?

I am a Perl programmer and a new emacs user. I'm on Windows, using cperl-mode to edit perl. Emacs version is 24.2.1. Here is a screenshot with sample code:


(source: breqwas.net )

  1. Obvious mistake: it highlights arrays, hashes, and literal values ​​without quotes in (a => "b") stylelists inside comments
  2. Another mistake: it selects the first word in the regular expression as an array due to the non-standard quote character
  3. Not a mistake, but it looks weird: it highlights arrays and hashes at any time when they are used (even in comments, yes), but scalars are highlighted only when declared
  4. Not a mistake, but it looks strange: the same story with functions: it is highlighted when declaring, and not when calling
  5. Not a mistake, but it looks strange: why do "print", "say" and "system" have different colors?

I could go on, but I hope this explains the word "broken" pretty well.

Then I studied the magic key combination Cu Cx =, which shows, among other things, the text properties for the text under the cursor, hoping to create a better own coloring scheme. At that moment, it began to make even less sense.

"print" has a cperl-nonoverridable-face. "die" has a font-lock-keyword-face. Meanwhile, both are functions and can be (and often) redefined. "system" has font-lock-type-face. Why? Function declarations have font-lock-function-name-face - this is normal, but the same as use arguments. Why? Function calls and scalars have no face properties at all and cannot be allocated. Why? And so on. And again, I could go on.

Is there any way to fix all this? Is there any configuration in which I can reassign lexical units to some other font faces or in some other way make the syntax highlighting less crazy?

To avoid the “perl is unparsible” conversation, here is a screenshot of the editor I'm switching from with the same code: http://breqwas.net/dropbox/perlsyn_pn.png . It looks much smarter.


Upd: So far (3 weeks after I asked this question here), I have not found a cure. All Perl programmers who use emacs, I know, simply ignore these problems. Emacs doesn't seem to have better perl highlights. Reading documents in cperl mode gives some explanations (choosing faces for different elements now seems less crazy), but gives no answers. I wrote an email to the cperl-mode maintainer with these questions and some other digging, but didn't get an answer.

Yes, you understood correctly: it seems that the emacs community has not been able to make good perl syntax highlighting in the 25 years that perl is. It is a sad story.

+4
source share
2 answers

You might want to try perl-mode instead of cperl-mode . If you find the missing functions in it, we can transfer them from cperl-mode without any problems. perl-mode backlighting is less tasteless than cperl-mode , but it fixes some of the problems you specify.

As for “highlighted when declared, not when called,” this is because Emacs usually stands out this way. I find that there is a null advantage for highlighting variables and using functions. I saved the selection of variables in perl-mode mainly because it was there before, and I did not want to deal with dissatisfied users. In addition, in the case of Perl, it is probably easier to highlight variable declarations and use identically, like perl-mode , while cperl-mode has to do extra work to distinguish between these two cases.

+3
source

Another syntax that sets snafu to watch for Emacs cperl-mode refers to the POD comments used to comment on blocks of code. Here is a screenshot for demonstration:

cperl-mode syntax highlighting bug demo

It is VERY easy to skip commented code that uses POD directives without filling in blank lines, as in my example, “not recommended” above. It just doesn't catch the eye like a comment when viewed in Emacs, especially if the commented block is large and spans multiple screens, so the "= cut" lines are not even displayed.

It is worth noting that vim Perl mode correctly allocates PODs without the need to fill in empty lines in the POD specification, although I would caution vim users not to rely on this function and use an empty line, = begin comment ... = end comment ', as shown above and as recommended .

It would be nice if Perl had a simple multi-line comment syntax a la '/ * ... * /' rather than an abusive POD mechanism. Perhaps we will get it in Perl 6 someday?

Another way to make multi-line comments in Emacs (for any language) is via the built-in string rectangle: Cx rt, then enter "#". To uncomment a block, do it manually or write a simple macro.

0
source

Source: https://habr.com/ru/post/1442969/


All Articles