在Emacs/F#模式下启动Mono可执行文件

4
我在emacs中使用Fsharp mode^C x键映射到以下命令:运行...
(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*缓冲区中?
2个回答

4
您可以尝试将最后一行更改为:
(shell-command (concat "mono " (match-string 1 name) ".exe")))))

但我还没有测试过这个。


3
你可以重新定义fsharp-run-executable-file并使用这个替代方案:
(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)在命令之前连接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")))))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接