emacs中的语法高亮显示。使用不同的颜色标记不同的数据类型 [英] Syntax highlighting in emacs. Marking different data types with different colours

查看:114
本文介绍了emacs中的语法高亮显示。使用不同的颜色标记不同的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Emacs中,是否可以使用不同的颜色标记不同数据类型的所有变量?例如如果我在C / C ++中有以下变量我的程序

  int i,j; 
float g,h;
char a,b;源代码i和j将被标记为红色,

g和h为绿色,a和b为蓝色。



我不知道将来会有多么有用,但是我觉得这将有助于我阅读代码,
,并成为匈牙利的好选择符号(不是我用这个符号:D)。

解决方案

否。 Emacs不知道具体表达式的类型;这样做将等于在 ELisp 中编写 C 编译器的重要部分。



然而,隧道尽头有一盏灯。



例如,如果您使用 tuareg-mode OCaml c>,您可以向Emacs询问任何表达式的类型,因为 ocaml 编译器提供该信息;因此您应该可以要求它按类型突出显示变量。这是要遵循的路径。



唉, gcc 不提供这些信息;但是,其扩展名为 gccxml



另外,其他 C 编译器,例如 clang ,提供开箱即用的信息,并有一个新的文件 semantic-clang.el ,它依赖于这些功能(虽然只是完成,不是用于语法高亮)。



所以,在这里没有什么开箱即用的,但是如果您愿意使用 clang 而不是 gcc 并为 CEDET 开发,你可能会得到你想要的。


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).

解决方案

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.

这篇关于emacs中的语法高亮显示。使用不同的颜色标记不同的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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