Syntax highlight for perl in Emacs is broken, is there a fix?

独自空忆成欢 提交于 2019-12-04 12:49:29

You might want to try perl-mode instead of cperl-mode. If you find missing features in it we might be able to port them from cperl-mode without too much trouble. perl-mode's highlighting is less gaudy than cperl-mode's but it does fix some of the problems you point out.

As for "highlighted when declared, not when called" this is because Emacs usually highlights in this way. I find there is zero benefit to highlighting variable and function uses. I kept the highlighting of variable uses in perl-mode mostly because it was there before and I didn't want to deal with disgruntled users. Also, in the case of Perl, it's probably easier to highlight variable declarations and uses identically as does perl-mode whereas cperl-mode has to do extra work to distinguish those two cases.

Trutane

Another syntax highlighting snafu to watch out for with Emacs cperl-mode relates to POD comments used to comment out blocks of code. Here's a screenshot to demo:

It's VERY easy to miss commented out code that uses POD directives without blank line padding as in my 'not recommended' example above. It just does not hit your eye as a comment when viewing it in Emacs, especially if the commented block is large and spans multiple screen pages so that the '=cut' lines aren't even in view.

It's worth noting that vim's Perl mode correctly highlights the POD without requiring blank line padding per the POD spec, though I would caution vim users to avoid relying on that feature and use blank line padding and '=begin comment ...=end comment' directives as shown above and as recommended.

It would be nice if Perl had a simpler multi-line comment syntax a la '/* ... */' rather than the POD mechanism that is subject to abuse. Perhaps we'll get this in Perl 6 some day?

Another way do multi-line comments in Emacs (for any language) is via the 'string-rectangle' built-in: C-x r t then type '# '. To uncomment a block, either do it manually or write a simple macro.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!