Skip to content

Commit 7399bcc

Browse files
author
dan sutton
committed
Scroll buffer after using cider-insert-X-in-repl
As it stood, buffer would not scroll, even if you included a `(goto-char (point-max))` call at the end. Using solution from https://stackoverflow.com/questions/13530025/emacs-scroll-automatically-when-inserting-text Have to watch out if the buffer is visible or not. If it is, we can scroll it with `with-selected-window`. Otherwise, the best we can do is the current behavior. Note `get-buffer-window` returns nil if something is not visible which is why we need to branch on it.
1 parent 2b089d7 commit 7399bcc

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

cider-mode.el

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Clojure buffer."
121121
(defun cider-switch-to-last-clojure-buffer ()
122122
"Switch to the last Clojure buffer.
123123
The default keybinding for this command is
124-
the same as `cider-switch-to-repl-buffer',
124+
the same as variable `cider-switch-to-repl-buffer',
125125
so that it is very convenient to jump between a
126126
Clojure buffer and the REPL buffer."
127127
(interactive)
@@ -234,18 +234,23 @@ and eval and the prefix is required to prevent evaluation."
234234

235235
(defun cider-insert-in-repl (form eval)
236236
"Insert FORM in the REPL buffer and switch to it.
237-
If EVAL is non-nil the form will also be evaluated."
237+
If EVAL is non-nil the form will also be evaluated. Use
238+
`cider-invert-insert-eval-p' to invert this behavior."
238239
(while (string-match "\\`[ \t\n\r]+\\|[ \t\n\r]+\\'" form)
239240
(setq form (replace-match "" t t form)))
240-
(with-current-buffer (cider-current-repl)
241-
(goto-char (point-max))
242-
(let ((beg (point)))
243-
(insert form)
244-
(indent-region beg (point)))
245-
(when (if cider-invert-insert-eval-p
246-
(not eval)
247-
eval)
248-
(cider-repl-return)))
241+
(let ((repl (cider-current-repl)))
242+
(with-selected-window (or (get-buffer-window repl)
243+
(selected-window))
244+
(with-current-buffer repl
245+
(goto-char (point-max))
246+
(let ((beg (point)))
247+
(insert form)
248+
(indent-region beg (point)))
249+
(when (if cider-invert-insert-eval-p
250+
(not eval)
251+
eval)
252+
(cider-repl-return))
253+
(goto-char (point-max)))))
249254
(when cider-switch-to-repl-after-insert-p
250255
(cider-switch-to-repl-buffer)))
251256

0 commit comments

Comments
 (0)