Skip to content

Commit c35e862

Browse files
authored
Merge pull request #2590 from dpsutton/feature/scroll-on-insert
Scroll buffer after using cider-insert-X-in-repl
2 parents b5fba37 + 8605901 commit c35e862

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
### Changes
2121

22+
* * Add new defcustom `cider-switch-to-repl-on-insert`: Set to prevent cursor from going to the repl when inserting a form in the repl with the insert-to-repl commands. Replaces obsoleted `cider-switch-to-repl-after-insert-p`
2223
* **(Breaking)** Upgrade to nREPL 0.6.0. This is now the minimum required version.
2324
* **(Breaking)** Upgrade to piggieback 0.4.0. This is now the minimum required version.
2425
* **(Breaking)** Remove `cider.nrepl.middleware.pprint`. All functionality has been replaced by the built-in printing support in nREPL 0.6.

cider-mode.el

Lines changed: 30 additions & 13 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)
@@ -223,6 +223,17 @@ With a prefix argument, prompt for function to run instead of -main."
223223
:group 'cider
224224
:package-version '(cider . "0.18.0"))
225225

226+
(defcustom cider-switch-to-repl-on-insert t
227+
"Whether to switch to the repl when inserting a form into the repl."
228+
:type 'boolean
229+
:group 'cider
230+
:package-version '(cider . "0.21.0"))
231+
232+
(define-obsolete-variable-alias
233+
'cider-switch-to-repl-after-insert-p
234+
'cider-switch-to-repl-on-insert
235+
"0.21.0")
236+
226237
(defcustom cider-invert-insert-eval-p nil
227238
"Whether to invert the behavior of evaling.
228239
Default behavior when inserting is to NOT eval the form and only eval with
@@ -234,20 +245,26 @@ and eval and the prefix is required to prevent evaluation."
234245

235246
(defun cider-insert-in-repl (form eval)
236247
"Insert FORM in the REPL buffer and switch to it.
237-
If EVAL is non-nil the form will also be evaluated."
248+
If EVAL is non-nil the form will also be evaluated. Use
249+
`cider-invert-insert-eval-p' to invert this behavior."
238250
(while (string-match "\\`[ \t\n\r]+\\|[ \t\n\r]+\\'" form)
239251
(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)))
249-
(when cider-switch-to-repl-after-insert-p
250-
(cider-switch-to-repl-buffer)))
252+
(when cider-switch-to-repl-on-insert
253+
(cider-switch-to-repl-buffer))
254+
(let ((repl (cider-current-repl)))
255+
(with-selected-window (or (get-buffer-window repl)
256+
(selected-window))
257+
(with-current-buffer repl
258+
(goto-char (point-max))
259+
(let ((beg (point)))
260+
(insert form)
261+
(indent-region beg (point))
262+
(cider--font-lock-ensure beg (point)))
263+
(when (if cider-invert-insert-eval-p
264+
(not eval)
265+
eval)
266+
(cider-repl-return))
267+
(goto-char (point-max))))))
251268

252269
(defun cider-insert-last-sexp-in-repl (&optional arg)
253270
"Insert the expression preceding point in the REPL buffer.

0 commit comments

Comments
 (0)