Fork me on GitHub

trying to insert contents into another buffer and move point to the end of the buffer. not having luck. Create a buffer named random, and then

(with-current-buffer "random"
  (goto-char (point-max))
  (insert "\nbob\n")
  (goto-char (point-max))
and no luck. point stays where it was as if there was an unwind-protect somewhere. anyone know how to do this?


(with-selected-window (get-buffer-window ...))

Michael Griffiths21:02:15

Are you possibly inside a save-excursion?

Michael Griffiths21:02:54

FWIW: (with-current-buffer "*scratch*" (goto-char (point-max)) (insert "foo\n")) works for me


i think that's because you're currently there. do it with a buffer that is separate from your current view


my steps above mimic more closely what we are doing with the repl buffer

Michael Griffiths21:02:18

You’re right, if the buffer isn’t visible it won’t move the point


even if its visible it doesn't move the point


screenshot incoming


note point at the end of "random stuff". using the first form will move point

Michael Griffiths22:02:28

Seems like we do this in a couple of places:

(with-selected-window (or (get-buffer-window ...buffer-name...)

Michael Griffiths22:02:02

I guess if the buffer isn’t in any live window we have to leave the point where it is


ok. there's a problem if the buffer isn't visible in a window. can't use with-selected-window. how about something like this:

(defun cider-insert-in-repl (form eval)
  "Insert FORM in the REPL buffer and switch to it.
If EVAL is non-nil the form will also be evaluated."
  (while (string-match "\\`[ \t\n\r]+\\|[ \t\n\r]+\\'" form)
    (setq form (replace-match "" t t form)))
  (let ((repl (cider-current-repl)))
    (if-let* ((window (get-buffer-window repl)))
        (with-selected-window window
          (cider--insert-in-repl form eval))
      (with-current-buffer repl
        (cider--insert-in-repl form eval))))
  (when cider-switch-to-repl-after-insert-p


ie, if there's a window, use with-selected-window else fall back to with-current-buffer and it won't scroll, but its not visible so whatever


so pull the guts out into cider--insert-in-repl and that is either in the context of a selected window or with-current-buffer


goog find @cichli. i've updated the PR