emacs 中的语法高亮显示。用不同的颜色标记不同的数据类型

发布于 2024-12-20 15:22:31 字数 258 浏览 2 评论 0原文

在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请恋爱 2024-12-27 15:22:32

不会。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 in ELisp.

However, there is a light at the end of the tunnel.

E.g., if you edit OCaml code using tuareg-mode, you can ask Emacs about the type of any expression because the ocaml 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 file semantic-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 of gcc and contribute to the CEDET development, you might get what you want.

灯角 2024-12-27 15:22:32

不,不可能有选择地将给定颜色分配给 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文