目前在Vim我有以下设置:
au Bufenter *.clj map <F5> :!clojure1.2 %<CR>
au Bufenter *.py map <F5> :!python %<CR>
实质上,这意味着当我用.clj打开一个新的缓冲区时 扩展它使用命令将f5绑定到eval当前缓冲区 line命令“clojure1.2 filename”。以下行是python文件的绑定。
我的问题是 - 如何在Emacs中实现同样的功能? 我一直在寻找几个星期,但找不到任何简单的东西。一世 欣赏有clojure和python模式供我尝试。但我会 有兴趣看看我是否可以在几行中实现上述目标 elisp的。
答案 0 :(得分:4)
这样的事情可以解决问题:
(defun run-it ()
"Run the appropriate executable with the file of the current buffer as input."
(interactive)
(let ((command (cdr (assq major-mode '((clojure-mode . "clojure1.2")
(python-mode . "python"))))))
(unless command
(error "No command found for major mode: %s" major-mode))
(shell-command (format "%s %s" command (buffer-file-name)))))
(define-key python-mode-map (kbd "<f5>") 'run-it)
(define-key clojure-mode-map (kbd "<f5>") 'run-it)