Skip to content

Commit

Permalink
allow evaluation contexts to opt out of pr-values printing of :value …
Browse files Browse the repository at this point in the history
…slots by setting :printed-value
  • Loading branch information
cemerick committed Mar 26, 2015
1 parent 3e06bf7 commit 3875c6e
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/main/clojure/clojure/tools/nrepl/middleware/pr_values.clj
Expand Up @@ -11,22 +11,31 @@
delegating all actual message handling to the provided handler.
Requires that results of eval operations are sent in messages in a
:value slot."
:value slot.
If :value is already a string, and a sent message's :printed-value
slot contains any truthy value, then :value will not be re-printed.
This allows evaluation contexts to produce printed results in :value
if they so choose, and opt out of the printing here."
[h]
(fn [{:keys [op ^Transport transport] :as msg}]
(h (assoc msg :transport (reify Transport
(recv [this] (.recv transport))
(recv [this timeout] (.recv transport timeout))
(send [this resp]
(.send transport
(if-let [[_ v] (find resp :value)]
(let [repr (java.io.StringWriter.)]
(assoc resp :value (do (if *print-dup*
(print-dup v repr)
(print-method v repr))
(str repr))))
resp))
this))))))
(h (assoc msg
:transport (reify Transport
(recv [this] (.recv transport))
(recv [this timeout] (.recv transport timeout))
(send [this {:keys [printed-value value] :as resp}]
(.send transport
(if (and printed-value (string? value))
(dissoc resp :printed-value)
(if-let [[_ v] (find resp :value)]
(assoc resp
:value (let [repl (java.io.StringWriter.)]
(if *print-dup*
(print-dup v repr)
(print-method v repr))
(str repr)))
resp)))
this))))))

(set-descriptor! #'pr-values
{:requires #{}
Expand Down

0 comments on commit 3875c6e

Please sign in to comment.