Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Puget doesn't respect overriden clojure.core/print-method for records #43

Closed
Engelberg opened this issue Feb 24, 2019 · 1 comment
Closed
Assignees
Labels

Comments

@Engelberg
Copy link

In several of my libraries, I have created custom print behavior for my data structures. I do this by implementing clojure.core/print-method for that data structure, which takes care of pr/print and then I add a method for clojure.core/pprint.

For example:

(defrecord Not [literal])

(defmethod clojure.core/print-method Not [x writer]
  (binding [*out* writer]
    (print "(! ")
    (pr (:literal x))
    (print ")")))

(. clojure.pprint/simple-dispatch addMethod Not #(clojure.core/print-method % *out*))

With the rise in popularity of puget as the printer of choice for cider, I'm finding it inconvenient that puget ignores my hooks into clojure's printing system, and continues to print records in its own default way.

Would you consider a pull-request that changes visit-record to first check whether print-method is implemented for the record, and when it is, use pr-handler instead?

Is there another good way to handle this?

@greglook greglook self-assigned this Feb 26, 2019
@greglook
Copy link
Owner

One of the original motivations for writing Puget was that Clojure's built-in print-method and kin are subject to global modification. I needed a printer that was canonical and that also meant I needed to ensure it would be fully configurable with a local dispatch function. Later on, this expanded to colorization and the broader use as a REPL pretty-printer. Which is perhaps a long way of saying that deferring to print-method implementations would go against that original design.

Given the above, there's no way to globally change Puget's behavior with respect to your custom types, but you can use its dispatch mechanism to choose a different representation within a specific REPL or project. I'm not an emacs user, so I'm not familiar with how you would wire this up in CIDER, but as an example, whidbey has the notion of escape types which are rendered with print-method instead of Puget's normal formatters. You should be able to configure something similar.

Happy to help with any configuration questions along that route!

@greglook greglook closed this as completed Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants