简体   繁体   English

在Emacs中突出显示Java中使用的'bool'

[英]Highlighting 'bool' used in Java, within Emacs

I switch back and forth between Java and C++ in my current job, and as a result I tend to use 'bool' in Java instead of 'boolean'. 我在当前的工作中在Java和C ++之间来回切换,因此我倾向于在Java中使用'bool'而不是'boolean'。 I program in Emacs, which highlights 'bool' in a declaration the same as any other type, so I don't tend to catch the error until compile time. 我在Emacs中编程,它在声明中突出显示'bool'与任何其他类型相同,所以我不倾向于在编译时捕获错误。

Is there any way to get java-mode to highlight 'bool' for me so that I can catch the error while I'm writing the code? 有没有办法让java模式为我突出'bool',以便我可以在编写代码时捕获错误?

Add this to your .emacs: 将其添加到.emacs:

(font-lock-add-keywords 'java-mode
        '(("\\<bool\\>" . font-lock-warning-face)))

The easiest is perhaps 最简单的也许是

M-x highlight-regexp RET
\_<bool\_> RET
font-lock-warning-face RET

You can certainly add this to the java-mode-hook too. 你当然可以将它添加到java-mode-hook Downside is, of course, this method provides no syntactic checking and will highlight also in strings and comments... 当然,缺点是这种方法不提供语法检查,并且还会在字符串和注释中突出显示......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM