kkinnear / zprint

Executables, uberjar, and library to beautifully format Clojure and Clojurescript source code and s-expressions.
MIT License
547 stars 46 forks source link

formatting assoc function similar to cursive #320

Closed hjbolide closed 1 month ago

hjbolide commented 1 month ago

Hi everyone,

Does anyone tried and succeeded in configuring zprint to match up the coding style of cursive? especially in the case of assoc function.

Here's the community standard:

(assoc some-map
  :key1 "value1"
  :key2 "value2")

And here's how cursive/intellij does it:

(assoc some-map :key1 "value1"
                :key2 "value2")

Ideally we would like to be able to configure zprint to follow the cursive styling, so we don't have to go through our entire codebase to change all assoc usages.

Most of the styling quirks we have encountered had been addressed easily by applying different :arg options, but I have no clue how to achieve this.

Thank you in advance for any suggestions.

kkinnear commented 1 month ago

Thanks for asking. I have something simple that you can try. I don't know how cursive handles all situations, but this seems to do what you want for the limited set of examples that I have given it. See what it does for you.

zprint.core=> (czprint i320 {:parse-string? true :fn-map {"assoc" [:guided {:guide [:element :element-best :element-pair-*]}]}})
(assoc some-map :key1 "value1"
                :key2 "value2")
nil
zprint.core=> (czprint i320 {:parse-string? true :fn-map {"assoc" [:guided {:guide [:element :element-best :element-pair-*]}]} :width 20})
(assoc some-map
  :key1 "value1"
  :key2 "value2")
nil
zprint.core=> (czprint i320 {:parse-string? true :fn-map {"assoc" [:guided {:guide [:element :element-best :element-pair-*]}]} :width 30})
(assoc some-map :key1 "value1"
                :key2
                  "value2")
nil
zprint.core=> (czprint i320 {:parse-string? true :fn-map {"assoc" [:guided {:guide [:element :element-best :element-pair-*]}]} :width 40})
(assoc some-map :key1 "value1"
                :key2 "value2")

To try this, put this in your options map:

{:fn-map {"assoc" [:guided {:guide [:element :element-best :element-pair-*]}]}}

Let me know how this works in practice.

hjbolide commented 1 month ago

Hi kkinnear,

Your config section works wonders! Thank you very much, last piece in our puzzle found.

Really appreciate your great work on zprint and appreciate your help finding the solution for us.

Best regards, Charles

hjbolide commented 1 month ago

Resolved.

Thanks for asking. I have something simple that you can try. I don't know how cursive handles all situations, but this seems to do what you want for the limited set of examples that I have given it. See what it does for you.

zprint.core=> (czprint i320 {:parse-string? true :fn-map {"assoc" [:guided {:guide [:element :element-best :element-pair-*]}]}})
(assoc some-map :key1 "value1"
                :key2 "value2")
nil
zprint.core=> (czprint i320 {:parse-string? true :fn-map {"assoc" [:guided {:guide [:element :element-best :element-pair-*]}]} :width 20})
(assoc some-map
  :key1 "value1"
  :key2 "value2")
nil
zprint.core=> (czprint i320 {:parse-string? true :fn-map {"assoc" [:guided {:guide [:element :element-best :element-pair-*]}]} :width 30})
(assoc some-map :key1 "value1"
                :key2
                  "value2")
nil
zprint.core=> (czprint i320 {:parse-string? true :fn-map {"assoc" [:guided {:guide [:element :element-best :element-pair-*]}]} :width 40})
(assoc some-map :key1 "value1"
                :key2 "value2")

To try this, put this in your options map:

{:fn-map {"assoc" [:guided {:guide [:element :element-best :element-pair-*]}]}}

Let me know how this works in practice.