Skip to content

Commit 3c046a9

Browse files
authored
Merge pull request #2579 from cichli/new-nrepl
Update to nREPL 0.6.0 / cider-nrepl 0.21.0
2 parents f4441e7 + 7dd2ce1 commit 3c046a9

20 files changed

+469
-480
lines changed

.dir-locals.el

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
(cider--jack-in . 1)
2323
(cider--make-result-overlay . 1)
2424
;; need better solution for indenting cl-flet bindings
25-
(multiline-comment-handler . defun) ;; cl-flet
2625
(insert-label . defun) ;; cl-flet
2726
(insert-align-label . defun) ;; cl-flet
2827
(insert-rect . defun) ;; cl-flet

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,29 @@
44

55
### New features
66

7+
* The `cider-test-run-*` and `cider-ns-refresh-*` commands are now interruptible by the `cider-interrupt` command.
8+
* Many commands now stream printed results back to the client incrementally – meaning it's now possible to, for example, interrupt evaluations while their result is being rendered.
9+
* New option: `cider-repl-init-code`. This is a list of strings containing Clojure code to evaluate when the REPL starts (with bindings for any `set!`-able vars in place). Replaces `cider-print-length` and `cider-print-level`, which are now obsolete.
10+
* New option: `cider-print-quota`. This is a hard limit on the number of bytes that will be returned by any printing operation. This defaults to one megabyte and can be set to `nil` if no limit is desired.
11+
712
### Changes
13+
14+
* **(Breaking)** Upgrade to nREPL 0.6.0. This is now the minimum required version.
15+
* **(Breaking)** Upgrade to piggieback 0.4.0. This is now the minimum required version.
16+
* **(Breaking)** Remove `cider.nrepl.middleware.pprint`. All functionality has been replaced by the built-in printing support in nREPL 0.6.
17+
* Option `cider-repl-scroll-on-output` is now obsolete, and the default REPL behaviour has changed to _not_ recenter the window. The built-in variable `scroll-conservatively` can be set to 101 (either globally or locally in the REPL buffer) to restore the old behaviour. This change has a dramatic positive effect on REPL performance.
18+
* `cider-pprint-fn` and `cider-pprint-options` are now obsolete, replaced by `cider-print-fn` and `cider-print-options`.
19+
* `cider-debug-print-options`, `cider-stacktrace-print-options`, and `cider-repl-pretty-print-width` are now all obsolete, replaced by `cider-print-options`.
820
* [#2546](https://github.com/clojure-emacs/cider/pull/2546): New defcustom `cider-ns-save-files-on-refresh-modes` to control for which buffers `cider-ns-refresh` should save before refreshing.
921

1022
### Bug fixes
23+
1124
* Fix values for `cider-preferred-build-tool` variable.
1225
* Fix value and safe property for `cider-allow-jack-in-without-project` variable.
1326
* `cider-ns-save-files-on-refresh` will now save any modified buffers visiting files on the classpath, rather than just in the current project.
1427
* `cider-expected-ns` no longer requires an absolute path as its argument, and now internally handles paths canonically and consistently.
28+
* Fixed a bug causing REPL output to be inserted after the prompt.
29+
* Fixed a bug causing `cider-pprint-eval-last-sexp-to-comment` and `cider-pprint-eval-defun-to-comment` to not insert anything.
1530

1631
## 0.20.0 (2019-01-14)
1732

cider-client.el

+94-65
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,18 @@
2525

2626
;;; Code:
2727

28+
(require 'map)
29+
(require 'seq)
30+
(require 'subr-x)
31+
32+
(require 'clojure-mode)
2833
(require 'spinner)
29-
(require 'nrepl-client)
34+
35+
(require 'cider-compat)
3036
(require 'cider-connection)
3137
(require 'cider-common)
3238
(require 'cider-util)
33-
(require 'clojure-mode)
34-
35-
(require 'subr-x)
36-
(require 'cider-compat)
37-
(require 'seq)
39+
(require 'nrepl-client)
3840

3941

4042
;;; Eval spinner
@@ -195,64 +197,71 @@ buffer, defaults to (cider-current-repl)."
195197
If NS is non-nil, include it in the eval request."
196198
(nrepl-sync-request:eval input (or connection (cider-current-repl)) ns))
197199

198-
(defcustom cider-pprint-fn 'pprint
199-
"Sets the function to use when pretty-printing evaluation results.
200+
(defcustom cider-print-fn 'pprint
201+
"Sets the function to use for printing.
202+
203+
nil – to defer to nREPL to choose the printing function. This will use
204+
the bound value of \\=`nrepl.middleware.print/*print-fn*\\=`, which
205+
defaults to the equivalent of \\=`clojure.core/pr\\=`.
200206
201-
The value must be one of the following symbols:
207+
`pr' – to use the equivalent of \\=`clojure.core/pr\\=`.
202208
203-
`pprint' - to use \\=`clojure.pprint/pprint\\=`
209+
`pprint' to use \\=`clojure.pprint/pprint\\=` (this is the default).
204210
205-
`fipp' - to use the Fast Idiomatic Pretty Printer, approximately 5-10x
206-
faster than \\=`clojure.core/pprint\\=` (this is the default)
211+
`fipp' to use the Fast Idiomatic Pretty Printer, approximately 5-10x
212+
faster than \\=`clojure.core/pprint\\=`.
207213
208-
`puget' - to use Puget, which provides canonical serialization of data on
209-
top of fipp, but at a slight performance cost
214+
`puget' to use Puget, which provides canonical serialization of data on
215+
top of fipp, but at a slight performance cost.
210216
211-
`zprint' - to use zprint, a fast and flexible alternative to the libraries
217+
`zprint' to use zprint, a fast and flexible alternative to the libraries
212218
mentioned above.
213219
214-
Alternatively, can be the namespace-qualified name of a Clojure function of
215-
two arguments - an object to print and an options map. The options map will
216-
have string keys. If the function
217-
cannot be resolved, an exception will be thrown.
218-
219-
The function should ideally have a two-arity variant that accepts the
220-
object to print and a map of configuration options for the printer. See
221-
`cider-pprint-options' for details.
222-
223-
The function is also assumed to respect the contract of
224-
\\=`clojure.pprint/pprint\\=` with respect to the bound values of
225-
\\=`*print-length*\\=`, \\=`*print-level*\\=`, \\=`*print-meta*\\=`, and
226-
\\=`clojure.pprint/*print-right-margin*\\=`. Those would normally serve as
227-
fallback values when a map of print options is not supplied explicitly."
228-
:type '(choice (const pprint)
220+
Alternatively can be the namespace-qualified name of a Clojure var whose
221+
function takes three arguments: the object to print, the
222+
\\=`java.io.PrintWriter\\=` to print on, and a (possibly nil) map of
223+
options. If the function cannot be resolved, will behave as if set to
224+
nil."
225+
:type '(choice (const nil)
226+
(const pr)
227+
(const pprint)
229228
(const fipp)
230229
(const puget)
231230
(const zprint)
232231
string)
233232
:group 'cider
234-
:package-version '(cider . "0.11.0"))
233+
:package-version '(cider . "0.21.0"))
235234

236-
(defcustom cider-pprint-options nil
237-
"A list of options for the pretty-printer that will be converted to a map.
238-
Note that map can only have string keys, so the printer functions should be
239-
able to handle those. Here's an example for `pprint':
235+
(defcustom cider-print-options nil
236+
"A map of options that will be passed to `cider-print-fn'.
237+
Here's an example for `pprint':
240238
241-
'(dict \"length\" 50 \"right-margin\" 70)"
239+
'((\"length\" 50) (\"right-margin\" 70))"
242240
:type 'list
243241
:group 'cider
244-
:package-version '(cider . "0.20.0"))
242+
:package-version '(cider . "0.21.0"))
243+
244+
(make-obsolete-variable 'cider-pprint-fn 'cider-print-fn "0.21")
245+
(make-obsolete-variable 'cider-pprint-options 'cider-print-options "0.21")
246+
247+
(defcustom cider-print-quota (* 1024 1024)
248+
"A hard limit on the number of bytes to return from any printing operation.
249+
Set to nil for no limit."
250+
:type 'integer
251+
:group 'cider
252+
:package-version '(cider . "0.21.0"))
245253

246-
(defun cider--pprint-fn ()
247-
"Return the value to send in the pprint-fn slot of messages."
248-
(pcase cider-pprint-fn
254+
(defun cider--print-fn ()
255+
"Return the value to send in the nrepl.middleware.print/print slot."
256+
(pcase cider-print-fn
257+
(`pr "cider.nrepl.pprint/pr")
249258
(`pprint "cider.nrepl.pprint/pprint")
250-
(`fipp "cider.nrepl.pprint/fipp-pprint")
251-
(`puget "cider.nrepl.pprint/puget-pprint")
259+
(`fipp "cider.nrepl.pprint/fipp-pprint")
260+
(`puget "cider.nrepl.pprint/puget-pprint")
252261
(`zprint "zprint.core/zprint-str")
253-
(_ cider-pprint-fn)))
262+
(_ cider-print-fn)))
254263

255-
(defvar cider--pprint-options-mapping
264+
(defvar cider--print-options-mapping
256265
'((right-margin
257266
((fipp . width) (puget . width) (zprint . width)))
258267
(length
@@ -261,32 +270,49 @@ able to handle those. Here's an example for `pprint':
261270
((fipp . print-level) (puget . print-level) (zprint . max-depth))))
262271
"A mapping of print option for the various supported print engines.")
263272

264-
(defun cider--pprint-option (name printer)
265-
"Covert the generic NAME to its PRINTER specific variant.
273+
(defun cider--print-option (name printer)
274+
"Convert the generic NAME to its PRINTER specific variant.
266275
E.g. pprint's right-margin would become width for fipp.
267276
The function is useful when you want to generate dynamically
268277
print options.
269278
270279
NAME can be a string or a symbol. PRINTER has to be a symbol.
271280
The result will be a string."
272281
(let* ((name (cider-maybe-intern name))
273-
(result (cdr (assoc printer (cadr (assoc name cider--pprint-options-mapping))))))
282+
(result (cdr (assoc printer (cadr (assoc name cider--print-options-mapping))))))
274283
(symbol-name (or result name))))
275284

276-
(defun cider--nrepl-pprint-request-plist (right-margin &optional pprint-fn)
277-
"Plist to be appended to an eval request to make it use pprint.
278-
PPRINT-FN is the name of the Clojure function to use.
279-
RIGHT-MARGIN specifies the maximum column-width of the pretty-printed
280-
result, and is included in the request if non-nil."
281-
(let* ((print-options (or cider-pprint-options (nrepl-dict))))
282-
(when right-margin
283-
(setq print-options (nrepl-dict-put print-options (cider--pprint-option "right-margin" cider-pprint-fn) right-margin)))
284-
(nconc `("printer" ,(or pprint-fn (cider--pprint-fn)))
285-
(and (not (nrepl-dict-empty-p print-options)) `("print-options" ,print-options)))))
286-
287-
(defun cider--nrepl-content-type-plist ()
288-
"Plist to be appended to an eval request to make it use content-types."
289-
'("content-type" "true"))
285+
(defun cider--nrepl-print-request-map (&optional right-margin)
286+
"Map to merge into requests that require pretty-printing.
287+
RIGHT-MARGIN specifies the maximum column-width of the printed result, and
288+
is included in the request if non-nil."
289+
(let* ((width-option (cider--print-option "right-margin" cider-print-fn))
290+
(print-options (thread-last
291+
(map-merge 'hash-table
292+
`((,width-option ,right-margin))
293+
cider-print-options)
294+
(map-pairs)
295+
(seq-mapcat #'identity)
296+
(apply #'nrepl-dict))))
297+
(map-merge 'list
298+
`(("nrepl.middleware.print/print" ,(cider--print-fn))
299+
("nrepl.middleware.print/stream?" "1"))
300+
(when cider-print-quota
301+
`(("nrepl.middleware.print/quota" ,cider-print-quota)))
302+
(unless (nrepl-dict-empty-p print-options)
303+
`(("nrepl.middleware.print/options" ,print-options))))))
304+
305+
(defun cider--nrepl-pr-request-map ()
306+
"Map to merge into requests that do not require pretty printing."
307+
(map-merge 'list
308+
`(("nrepl.middleware.print/print" "cider.nrepl.pprint/pr"
309+
"nrepl.middleware.print/stream?" nil))
310+
(when cider-print-quota
311+
`(("nrepl.middleware.print/quota" ,cider-print-quota)))))
312+
313+
(defun cider--nrepl-content-type-map ()
314+
"Map to be merged into an eval request to make it use content-types."
315+
'(("content-type" "true")))
290316

291317
(defun cider-tooling-eval (input callback &optional ns connection)
292318
"Send the request INPUT to CONNECTION and register the CALLBACK.
@@ -585,10 +611,13 @@ The result entries are relative to the classpath."
585611

586612
(defun cider-sync-request:format-edn (edn right-margin)
587613
"Perform \"format-edn\" op with EDN and RIGHT-MARGIN."
588-
(let* ((response (thread-first `("op" "format-edn"
589-
"edn" ,edn)
590-
(append (cider--nrepl-pprint-request-plist right-margin))
591-
(cider-nrepl-send-sync-request)))
614+
(let* ((request (thread-last
615+
(map-merge 'list
616+
`(("op" "format-edn")
617+
("edn" ,edn))
618+
(cider--nrepl-print-request-map right-margin))
619+
(seq-mapcat #'identity)))
620+
(response (cider-nrepl-send-sync-request request))
592621
(err (nrepl-dict-get response "err")))
593622
(when err
594623
;; err will be a stacktrace with a first line that looks like:

cider-debug.el

+17-18
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@
2525

2626
;;; Code:
2727

28-
(require 'nrepl-dict)
29-
(require 'nrepl-client) ; `nrepl--mark-id-completed'
30-
(require 'cider-eval)
28+
(require 'map)
29+
(require 'seq)
30+
(require 'subr-x)
31+
32+
(require 'spinner)
33+
34+
(require 'cider-browse-ns)
3135
(require 'cider-client)
32-
(require 'cider-util)
36+
(require 'cider-eval)
3337
(require 'cider-inspector)
34-
(require 'cider-browse-ns)
38+
(require 'cider-util)
3539
(require 'cider-common)
36-
(require 'subr-x)
3740
(require 'cider-compat)
38-
(require 'seq)
39-
(require 'spinner)
41+
(require 'nrepl-client) ; `nrepl--mark-id-completed'
42+
(require 'nrepl-dict)
4043

4144

4245
;;; Customization
@@ -103,13 +106,7 @@ configure `cider-debug-prompt' instead."
103106

104107
(make-obsolete 'cider-debug-print-length 'cider-debug-print-options "0.20")
105108
(make-obsolete 'cider-debug-print-level 'cider-debug-print-options "0.20")
106-
107-
(defcustom cider-debug-print-options '(dict "length" 10 "level" 10)
108-
"The print options for values displayed by the debugger.
109-
This variable must be set before starting the repl connection."
110-
:type 'listp
111-
:group 'cider-stacktrace
112-
:package-version '(cider . "0.20.0"))
109+
(make-obsolete-variable 'cider-debug-print-options 'cider-print-options "0.21")
113110

114111

115112
;;; Implementation
@@ -156,9 +153,11 @@ This variable must be set before starting the repl connection."
156153
(defun cider--debug-init-connection ()
157154
"Initialize a connection with the cider.debug middleware."
158155
(cider-nrepl-send-request
159-
(nconc '("op" "init-debugger")
160-
(when cider-debug-print-options
161-
`("print-options" ,cider-debug-print-options)))
156+
(thread-last
157+
(map-merge 'list
158+
'(("op" "init-debugger"))
159+
(cider--nrepl-print-request-map fill-column))
160+
(seq-mapcat #'identity))
162161
#'cider--debug-response-handler))
163162

164163

0 commit comments

Comments
 (0)