Skip to content

Evaluating a value with custom print has weird behavior #3741

Open
@Macroz

Description

@Macroz

Hey,

I've been trying to add custom printing to my user type in ClojureScript. Evaluating a value with custom print has weird behavior, when done inside CIDER + Shadow-CLJS. If I run a plain Shadow-CLJS REPL then it just works. Also I've heard that a plain REPL also works. Therefore, I think my problem has something to do with CIDER, in how it "prints a value".

It would also help me, if you can confirm or deny the problem in a plain CLJS project with Shadow-CLJS, with "jacked-in" CIDER. Perhaps it is my user error.

See also discussion https://clojurians.slack.com/archives/C0617A8PQ/p1725863915225369

Expected behavior

A custom IPrintWithWriter (standard CLJS) can be defined for a type and the custom printed value is used by CIDER when showing a value without problem.

You should see in the following example this should print.

Actual behavior

It seems like the printing is cut at the first space since CIDER only shows this. Also special characters # and [] seem to be acting weird. Perhaps there is some kind of an encoding problem or missing escaping somewhere.

Steps to reproduce the problem

Define the type (in e.g., REPL)

(deftype TestType []
  IPrintWithWriter
  (-pr-writer [this writer _]
    (-write writer "this should print")))

Then evaluate to return a value of it:

> (TestType.)
this

NB. This works:

> (pr-str (TestType.))
"this should print"

Environment & Version information

CIDER version information

Tested with two nREPL versions.

CIDER 1.15.1 (Cogne), nREPL 1.3.0
Clojure 1.11.1, Java 17.0.12

CIDER 1.15.1 (Cogne), nREPL 1.2.0
Clojure 1.11.1, Java 17.0.12

Lein / Clojure CLI version

Leiningen 2.9.8 on Java 17.0.12 OpenJDK 64-Bit Server VM

Emacs version

GNU Emacs 28.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38, cairo version 1.16.0) of 2024-06-25, modified by Debian

Operating system

Linux beta 6.1.0-25-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.106-3 (2024-08-26) x86_64 GNU/Linux

JDK distribution

openjdk version "17.0.12" 2024-07-16
OpenJDK Runtime Environment (build 17.0.12+7-Debian-2deb12u1)
OpenJDK 64-Bit Server VM (build 17.0.12+7-Debian-2deb12u1, mixed mode, sharing)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions