gpt4 book ai didi

emacs - 在 emacs/elisp 中运行 start-process 的过滤结果

转载 作者:行者123 更新时间:2023-12-04 06:47:16 25 4
gpt4 key购买 nike

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

(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 在暂存缓冲区中给我以下代码。
hello, world from PythonProcess 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")

这将返回一个字符串,您可以像这样将其插入到暂存缓冲区中:
(with-current-buffer "*scratch*"
(insert (shell-command-to-string "/Users/smcho/Desktop/temp/hello.py")))

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com