python - 在 emacs 中以 comint 模式执行带有参数的 python 脚本

标签 python emacs elisp comint-mode

我正在为 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 进程并让脚本在启动前询问一些信息?

最佳答案

make-comint-in-buffer 的文档字符串 (C-hfmake-comint-in-bufferRET)指出以下内容


(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.

So the correct way to use the function is to have the only name of the program as a string and pass the arguments to be passed to the program, as additional arguments to make-comint-in-buffer as follows

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

关于python - 在 emacs 中以 comint 模式执行带有参数的 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22561151/

相关文章:

python - 无法从ManyToManyField获取相关数据

python - Django ORM for select max(field1) from table group by (field2);

emacs - 如何在 Ubuntu (Unity 11.04) 上为 Emacs 启用全局菜单栏

security - 如何保护 emacs 服务器?

emacs - 使 Emacs 编译窗口在其他框架中显示有错误的源代码

python - 在 python 中创建字典列表

python - 如何在不设置__tablename__的情况下继承SQLAlchemy中的声明式?

emacs - Emacs 框架周围的边框/框架

emacs - 如何在 Emacs 中跳转到标记

Emacs - 找不到关于电子布局模式的信息