在emacs / elisp中运行启动过程的过滤结果 [英] Filtering result from running start-process in emacs/elisp

查看:123
本文介绍了在emacs / elisp中运行启动过程的过滤结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 (defun hello()
测试,只是打印你好,世界到迷你缓冲区
交互式)
(开始进程我的进程* scratch *python/Users/smcho/Desktop/temp/hello.py)
(消息Hello,world:I 很高兴见到你))
(定义键全局映射\C-ck'hello)

python代码如下。

 如果__name__ ==__main__:
printhello,world from Python

使用Cc k给了我下面的代码> scratch 缓冲区。



$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b

我不需要最后一部分,因为它不是从python。有没有办法得到这个字符串或删除这个有效?



添加



Trey帮助我得到答案。

 (defun hello()
测试,只是打印你好,世界到迷你缓冲区
(interactive)
(insert(shell-command-to-stringpython /Users/smcho/Desktop/temp/hello.py))
(消息Hello,world:I很高兴见到你))
(定义键全局映射\C-ck'hello)


解决方案

您是否尝试过

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

将返回一个字符串,您可以像这样在 scratch 缓冲区中插入:

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


I have the following code to run python and get the result in scratch buffer.

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

The python code is as follows.

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

Using C-c k gives me the following code in scratch buffer.

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)

解决方案

Have you tried

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

That will return a string that you can insert in the scratch buffer like so:

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

这篇关于在emacs / elisp中运行启动过程的过滤结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆