Skip to content

docstrings of java-time.api contain literal \n #111

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

Closed
devurandom opened this issue May 31, 2024 · 3 comments · Fixed by #113
Closed

docstrings of java-time.api contain literal \n #111

devurandom opened this issue May 31, 2024 · 3 comments · Fixed by #113

Comments

@devurandom
Copy link
Contributor

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.

@devurandom
Copy link
Contributor Author

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"}

@frenchy64
Copy link
Collaborator

frenchy64 commented Aug 1, 2024

Could you submit a PR we can collaborate on please?

devurandom added a commit to devurandom/clojure.java-time that referenced this issue Aug 2, 2024
devurandom added a commit to devurandom/clojure.java-time that referenced this issue Aug 2, 2024
@devurandom
Copy link
Contributor Author

Could you submit a PR we can collaborate on please?

#113

devurandom added a commit to devurandom/clojure.java-time that referenced this issue Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants