Emacs下一键执行代码(可输入)——maple-run
之前一直使用quickrun来执行一些代码片段,但quickrun有一个问题就是无法输入,比如python代码
1a = input("aaaaa: ") 2print(a)
需要建立一个qrinput的文件,太过麻烦,所以我平时测试一些需要输入的python代码时会使用
1(defun maple/run-python () 2 (interactive) 3 (or (python-shell-get-process) (call-interactively 'run-python)) 4 (if (use-region-p) 5 (python-shell-send-region (region-beginning) (region-end) t) 6 (python-shell-send-buffer t)))
但退出python shell又需要手动输入exit(),我是一个怕麻烦的人,所以写了一个可供输入的 emacs-maple-run
来一键执行当前buffer的代码(后面发现quickrun其实也可以通过quickrun-shell来提供实时输入,不过使用的是eshell)
目前只加了python,go,lua,html的执行命令,自定义只需要使用
1(add-to-list 'maple-run:alist '(python-mode :command "python %F")) 2(add-to-list 'maple-run:alist '(c-mode :command "gcc %F -o %b && ./%b")) 3(add-to-list 'maple-run:alist '((html-mode web-mode) :command browse-url-of-file))
另外,maple-run也提供了一个非常方便的函数 (maple-run:script process-name program prgram-args) 来供用户自定义命令,比如:
-
打开一个bash shell
1(maple-run:script nil "bash") -
打开一个ipython shell
1(maple-run:script nil "ipython") -
执行golang代码
1(maple-run:script nil "go" "run" (buffer-file-name)) -
默认的执行方式
1(maple-run:script nil "bash" "-c" "python file.py")
