Skip to content

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

Closed

Description

@devurandom

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.

Activity

  1. devurandom commented on Jun 12, 2024

    @devurandom
    ContributorAuthor

    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"}
    
  2. frenchy64 commented on Aug 1, 2024

    @frenchy64
    Collaborator

    Could you submit a PR we can collaborate on please?

  3. devurandom commented on Aug 2, 2024

    @devurandom
    ContributorAuthor

    Could you submit a PR we can collaborate on please?

    #113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions