elisp - How can I make an Emacs shell command output buffer always follow the bottom? -


i'm writing emacs minor mode has emacs commands invoke shell commands. i'm using following code:

    (let ((output (get-buffer-create "*foo output*")))       (start-process "foo process" output argv0)       (display-buffer output)) 

i'd buffer containing shell commands automatically scroll bottom time output inserted, or @ least when command finished executing. how can that?

you can using process filter function.

a process filter function function receives standard output associated process. if process has filter, output process passed filter. process buffer used directly output process when there no filter.

[...]

many filter functions (or always) insert output in process's buffer, mimicking actions of emacs when there no filter.

start-process returns process object stands new subprocess in lisp can store in variable, proc. can write simple filter function inserts output of process associated output buffer, thereby moving point end of buffer.

(defun my-insertion-filter (proc string)   (when (buffer-live-p (process-buffer proc))     (with-current-buffer (process-buffer proc)       ;; insert text, advancing process marker.       (goto-char (process-mark proc))       (insert string)       (set-marker (process-mark proc) (point))))) 

use set-process-filter assign filter function process.

(set-process-filter proc 'my-insertion-filter) 

alternatively, if it's sufficient jump end of buffer once process has terminated, might want use sentinel.

a process sentinel function called whenever associated process changes status reason, including signals (whether sent emacs or caused process's own actions) terminate, stop, or continue process. process sentinel called if process exits.

(defun my-sentinel (proc event)   (when (buffer-live-p (process-buffer proc))     (with-current-buffer (process-buffer proc)       (end-of-buffer)))) 

(note function scrolls end of process buffer every time called may happen not @ end of process. if really want when process has terminated, check if event string "finished\n".)

use set-process-sentinel assign sentinel process.

(set-process-sentinel proc 'my-sentinel) 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -