您可以使用process filter function 来做到这一点。
流程过滤函数是接收标准的函数
相关进程的输出。如果一个进程有一个过滤器,那么
该过程的所有输出都传递给过滤器。过程
缓冲区仅在存在时直接用于进程的输出
没有过滤器。
[...]
许多过滤器函数有时(或总是)将输出插入
进程的缓冲区,模仿 Emacs 没有时的动作
过滤器。
start-process 返回一个进程对象,它代表 Lisp 中的新子进程,您可以将其存储在变量中,例如 proc。您可以编写一个简单的过滤器函数,将进程的输出插入到相关的输出缓冲区中,从而将point 移动到缓冲区的末尾。
(defun my-insertion-filter (proc string)
(when (buffer-live-p (process-buffer proc))
(with-current-buffer (process-buffer proc)
;; Insert the text, advancing the process marker.
(goto-char (process-mark proc))
(insert string)
(set-marker (process-mark proc) (point)))))
使用set-process-filter 将该过滤器功能分配给您的流程。
(set-process-filter proc 'my-insertion-filter)
或者,如果只在进程终止后跳转到缓冲区的末尾就足够了,您可能需要使用sentinel。
进程哨兵是一个函数,每当
相关进程因任何原因更改状态,包括信号
(无论是由 Emacs 发送还是由进程自身的操作引起)
终止、停止或继续该过程。进程哨兵也是
进程退出时调用。
(defun my-sentinel (proc event)
(when (buffer-live-p (process-buffer proc))
(with-current-buffer (process-buffer proc)
(end-of-buffer))))
(请注意,此函数每次调用时都会滚动到进程缓冲区的末尾,这不仅可能发生在进程结束时。如果您真的只希望它在进程已终止,检查event是否为字符串"finished\n"。)
使用set-process-sentinel 将该哨兵分配给您的进程。
(set-process-sentinel proc 'my-sentinel)