9

Context: I have a window that shows the output of a shell command. As new lines are added, I'd like the window to always show the most recent lines. Example:

(let ((temp-window (or (get-buffer-window "*test*")
                       (split-window-below -10))))
  (start-process-shell-command
   "test-process"
   "*test*"
   "sleep 1; ps -ax")
  (set-window-buffer temp-window "*test*"))

For reasons that I don't understand, the window scrolls the first time this code is executed but not the second time (when the buffer already exists).

I'm on Emacs 26.0.60 on Ubuntu 16.04.

npostavs
  • 9,033
  • 1
  • 21
  • 53
tmalsburg
  • 2,540
  • 1
  • 14
  • 29

4 Answers4

2

Does it help to customize option comint-scroll-to-bottom-on-output? C-h v tells us:

comint-scroll-to-bottom-on-output is a variable defined in comint.el. Its value is nil

This variable is an alias for comint-move-point-for-output.

Documentation:

Controls whether interpreter output moves point to the end of the output.

If nil, then output never moves point to the output. (If the output occurs at point, it is inserted before point.)

If t or `all', move point in all windows showing the buffer.

If this, move point only the selected window.

If others, move point only in other windows, not in the selected window.

The default is nil.

See the variable comint-scroll-show-maximum-output and the function comint-postoutput-scroll-to-bottom.

This variable is buffer-local in all Comint buffers.

You can customize this variable.

Drew
  • 75,699
  • 9
  • 109
  • 225
2

How about?

(let ((temp-window (or (get-buffer-window "*test*")
                       (split-window-below -10))))
  (set-window-buffer temp-window "*test*")
  (select-window temp-window)
  (goto-char (point-max))
  (start-process-shell-command
   "test-process"
   "*test*"
   "sleep 1; ps -ax"))

The most common way to do this is to select the target window and place point at point-max to continue scrolling automatically. There are other ways to do this by selecting the window temporarily and going back to another window, but this example should be sufficient to convey the general concept. See also a related function set-window-point ...

lawlist
  • 18,826
  • 5
  • 37
  • 118
2

Here the solution a use for my compilation log buffer

(let ((buf (get-buffer "*Compile-Log*")))
  (set-window-point (get-buffer-window buf) (buffer-size buf)))
djangoliv
  • 3,169
  • 16
  • 31
1

Try compilation-scroll-output. Just came across it in: Automatically scroll *compilation* window, beside source-buffer window. Only works for compilation buffers obviously.

marcantonio
  • 133
  • 5