当我尝试在Emacs 24.2.1下进行字节编译csharp-mode时,我收到以下错误:
csharp-mode.el:2028:1:Error: Symbol's value as variable is void: csharp-enum-decl-re
This post确认了同样的编译问题并提供了以下补救措施:
我尝试通过在C上执行C-x C-e来手动定义csharp-enum-decl-re defconst;这得到了编译。
这个补救措施对我也有用!但是,这种补救办法给我留下了几个问题:
csharp-enum-decl-re
,为什么 csharp-mode.el 无法进行字节编译? (请参阅 csharp-mode.el 源代码的第一个链接。)csharp-enum-decl-re
?(defconst csharp-font-lock-keywords-2 (c-lang-const c-matchers-2 csharp)
"Fast normal highlighting for C# mode.")
答案 0 :(得分:4)
据我所知:
文件无法进行字节编译,因为宏需要尚未定义的符号的值。这个错误滑向一些程序员,因为他们正在开发一个emacs会话,他们已经评估了他们正在编写的一些代码。编译错误的典型解决方案是对编译时需要知道的表达式使用eval-and-compile
宏。
在eval-buffer
之前使用byte-compile
是一种解决方法,可以帮助您避免修改源代码。编写补丁并将其发送给作者是另一种选择。
代码相对棘手,因为它在宏中非常依赖。我需要c-lang-defconst
来定义c-matchers-1
,c-matchers-2
和c-matchers-3
的值,但c-matchers-2
需要csharp-enum-decl-re
的值(参见第1304行) )。请注意,符号名称(c-matchers- *)由c-lang-defconst
宏本身创建。