emacs - 过滤在 emacs/elisp 中运行启动进程的结果

标签 emacs elisp

我有以下代码来运行 python 并在 scratch 缓冲区中获取结果。

(defun hello ()
  "Test, just prints Hello, world to mini buffer"
  (interactive)
  (start-process "my-process" "*scratch*" "python" "/Users/smcho/Desktop/temp/hello.py")
  (message "Hello, world : I'm glad to see you"))
(define-key global-map "\C-ck" 'hello)

Python代码如下。

if __name__ == "__main__":
    print "hello, world from Python"

使用 C-c k 在 scratch 缓冲区中提供以下代码。

hello, world from Python

Process my-process finished

I don't need the last part, as it's not from the python. Is there a way not to get this string or deleting this one effectively?

Added

Trey helped me to get an answer.

(defun hello ()
  "Test, just prints Hello, world to mini buffer"
 (interactive)
  (insert (shell-command-to-string "python /Users/smcho/Desktop/temp/hello.py"))
 (message "Hello, world : I'm glad to see you"))
(define-key global-map "\C-ck" 'hello)

最佳答案

你试过吗

(shell-command-to-string "/Users/smcho/Desktop/temp/hello.py")

这将返回一个字符串,您可以将其插入到 scratch 缓冲区中,如下所示:

(with-current-buffer "*scratch*"
  (insert (shell-command-to-string "/Users/smcho/Desktop/temp/hello.py")))

关于emacs - 过滤在 emacs/elisp 中运行启动进程的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3569461/

相关文章:

emacs - 您是否使用Emacs标签栏?

emacs - 用注释 (/* */) 替换 C++ 注释 (//)

emacs --daemon 与 --batch 和输入文件

emacs - 如何在 ESS 中缩进缓冲区?

emacs - 如何使泥土轨道模式与彩色多行提示一起使用

Emacs 口齿不清 : get RGB components of face?

windows - Emacs tramp 从 Linux 编辑 Windows 上的远程文件

c - Gnu Emacs 缩进我的 typedef

windows - 在 Windows 上的 Emacs 中重新定义键

列出与文件关联的缓冲区?