我在OS X上的Emacs 23中使用csharp-mode.我想让flymake语法检查正常工作,但我对emacs lisp不太熟悉,知道在csharp-mode.el文件中更改内容以更改编译器.任何援助将不胜感激.
解决方法:
如果将以下内容添加到Emacs init文件中,则应执行以下操作:
(add-hook 'csharp-mode-hook 'flymake-mode)
从EmacsWiki开始:
History The original flymake-for-csharp came from a Blog Post on MSDN.
It has since been generalized, updated, and made more reliable and
flexible. In May 2011, it was integrated into csharp-mode itself.
要更改编译器,可以在C#代码的顶部添加注释:
// flymake: csc.exe /t:module /R:MyAssembly.dll @@FILE@@
有关更改编译器的选项的更多详细信息,请参阅csharp-mode.el源文件中的注释(搜索“csharp-flymake-get-cmdline”).
编辑:好的,根据你在下面的评论,不想在你的C#代码中放入flymake评论行,我想出了另一种解决方案.将以下代码放在Emacs init文件中.将(setq my-csharp-default-compiler“mono @@ FILE @@”)行更改为您想要的任何编译行.现在,无论何时打开C#文件,您都应该能够使用flymake而无需在C#源中添加注释行.如果在稍后阶段,您想要使用标准的csharp模式机制(在C#源文件中查找flymake注释),则只需将语句更改为(setq my-csharp-default-compiler nil) .
;; Basic code required for C# mode
(require 'flymake)
(autoload 'csharp-mode "csharp-mode" "Major mode for editing C# code." t)
(setq auto-mode-alist (append '(("\\.cs$" . csharp-mode)) auto-mode-alist))
;; Custom code to use a default compiler string for all C# files
(defvar my-csharp-default-compiler nil)
(setq my-csharp-default-compiler "mono @@FILE@@")
(defun my-csharp-get-value-from-comments (marker-string line-limit)
my-csharp-default-compiler)
(add-hook 'csharp-mode-hook (lambda ()
(if my-csharp-default-compiler
(progn
(fset 'orig-csharp-get-value-from-comments
(symbol-function 'csharp-get-value-from-comments))
(fset 'csharp-get-value-from-comments
(symbol-function 'my-csharp-get-value-from-comments))))
(flymake-mode)))