emacs 中的语法高亮显示。用不同的颜色标记不同的数据类型
在Emacs中,是否可以用不同的颜色来标记不同数据类型的所有变量?例如,如果我的程序在 C/C++ 中有以下变量,
int i,j;
float g,h;
char a,b;
则整个源代码 i 和 j 将标记为红色,g 和 h 标记为绿色,a 和 b 标记为蓝色。
我不确定这将来会有多大用处,但我觉得它会对我阅读代码有所帮助, 并成为匈牙利表示法的一个很好的替代品(不是我使用这个表示法:D)。
In Emacs, is it possible to mark all variables of different data types with different colors? e.g. if I have the following variables in C/C++ my program
int i,j;
float g,h;
char a,b;
Then throughout the source code i and j would be marked as red, g and h as green, a and b as blue.
I am not sure how useful this will be in future, but I feel it would help me while reading code,
and be a good alternative to the Hungarian notation(not that I use this notation :D).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不会。Emacs 不知道特定表达式的类型。这样做相当于在
ELisp
中编写C
编译器的重要部分。然而,隧道尽头有一盏灯。
例如,如果您使用 tuareg-mode 编辑 OCaml 代码,您可以向 Emacs 询问任何表达式的类型,因为 ocaml 编译器提供了该信息;因此你应该能够要求它按类型突出显示变量。这是要遵循的道路。
唉,
gcc
不提供该信息;但是,它的扩展名gccxml
却可以。此外,其他
C
编译器,例如clang
提供该信息开箱即用,并且有一个新文件 <代码>语义-clang.el依赖于这些功能(尽管仅用于完成,而不用于语法突出显示)。因此,这里没有任何开箱即用的东西,但如果您愿意使用
clang
而不是gcc
并为CEDET
开发做出贡献,你可能会得到你想要的。No. Emacs has no idea about the type of a specific expression; doing this would be tantamount to writing a significant part of a
C
compiler inELisp
.However, there is a light at the end of the tunnel.
E.g., if you edit
OCaml
code usingtuareg-mode
, you can ask Emacs about the type of any expression because theocaml
compiler provides that information; thus you should be able to ask it to highlight variables by type. This is the path to follow.Alas,
gcc
does not provide that information; however, its extensiongccxml
does.Also, other
C
compilers, e.g.,clang
, provide that information out of the box, and there is a new filesemantic-clang.el
which relies on those features (although for completion only, not for syntax highlighting).So, nothing out of the box for you here, but if you are willing to use
clang
instead ofgcc
and contribute to theCEDET
development, you might get what you want.不,不可能有选择地将给定颜色分配给 emacs 中的给定变量(或仅针对一个给定程序)。
但是,如果您只是寻找语法突出显示,当然,emacs 会突出显示大多数语言,您甚至可以为 emacs 不知道的语言创建语法突出显示。
前任。 Smali: https://github.com/strazzere/Emacs-Smali
No, it's not possible to selectively assign a given color to a given variable in emacs (or just for one given program).
However, if it's just syntax highlighting you are looking for, of course, emacs will highlight most languages, and you can even create syntax highlighting for languages emacs would not know about.
Ex. Smali: https://github.com/strazzere/Emacs-Smali