Skip to content

Commit c5b2c40

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 c5b2c40

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

cider-mode.el

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,30 @@ and eval and the prefix is required to prevent evaluation."
232232
:group 'cider
233233
:package-version '(cider . "0.18.0"))
234234

235+
(defun cider--insert-in-repl (form eval)
236+
(goto-char (point-max))
237+
(let ((beg (point)))
238+
(insert form)
239+
(indent-region beg (point)))
240+
(when (if cider-invert-insert-eval-p
241+
(not eval)
242+
eval)
243+
(cider-repl-return))
244+
(goto-char (point-max)))
245+
235246
(defun cider-insert-in-repl (form eval)
236247
"Insert FORM in the REPL buffer and switch to it.
237248
If EVAL is non-nil the form will also be evaluated."
238249
(while (string-match "\\`[ \t\n\r]+\\|[ \t\n\r]+\\'" form)
239250
(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)))
251+
(let ((repl (cider-current-repl)))
252+
(if-let* ((window (get-buffer-window repl)))
253+
;; if buffer is visible we can scroll it
254+
(with-selected-window window
255+
(cider--insert-in-repl form eval))
256+
;; if not visible, we can only insert into it
257+
(with-current-buffer repl
258+
(cider--insert-in-repl form eval))))
249259
(when cider-switch-to-repl-after-insert-p
250260
(cider-switch-to-repl-buffer)))
251261

0 commit comments

Comments
 (0)