在emacs中使用comint-mode中的参数执行python脚本

时间:2014-03-21 14:08:50

标签: python emacs elisp comint-mode

我正在为python脚本编写一个comint-mode。

可以使用以下命令启动脚本:

/usr/bin/python3.3 tool-name arg0

我正在使用comint-mode,因为此调用会在运行之前在提示符中询问一些信息。

如果我创建:

(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 :(得分:2)

make-comint-in-buffer的文档字符串( C-h f make-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.

因此,使用该函数的正确方法是将程序的 only 名称作为字符串,并传递要传递给程序的参数,作为make-comint-in-buffer的附加参数如下

(apply 'make-comint-in-buffer "tool" buffer "/usr/bin/python3.3" nil "tool-name" "arg0")

答案 1 :(得分:0)

您必须将tool-namearg0放在字符串之外。您想以交互方式询问用户吗?您可以轻松地执行此操作,请参阅http://ergoemacs.org/emacs/elisp_basics.html(最后)。

exple:

defun myFunc (firstArg)
  (interactive "sWhat is first arg ? ") ;; note the s
  ( ;; use firstArg)