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

4 Answers 4


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


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.


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
    Commented Apr 26, 2018 at 17:32
  • this worked perfectly for me with the Racket REPL, thanks! Commented Jan 24, 2021 at 14:07

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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