Skip to content

Commit 81662e1

Browse files
committed
[#2628] Add a defcustom controlling nREPL's print buffer size
This makes it possible to stream results in bigger chunks (and as a corollary - fontify as Clojure bigger results).
1 parent e430c2c commit 81662e1

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Add support for nREPL 0.8 `completions` op. It's used if `cider-nrepl` is not available.
1414
* Add `browser` to the list of supported ClojureScript REPL types.
1515
* Add an interactive command to toggle Clojure font-locking in the REPL (`cider-repl-toggle-clojure-font-lock`).
16+
* Add a defcustom controlling nREPL's print buffer size (`cider-print-buffer-size`). It's set to 4K by default, nREPL own default is 1k.
1617

1718
### Changes
1819

cider-client.el

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,17 @@ Set to nil for no limit."
264264
:group 'cider
265265
:package-version '(cider . "0.21.0"))
266266

267+
(defcustom cider-print-buffer-size (* 4 1024)
268+
"The size in bytes of each value/output chunk when using print streaming.
269+
Smaller values mean smaller data chunks and faster feedback, but they also mean
270+
smaller results that can be font-locked as Clojure in the REPL buffers, as only
271+
a single chunk result can be font-locked.
272+
273+
The default value in nREPL is 1024."
274+
:type 'integer
275+
:group 'cider
276+
:package-version '(cider . "0.25.0"))
277+
267278
(defun cider--print-fn ()
268279
"Return the value to send in the nrepl.middleware.print/print slot."
269280
(pcase cider-print-fn
@@ -313,6 +324,8 @@ is included in the request if non-nil."
313324
`(("nrepl.middleware.print/print" ,(cider--print-fn))))
314325
(when cider-print-quota
315326
`(("nrepl.middleware.print/quota" ,cider-print-quota)))
327+
(when cider-print-buffer-size
328+
`(("nrepl.middleware.print/buffer-size" ,cider-print-buffer-size)))
316329
(unless (nrepl-dict-empty-p print-options)
317330
`(("nrepl.middleware.print/options" ,print-options))))))
318331

doc/modules/ROOT/pages/repl/configuration.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ each chunk is font-locked by itself and the results can't really be combined
152152
* The font-locking of results is an expensive operation which involves copying the value
153153
to a temporary buffer, where we check its integrity and do the actual font-locking.
154154

155+
By default CIDER instructs nREPL to stream data in 4K chunks, but you can easily modify this:
156+
157+
[source,lisp]
158+
----
159+
;; let's stream data in 8K chunks
160+
(setq cider-print-buffer-size (8 * 1024))
161+
----
162+
163+
Setting this to `nil` will result in using nREPL's default `buffer-size` of 1024 bytes.
164+
The smaller the print buffer size the faster you'll get feedback/updates in the REPL, so generally
165+
it's a good idea to stick to some relatively small size.
166+
155167
TIP: If you'd like to learn more about the font-locking of results you can check
156168
out the definition of `clojure-font-lock-as` and `clojure-font-lock-as-clojure`
157169
in `cider-util.el`.

0 commit comments

Comments
 (0)