簡體   English   中英

使用csharp-mode和Mono

[英]Using csharp-mode and Mono

我在OS X的Emacs 23中使用csharp-mode。我想使flymake語法檢查正常工作,但我對emacs lisp並不熟悉,無法知道在哪里將csharp-mode.el文件中的內容更改為更換編譯器。 任何援助將不勝感激。

如果將以下內容添加到Emacs的init文件中,則可以完成此工作:

(add-hook  'csharp-mode-hook 'flymake-mode)

EmacsWiki

歷史最初的flymake-for-csharp來自MSDN上的博客文章。 此后已對其進行了概括,更新,並使其更加可靠和靈活。 在2011年5月,它已集成到csharp-mode本身。

為了更改編譯器,您可以在C#代碼的頂部添加注釋:

// flymake: csc.exe /t:module /R:MyAssembly.dll @@FILE@@

有關更改編譯器的選項的更多詳細信息,請參見csharp-mode.el源文件中的注釋(搜索“ csharp-flymake-get-cmdline”)。

編輯:好的,基於您下面關於不想將flymake注釋行放在C#代碼中的評論,我提出了一個替代解決方案。 將以下代碼放入Emacs初始化文件中。 (setq my-csharp-default-compiler "mono @@FILE@@")行更改為所需的任何編譯行。 現在,無論何時打開C#文件,都應該能夠使用flymake,而無需在C#源代碼中添加注釋行。 如果在以后的某個階段要使用標准的csharp-mode機制(在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)))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM