[英]On Emacs, getting the output of a command sent to a buffer via Emacs-Lisp
I would like to write a small script in ELisp that would:我想在 ELisp 中编写一个小脚本:
I am struggling with point 2: I cant get the output of a command.我在第 2 点上苦苦挣扎:我无法获得命令的 output。 For example, if I have a shell buffer on, I can use
例如,如果我有一个 shell 缓冲区,我可以使用
(process-send-string "shell" "help\n")
to send "help" to my shell buffer.向我的 shell 缓冲区发送“帮助”。 It will then show the list of the commands available.
然后它将显示可用命令的列表。 But how can I get this list to use it somewhere else?
但是我怎样才能让这个列表在其他地方使用呢?
Thanks,谢谢,
S4m S4m
(buffer-string)
returns the contents of the current buffer, so (with-current-buffer <buf> (buffer-string))
will return the contents of <buf>
. (buffer-string)
返回当前缓冲区的内容,因此(with-current-buffer <buf> (buffer-string))
将返回<buf>
的内容。
I don't know the exact emacs commands for this off the top of my head, but one option would be to do the following:我不知道确切的 emacs 命令,但一种选择是执行以下操作:
Have you considered using the shell-command
or shell-command-to-string
functions?您是否考虑过使用
shell-command
或shell-command-to-string
函数?
The don't "send a command to a buffer" like you asked, but they do both allow running a command through a process that will be started just for that purpose and either dumping the output into a target buffer or collecting it into a string.不要像您问的那样“将命令发送到缓冲区”,但它们都允许通过将为此目的启动的进程运行命令,并将 output 转储到目标缓冲区或将其收集到字符串中.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.