I want to move the point to the end of a window using elisp. The following code snippet:

(set-buffer "buffer-name")
(goto-char (point-min))

does not visually change the location of the cursor on the window visiting the buffer "buffer-name". This is because windows and buffers are separate concepts.

I found the function set-window-point documented at https://www.gnu.org/software/emacs/manual/html_node/elisp/Window-Point.html, but I am not able to use it. Its signature is:

set-window-point window position

What does the first argument, window mean?

I tried running the command (set-window-point "buffer-name" (point-min)), but it returns the error Wrong type argument: window-live-p, "buffer-name", which I guess, means that the window named "buffer-name" is not showing on the screen.

Purpose: I have multiple eshell windows on the screen that are logged in via ssh to remote machines and I have written an elisp function to run a single command on all the eshell buffers. I am able to run the command, but can't see the output because the windows do not auto-scroll. I have to switch to the windows and scroll down.

  • 2
    Could you solve your problem by setting the value of eshell-scroll-to-bottom-on-output to all?
    – nispio
    Mar 28, 2016 at 20:47
  • 1
    From the doc:The default for window is the selected window. default means if you provide nil as argument.
    – JeanPierre
    Mar 28, 2016 at 20:52
  • Yes, both the comments are useful. Setting the value of eshell-scroll-to-bottom-on-output to all solves the problem. Also, I didn't know that providing nil will pass the default argument. That works too.
    – Sagar Jha
    Mar 28, 2016 at 20:58
  • 1
    Using nil in set-window-point means that the current (selected) window will be used, even if it doesn't display the current buffer (as set e.g. by set-buffer). As you found out yourself, using get-buffer-window will return an actual window displaying the given buffer (There might be others, the whole list can be obtaid via get-buffer-window-list).
    – YoungFrog
    Mar 28, 2016 at 21:51

1 Answer 1


Unless you have a reason not to have the eshell buffers scroll automatically on output, I think that using eshell-scroll-to-bottom-on-output (check out M-x customize-apropos RET eshell to see related variables) will be a much more elegant and reliable solution.

The following function should do what you are asking for though. One caveat (of many) is that it will only scroll one window that is showing this buffer, if you happen to have more than one.

(defun my-scroll-buffer-to-bottom (buf)
  (with-current-buffer buf
     (get-buffer-window (current-buffer) 'visible)
  • 1
    Yes, thanks a lot. I have set the eshell-scroll-to-bottom-on-output variable to all and it perfectly solves my problem. But, the answer to the question is that we can call get-buffer-window to get the window from the buffer name.
    – Sagar Jha
    Mar 28, 2016 at 21:15

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.