在emacs的comint-mode中执行带参数的python脚本
我正在为一个Python脚本写一个comint模式。
这个脚本可以通过以下方式启动:
/usr/bin/python3.3 tool-name arg0
我使用comint模式是因为这个调用会在运行之前在提示符中询问一些信息。
如果我创建:
(defun create-app ()
"create application by using python tool"
(interactive)
(progn
(setq default-directory "/path/to/tool")
(setq buffer (get-buffer-create "*buffer_name*"))
(apply 'make-comint-in-buffer "tool" buffer "/usr/bin/python3.3" nil nil)
)
)
一切都正常,Python也能启动,但如果我写:
(defun create-app ()
"create application by using python tool"
(interactive)
(progn
(setq default-directory "/path/to/tool")
(setq buffer (get-buffer-create "*buffer_name*"))
(apply 'make-comint-in-buffer "tool" buffer "/usr/bin/python3.3 tool-name arg0" nil nil)
)
)
缓冲区告诉我,它无法执行程序“/usr/bin/python3.3 tool-name arg0”。
有没有人知道(无论是否使用comint)我该如何启动这个Python进程,并在启动之前让脚本询问一些信息?
2 个回答
0
你需要把 tool-name
和 arg0
放在字符串外面。你想要和用户进行互动提问吗?这很简单,你可以参考一下这个链接:http://ergoemacs.org/emacs/elisp_basics.html(在最后部分)。
举个例子:
defun myFunc (firstArg)
(interactive "sWhat is first arg ? ") ;; note the s
( ;; use firstArg)
2
make-comint-in-buffer
这个函数的文档说明(可以通过按 C-hfmake-comint-in-buffer
RET 来查看)提到以下内容:
(make-comint-in-buffer NAME BUFFER PROGRAM &optional STARTFILE &rest SWITCHES) Make a Comint process NAME in BUFFER, running PROGRAM. If BUFFER is nil, it defaults to NAME surrounded by `*'s. If there is a running process in BUFFER, it is not restarted. PROGRAM should be one of the following: - a string, denoting an executable program to create via `start-file-process' - a cons pair of the form (HOST . SERVICE), denoting a TCP connection to be opened via `open-network-stream' - nil, denoting a newly-allocated pty. ... If PROGRAM is a string, any more args are arguments to PROGRAM.
所以,正确使用这个函数的方法是,只需要把程序的名字作为一个字符串传进去,然后把要传给程序的其他参数作为额外的参数传给 make-comint-in-buffer
,具体如下:
(apply 'make-comint-in-buffer "tool" buffer "/usr/bin/python3.3" nil "tool-name" "arg0")