Skip to content

Pretty-printing expressions yields nil *1, etc. #468

@cemerick

Description

@cemerick

My understanding is that cider implements pretty-printing in the REPL and elsewhere by wrapping the expression to be evaluated in an explicit clojure.pprint/pprint form (e.g. https://github.com/clojure-emacs/cider/blob/master/cider-repl.el#L554). Naturally, this leaves *1 holding nil, something I presume no one likes.

I'd like to suggest two options:

  1. Evaluate an interpolated expression like (let [x %s] (clojure.pprint/pprint x) x), which will leave *1 set properly. cider-repl-handler can then simply not do anything with :value, which will ensure that only one printed representation of the evaluated value is seen, e.g.:
(lambda (buffer value)
  (if (not cider-repl-use-pretty-printing)
    (cider-repl-emit-result buffer value t)))
  1. Alternatively (and perhaps as a more long-term solution), the standard pr-values middleware can be modified to provide a set!-able session-local configuration var so that clients/users can (a) set which function should generate the printed representation of :value, and (b) set which slot in the response message that representation should put in (since certain printed representations are likely not read-able, something that :value strings really should be).

I've tweaked my cider locally to do (1), and it works well. Would you like a patch for that?

Further, thoughts on the utility of (2) are welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions