默认情况下,输出缓冲会一直滚动到底部:
Code
(let ((buffer (generate-new-buffer " *test*"))
proc)
(setq proc (start-process "Shell" buffer "/bin/bash" "-c"
"for i in {1..100}; do echo \"Line $i\"; done"))
(pop-to-buffer buffer))
方法1,最简单也是最"脏",在输出缓冲插入至少一个字符:
Code
(let ((buffer (generate-new-buffer " *test*"))
proc)
(with-current-buffer buffer
(insert "\n")
(goto-char (point-min)))
(setq proc (start-process "Shell" buffer "/bin/bash" "-c"
"for i in {1..100}; do echo \"Line $i\"; done"))
(pop-to-buffer buffer))
脏不单指视觉,即使插入一个不可见字符,输出内容也着实被污染了,除非最后再加一个删除的步骤,但这又让事情变复杂了。
方法2,自定义 filter:
Code
(let ((buffer (generate-new-buffer " *test*"))
proc)
(setq proc (start-process "Shell" buffer "/bin/bash" "-c"
"for i in {1..100}; do echo \"Line $i\"; done"))
(set-process-filter
proc (lambda (proc string)
(when (buffer-live-p (process-buffer proc))
(with-current-buffer (process-buffer proc)
(save-excursion
(goto-char (point-max))
(insert string)
(set-marker (process-mark proc) (point)))))))
(pop-to-buffer buffer))
替换原生的 filter 就为了移动光标位置,多少感觉有点小题大作。
不知道还有没有其他更简单的方法?