dm3/clojure.java-time

docstrings of java-time.api contain literal \n

Opened this issue · 3 comments

The docstrings in java-time.api contain literal \n instead of newlines, which makes them hard to read in code. Cursive does not display them nicely either, but shows the documentation with the literal \n.

I looked at

(defn print-form [form]
(with-bindings
(cond-> {#'*print-meta* true
#'*print-length* nil
#'*print-level* nil}
(resolve '*print-namespace-maps*)
(assoc (resolve '*print-namespace-maps*) false))
(cond
(string? form) (println form)
:else (println (pr-str (walk/postwalk
(fn [v]
(if (meta v)
(if (symbol? v)
(vary-meta v #(not-empty
(cond-> (sorted-map)
(some? (:tag %)) (assoc :tag (:tag %))
(some? (:doc %)) (assoc :doc (:doc %))
((some-fn true? string?) (:deprecated %)) (assoc :deprecated (:deprecated %))
(string? (:superseded-by %)) (assoc :superseded-by (:superseded-by %))
(string? (:supercedes %)) (assoc :supercedes (:supercedes %))
(some? (:arglists %)) (assoc :arglists (list 'quote (doall (map normalize-argv (:arglists %))))))))
(with-meta v nil))
v))
form)))))
nil)
and after some experimentation on the REPL I believe this might work:

(deftype DocString [value])

(defmethod print-method DocString
 [^DocString this ^Writer w]
 (.write w (str "\"" (.-value this) "\"")))

With this, the following code (modelled after java-time.dev.gen/print-form):

(with-bindings {#'*print-meta* true}
 (println (pr-str (with-meta {:value "X"} {:doc (DocString. "multi\nline\nstring")}))))

prints:

^{:doc "multi
line
string"} {:value "X"}

Could you submit a PR we can collaborate on please?

Could you submit a PR we can collaborate on please?

#113