Emacs下一键执行代码(可输入)——maple-run

之前一直使用quickrun来执行一些代码片段,但quickrun有一个问题就是无法输入,比如python代码

a = input("aaaaa: ")
print(a)

需要建立一个qrinput的文件,太过麻烦,所以我平时测试一些需要输入的python代码时会使用

  (defun maple/run-python ()
    (interactive)
    (or (python-shell-get-process) (call-interactively 'run-python))
    (if (use-region-p)
        (python-shell-send-region (region-beginning) (region-end) t)
      (python-shell-send-buffer t)))

但退出python shell又需要手动输入exit(),我是一个怕麻烦的人,所以写了一个可供输入的

来一键执行当前buffer的代码(后面发现quickrun其实也可以通过quickrun-shell来提供实时输入,不过使用的是eshell)

目前只加了python,go,lua,html的执行命令,自定义只需要使用

(add-to-list 'maple-run:alist '(python-mode :command "python %F"))
(add-to-list 'maple-run:alist '(c-mode :command "gcc %F -o %b && ./%b"))
(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

(maple-run:script nil "bash")

打开一个ipython shell

(maple-run:script nil "ipython")

执行golang代码

(maple-run:script nil "go" "run" (buffer-file-name))

默认的执行方式

(maple-run:script nil "bash" "-c" "python file.py")

欢迎测试

7 个赞

d i n g