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

Double tagged literals at map value result in extra line break #344

Open
marksto opened this issue Jan 9, 2025 · 3 comments
Open

Double tagged literals at map value result in extra line break #344

marksto opened this issue Jan 9, 2025 · 3 comments

Comments

@marksto
Copy link

marksto commented Jan 9, 2025

Hi @kkinnear!

The issue I encountered has to do with how Aero-based configuration files are formatted in a certain case.

Here's the minimalistic zprint config I have for this one:

{:width 120
 :style [:justified
         :multi-lhs-hang
         :respect-nl]
 :map   {:indent  0
         :justify {:max-variance 60}
         :comma?  false}}

What I have before running zprint:

{:system/server {:jetty-opts {:port #or [#env PORT 8080]
                              :host #profile {:prod "0.0.0.0"}}}}

What I have after running zprint:

{:system/server
 {:jetty-opts {:port #or [#env PORT 8080]
               :host #profile {:prod "0.0.0.0"}}}}

All is expected and neat.

But, if I add just one extra thing, an Aero tag for the :port value:

{:system/server {:jetty-opts {:port #long #or [#env PORT 8080]
                              :host #profile {:prod "0.0.0.0"}}}}

Then, after running zprint, it quite surprisingly becomes:

{:system/server
 {:jetty-opts
  {:port #long #or [#env PORT 8080]
   :host #profile {:prod "0.0.0.0"}}}}

Which is quite unexpected, I would say, since there is enough space for the :jetty-opts value map to fit on the same line as the key.

I tried out all config options for :tagged-literal, which are few, and none were of help. I also played with all other relevant :map options — still, with no luck.

It seems like these are double tagged literals at map value that result in the extra line break.
I wonder, is there anything that can be done about this?

@kkinnear
Copy link
Owner

kkinnear commented Jan 9, 2025

Hello!

In recently ran into issues with tagged literals, and had to completely reimplement them. From the 1.3.0 CHANGELOG.md:

  * Formatting for tagged-literals was completely reimplemented.
  This corrected many problems (not least that they were ignored
  when they appeared in Clojure data structures formatted by zprint
  as a library) and brought the implementation and configuration
  into line with the rest of zprint. Unfortunately, this also caused
  a change to the interpretation of the `:indent` for tagged-literals.
  Previously, the default was `:indent 0`, which would place the
  literal one space to the right of the `#` if it formatted onto
  the line below the tag.  That same placement remains the default,
  but the configuration to generate that output is now `:indent 1`,
  which is an unfortunate but necessary change.  Issue #318.

I was hoping that this might make your situation work better, and indeed:

(czprint i344 {:parse-string? true :width 120, :style [:justified :multi-lhs-hang :respect-nl], :map {:indent 0, :justify {:max-variance 60}, :comma? false}})
{:system/server {:jetty-opts {:port #or [#env PORT 8080]
                              :host #profile {:prod "0.0.0.0"}}}}

(czprint i344a {:parse-string? true :width 120, :style [:justified :multi-lhs-hang :respect-nl], :map {:indent 0, :justify {:max-variance 60}, :comma? false}})
{:system/server {:jetty-opts {:port #long #or [#env PORT 8080]
                              :host #profile {:prod "0.0.0.0"}}}}

It seems to fix the problem that adding the additional tag seemed to generate. Which is nice (to put it mildly). I have no solution for you until 1.3.0 is out, unfortunately.

I'm currently working on implementing :wrap-multi? true for regular lists and vectors (not just in guides) as came up in Issue #341. Turned into an interesting tangle, where I pulled one string and a bunch of others were tied up with it. I think I'm about finished with the heavy lifting for that (tempting fate here) and after cleaning up and writing tests etc I will then push forward to finish out a few outstanding things for1.3.0, which is way overdue.

@marksto
Copy link
Author

marksto commented Jan 9, 2025

Wow, this is huge for such a subtle thing — thanks for sharing these "behind the scenes"! Should we close this issue then?

@kkinnear
Copy link
Owner

I'll close it when I release 1.3.0. Thanks for asking.

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

No branches or pull requests

2 participants