5

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.

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 ...

1

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)))
0

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.

  • I think this would only help if I were using comint mode in the buffer but I'm not. The process is not an interpreter. But thanks for the suggestion. – tmalsburg Apr 26 '18 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.