Skip to content

Commit dc80d87

Browse files
committed
Remove recentering logic from cider-repl.el
The behaviour of setting cider-repl-scroll-on-output to t is the same as setting scroll-conservatively to 101. Document this, and remove both the option and its associated logic. This results in a dramatic performance improvement in the REPL.
1 parent 06a62f3 commit dc80d87

File tree

2 files changed

+13
-53
lines changed

2 files changed

+13
-53
lines changed

cider-repl.el

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,7 @@ focused. Otherwise the buffer is displayed and focused."
102102
:type 'boolean
103103
:group 'cider-repl)
104104

105-
(defcustom cider-repl-scroll-on-output t
106-
"Controls whether the REPL buffer auto-scrolls on new output.
107-
108-
When set to t (the default), if the REPL buffer contains more lines than the
109-
size of the window, the buffer is automatically re-centered upon completion
110-
of evaluating an expression, so that the bottom line of output is on the
111-
bottom line of the window.
112-
113-
If this is set to nil, no re-centering takes place."
114-
:type 'boolean
115-
:group 'cider-repl
116-
:package-version '(cider . "0.11.0"))
105+
(make-obsolete-variable 'cider-repl-scroll-on-output 'scroll-conservatively "0.21")
117106

118107
(defcustom cider-repl-use-pretty-printing t
119108
"Control whether results in the REPL are pretty-printed or not.
@@ -512,15 +501,6 @@ If given a negative value of ARG, move to the beginning of defun."
512501
This will not work on non-current prompts."
513502
(= (point) cider-repl-input-start-mark))
514503

515-
(defun cider-repl--show-maximum-output ()
516-
"Put the end of the buffer at the bottom of the window."
517-
(when (and cider-repl-scroll-on-output (eobp))
518-
(let ((win (get-buffer-window (current-buffer) t)))
519-
(when win
520-
(with-selected-window win
521-
(set-window-point win (point-max))
522-
(recenter -1))))))
523-
524504
(defmacro cider-save-marker (marker &rest body)
525505
"Save MARKER and execute BODY."
526506
(declare (debug t))
@@ -681,8 +661,7 @@ If BOL is non-nil insert at the beginning of line. Run
681661
(when (and (= (point) cider-repl-prompt-start-mark)
682662
(not (bolp)))
683663
(insert-before-markers "\n")
684-
(set-marker cider-repl-output-end (1- (point)))))))
685-
(cider-repl--show-maximum-output)))
664+
(set-marker cider-repl-output-end (1- (point)))))))))
686665

687666
(defun cider-repl--emit-interactive-output (string face)
688667
"Emit STRING as interactive output using FACE."
@@ -718,8 +697,7 @@ If BOL is non-nil, emit at the beginning of the line."
718697
(save-excursion
719698
(cider-save-marker cider-repl-output-start
720699
(cider-save-marker cider-repl-output-end
721-
(cider-repl--insert-prompt cider-buffer-ns))))
722-
(cider-repl--show-maximum-output)))
700+
(cider-repl--insert-prompt cider-buffer-ns))))))
723701

724702
(defun cider-repl-emit-result (buffer string show-prefix &optional bol)
725703
"Emit into BUFFER the result STRING and mark it as an evaluation result.
@@ -738,8 +716,7 @@ of the line. If BOL is non-nil insert at the beginning of the line."
738716
(insert-before-markers (cider-font-lock-as-clojure string))
739717
(cider-propertize-region
740718
'(font-lock-face cider-repl-result-face rear-nonsticky (font-lock-face))
741-
(insert-before-markers string))))))
742-
(cider-repl--show-maximum-output)))
719+
(insert-before-markers string))))))))
743720

744721
(defun cider-repl-newline-and-indent ()
745722
"Insert a newline, then indent the next line.
@@ -810,8 +787,7 @@ SHOW-PREFIX and BOL."
810787
(when (boundp 'image-map)
811788
`(keymap ,image-map)))))
812789
(insert-before-markers " ")
813-
(add-text-properties start (point) props)))))
814-
(cider-repl--show-maximum-output))
790+
(add-text-properties start (point) props))))))
815791
t)
816792

817793
(defcustom cider-repl-image-margin 10
@@ -919,8 +895,7 @@ If NEWLINE is true then add a newline at the end of the input."
919895
(let ((end (point))) ; end of input, without the newline
920896
(cider-repl--add-to-input-history input)
921897
(when newline
922-
(insert "\n")
923-
(cider-repl--show-maximum-output))
898+
(insert "\n"))
924899
(let ((inhibit-modification-hooks t))
925900
(add-text-properties cider-repl-input-start-mark
926901
(point)
@@ -956,21 +931,13 @@ are not balanced."
956931
(cider-repl--send-input))
957932
((and (get-text-property (point) 'cider-old-input)
958933
(< (point) cider-repl-input-start-mark))
959-
(cider-repl--grab-old-input end-of-input)
960-
(cider-repl--recenter-if-needed))
934+
(cider-repl--grab-old-input end-of-input))
961935
((cider-repl--input-complete-p cider-repl-input-start-mark (point-max))
962936
(cider-repl--send-input t))
963937
(t
964938
(cider-repl-newline-and-indent)
965939
(message "[input not complete]"))))
966940

967-
(defun cider-repl--recenter-if-needed ()
968-
"Make sure that the point is visible."
969-
(unless (pos-visible-in-window-p (point-max))
970-
(save-excursion
971-
(goto-char (point-max))
972-
(recenter -1))))
973-
974941
(defun cider-repl--grab-old-input (replace)
975942
"Resend the old REPL input at point.
976943
If REPLACE is non-nil the current input is replaced with the old

doc/repl/configuration.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,14 @@ following:
8484

8585
## Auto-scrolling the REPL on Output
8686

87-
By default, if the REPL buffer contains more lines than the size of the
88-
(Emacs) window, the buffer is automatically re-centered upon
89-
completion of evaluating an expression, so that the bottom line of
90-
output is on the bottom line of the window.
91-
92-
The default has the nice advantage that you always see as much as you
93-
can from your previous REPL interactions, but can be pretty annoying
94-
if you're a heavy user of `C-l` (`M-x recenter-top-bottom`), as even
95-
if you're at the top of the REPL buffer the next output will scroll it all
96-
the way down.
97-
98-
If you don't like this re-centering you can disable it like this:
87+
Prior to version 0.21.0, the REPL buffer would be automatically re-centered
88+
whenever any output was printed, so that the prompt was on the bottom line of
89+
the window, displaying the maximum possible amount of output above it. This is
90+
no longer the default behaviour – you can now replicate it by setting the
91+
built-in option `scroll-conservatively`, for example:
9992

10093
```el
101-
(setq cider-repl-scroll-on-output nil)
94+
(add-hook 'cider-repl-mode-hook '(lambda () (setq scroll-conservatively 101)))
10295
```
10396

10497
## Result Prefix

0 commit comments

Comments
 (0)