Emacs中perl的语法高亮被打破了,有没有修复? [英] Syntax highlight for perl in Emacs is broken, is there a fix?

查看:92
本文介绍了Emacs中perl的语法高亮被打破了,有没有修复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个Perl程序员和一个新的emacs用户。我在Windows下,使用cperl-mode进行编辑perl。 Emacs版本是24.2.1。以下是一些示例代码的截图:



http ://breqwas.net/dropbox/perlsyn_emacs.png

  1. 明显的错误:它突出显示数组,散列和非引号文字值( a =>b)样式列表里面的评论

  2. 还有一个bug:由于非默认值,它将正则表达式中的第一个单词作为数组高估引用符号

  3. 不是一个错误,但看起来很奇怪:它突出显示数组和任何时候使用它们的哈希(即使在注释中),但标量仅在声明时被突出显示

  4. 不是一个错误,但看起来很奇怪:与功能相同的故事:声明时突出显示,而不是调用时

  5. 不是一个错误,但看起来很奇怪:为什么打印,说和系统有不同的颜色?

我可以继续下去,但我希望能够很好地解释破



然后我学到了魔法铜C-x =键组合,其中显示了光标下的文本的文本属性,希望能够使自己更好的着色方案。在这一点上,它开始变得没有意义。



print具有 cperl-nonoverstrable-face 。 死有 font-lock-keyword-face 。同时,两者都是功能,并且可以(并且经常被)超越。 系统具有 font-lock-type-face 。为什么?函数声明具有 font-lock-function-name-face - 没关系,use的参数也是如此。为什么?函数调用和标量根本没有face属性,不能突出显示。为什么?等等再次,我可以继续前进。



有没有办法解决所有这些?有没有一些配置,我可以将词汇单位重新映射到某些其他字体,或者其他一些方法使语法突出显示更不疯狂?



为了避免perl is不可否认的谈话,这里是我正在迁移的编辑器的截图,使用相同的代码: http: //breqwas.net/dropbox/perlsyn_pn.png 。看起来更合理






更新:现在(在这里提出这个问题后3周),我没有找到治愈。所有使用emacs的perl程序员,我知道只是忽略这些问题。没有更好的perl荧光笔emacs似乎存在。阅读cperl-mode docs提供了一些解释(现在各种元素的面部选择似乎不那么疯狂),但不提供任何答案。我写了一封电子邮件给cperl-mode维护者,这些问题和一些挖掘我做了,但没有回复。



是的,你的权利:看起来像emacs社区在25年的时间里,Perl无法使一个很好的perl语法高效。这是一个难过的故事。

解决方案

您可能想尝试 perl-mode 而不是 cperl-mode 。如果您发现缺少的功能,我们可以将它们从 cperl-mode 中移植,而不会有太多麻烦。 perl-mode 的突出显示不如 cperl-mode ,但它确实解决了一些问题指出。



至于声明时突出显示,而不是被调用,这是因为Emacs通常以这种方式突出显示。我发现突出变量和功能使用没有好处。我在 perl-mode 中强调变量使用的重点,主要是因为它在之前,我不想处理不满的用户。此外,在Perl的情况下,与 perl-mode 相比,可以更容易地突出显示变量声明和使用方法,而 cperl-mode 必须做额外的工作来区分这两种情况。


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:

http://breqwas.net/dropbox/perlsyn_emacs.png

  1. Obvious bug: it highlights arrays, hashes and non-quoted literal values in ( a => "b" ) style lists inside comments
  2. One more bug: it highligts the first word in a regular expression as an array because of non-default quote symbol
  3. 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
  4. Not a bug, but looks weird: same story with functions: highlighted when declared, not when called
  5. 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.

解决方案

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.

这篇关于Emacs中perl的语法高亮被打破了,有没有修复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆