如何处理包含控制字符的 make-process 输出
How to handle make-process output including control character
我想处理 make-process
包括控制字符的输出。
(setq proc
(make-process
:name "sh"
:buffer (get-buffer-create "*proc*")
:command '("hub" "clone" "emacs-mirror/emacs")
:filter (lambda (proc string)
(when (buffer-live-p (process-buffer proc))
(with-current-buffer (process-buffer proc)
(let ((moving (= (point) (process-mark proc))))
(save-excursion
(goto-char (process-mark proc))
(insert string)
(set-marker (process-mark proc) (point)))
(if moving (goto-char (process-mark proc)))))))))
但是,控制字符按原样插入。怎么处理像shell?
注意:可能相关手册页
使用 Eshell 内部输出过滤器产生了一个很好的结果。
不需要整个Eshell(不要输入eshell-mode
),设置一些标记可以使用eshell-output-filter
功能。
(with-current-buffer (get-buffer-create "*proc*")
(set (make-local-variable 'eshell-last-input-start) (point-marker))
(set (make-local-variable 'eshell-last-input-end) (point-marker))
(set (make-local-variable 'eshell-last-output-start) (point-marker))
(set (make-local-variable 'eshell-last-output-end) (point-marker))
(set (make-local-variable 'eshell-last-output-block-begin) (point)))
;;=> 1
(setq proc
(make-process
:name "sh"
:buffer (get-buffer-create "*proc*")
:command '("hub" "clone" "emacs-mirror/emacs")
:filter (lambda (proc string)
(when (buffer-live-p (process-buffer proc))
(with-current-buffer (process-buffer proc)
(let ((moving (= (point) (process-mark proc))))
(save-excursion
(goto-char (process-mark proc))
(let ((inhibit-read-only t))
(eshell-output-filter proc string))
(set-marker (process-mark proc) (point)))
(if moving (goto-char (process-mark proc)))))))))
;;=> #<process sh>
(delete-process proc) ; kill the process when you want
;;=> nil
我想处理 make-process
包括控制字符的输出。
(setq proc
(make-process
:name "sh"
:buffer (get-buffer-create "*proc*")
:command '("hub" "clone" "emacs-mirror/emacs")
:filter (lambda (proc string)
(when (buffer-live-p (process-buffer proc))
(with-current-buffer (process-buffer proc)
(let ((moving (= (point) (process-mark proc))))
(save-excursion
(goto-char (process-mark proc))
(insert string)
(set-marker (process-mark proc) (point)))
(if moving (goto-char (process-mark proc)))))))))
但是,控制字符按原样插入。怎么处理像shell?
注意:可能相关手册页
使用 Eshell 内部输出过滤器产生了一个很好的结果。
不需要整个Eshell(不要输入eshell-mode
),设置一些标记可以使用eshell-output-filter
功能。
(with-current-buffer (get-buffer-create "*proc*")
(set (make-local-variable 'eshell-last-input-start) (point-marker))
(set (make-local-variable 'eshell-last-input-end) (point-marker))
(set (make-local-variable 'eshell-last-output-start) (point-marker))
(set (make-local-variable 'eshell-last-output-end) (point-marker))
(set (make-local-variable 'eshell-last-output-block-begin) (point)))
;;=> 1
(setq proc
(make-process
:name "sh"
:buffer (get-buffer-create "*proc*")
:command '("hub" "clone" "emacs-mirror/emacs")
:filter (lambda (proc string)
(when (buffer-live-p (process-buffer proc))
(with-current-buffer (process-buffer proc)
(let ((moving (= (point) (process-mark proc))))
(save-excursion
(goto-char (process-mark proc))
(let ((inhibit-read-only t))
(eshell-output-filter proc string))
(set-marker (process-mark proc) (point)))
(if moving (goto-char (process-mark proc)))))))))
;;=> #<process sh>
(delete-process proc) ; kill the process when you want
;;=> nil