2011-05-31 50 views
4

我在emacs中使用Fsharp mode^C x的密鑰被映射爲Run ...命令,其命令如下。在emacs/Fsharp模式下啓動mono exe文件

(defun fsharp-run-executable-file() 
    (interactive) 
    (let ((name (buffer-file-name))) 
    (if (string-match "^\\(.*\\)\\.\\(fs\\|fsi\\)$" name) 
     (shell-command (concat (match-string 1 name) ".exe"))))) 

的問題是,它試圖運行bash something.exe,而我需要運行的mono something.exe的命令。我收到了錯誤信息/bin/bash ...exe: cannot execute binary file

我怎麼能拿出一個新的elisp命令來啓動mono,然後得到結果來顯示它到*compilation*緩衝區?

回答

3

你可以重新定義fsharp運行可執行文件,並用這個來代替:

(defun fsharp-run-executable-file() 
    (interactive) 
    (let ((name (buffer-file-name))) 
    (if (string-match "^\\(.*\\)\\.\\(fs\\|fsi\\)$" name) 
     (compile (concat "mono " (match-string 1 name) ".exe"))))) 

有兩個變化:1)CONCAT mono命令之前(如petebu寫); 2)使用compile函數,以便輸出位於*compilation*緩衝區中。

要快速測試,只需評估上述函數(將其添加到您的Emacs init文件中以進行永久更改)。請注意,您不應修改fsharp.el文件,因爲我可能會在某些時候更新(您不想丟失更改)。

編輯

一個與以前的功能的問題是,它修改最後編譯命令。如果使用compilerecompile命令編譯代碼,這可能會令人討厭。這是一個修復:

(defun fsharp-run-executable-file() 
    (interactive) 
    (let ((name (buffer-file-name))) 
    (if (string-match "^\\(.*\\)\\.\\(fs\\|fsi\\)$" name) 
     (compilation-start (concat "mono " (match-string 1 name) ".exe"))))) 
4

你可以嘗試改變最後一行:

(shell-command (concat "mono " (match-string 1 name) ".exe"))))) 

,但我沒有測試過這一點。

+0

它工作正常。謝謝。 – prosseek 2011-06-01 14:48:21