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

:community and :rod don't compose well #223

Closed
vemv opened this issue Mar 2, 2022 · 7 comments
Closed

:community and :rod don't compose well #223

vemv opened this issue Mar 2, 2022 · 7 comments

Comments

@vemv
Copy link
Contributor

vemv commented Mar 2, 2022

Hi!

As you surely remember, I requested the ":rod" style, which other people came to appreciate. In fact, at my new job they happened to be using it!

However, it's also used in composition with the :community style, which is when issues arise.

We use lein-zprint, with a :style [:community :rod] Lein setting. While either of those individually work as intended, when composed, they yield a 1-space indentation:

;; one-space indentation!
(defn foo [x]
 (println x "Hello, World!")
 (println x "Hello, World!")
 (println x "Hello, World!"))

Since 1-space indentation is not the intended (or effective) style of either preset, it seems to represent a bug. And of course it's quite an inconvenience, since it will cause quite the discrepancy between editors' formatting and zprint's in this case.

For your consideration.

Cheers - V

@kkinnear
Copy link
Owner

kkinnear commented Mar 3, 2022

Oh yes, I surely remember! I implemented an entirely new subsystem in no small part so that I could implement the :rod style. I've used it for several things since, but your request was the main reason I started down that path.

This is clearly a bug of some kind. I can reproduce it, thanks for the simple example. I'm out of time tonight, but I'll give it a good hard look first thing tomorrow. I'm hopeful that I can find some fix that doesn't require a new release, but rather some configuration tweaking, but I'll know for sure once I figure out the details.

@kkinnear
Copy link
Owner

kkinnear commented Mar 3, 2022

The problem is that some function types are "arg" and some are "body", and the :guided function type is "arg". I need to also create a :guided-body function type. and I will do so in the next release.

However, when using guides, the actual function type is pretty much ignored (except the the arg/body distinction), and so we can replace the :guided function type with one that is considered a body function type, for example, :fn as a temporary expedient to getting your code to format the way that you want it to.

[Note -- you have to be using zprint 1.2.1 or 1.2.2 for the following to work for you. I could change these instructions to work with 1.2.0 if that is what you have to use, so let me know if you need that.]

I can see two, rather similar, ways to do this. One is to just ignore the :rod style and fix defn to have the right stuff. The other is to redefine the :rod style to do this, and continue to use the current styles you are using.

Here is where you just fix the :fn-map for defn directly:

 projects/zprint % ./zprintm-1.2.2 '{:style [:community] :fn-map {"defn" [:fn {:list {:option-fn (partial rodguide {:multi-arity-nl? true})}}]}}'  <cljfiles/i223.clj
(defn foo [x]
  (println x "Hello, World!")
  (println x "Hello, World!")
  (println x "Hello, World!"))

Here is where you redefine the :rod style in the :style-map, and then use it as your normally do:

√ projects/zprint % ./zprintm-1.2.2 '{:style [:community :rod] :style-map {:rod {:fn-map {"defn" [:fn {:list {:option-fn (partial rodguide {:multi-arity-nl? true})}}]}}}}'  <cljfiles/i223.clj
(defn foo [x]
  (println x "Hello, World!")
  (println x "Hello, World!")
  (println x "Hello, World!"))

This makes me glad that I did the work to allow you to define a style and invoke it in the same option map. That didn't just fall out.

Since you are using lein zprint (and I'm glad you mentioned that), it is a bit more complex. You can't put the :style-map definition in the :zprint { ... } key-value pair in your project.clj, since lein zprint doesn't know about guides as yet. I wasn't sure anyone even used lein zprint anymore, since the executables are so much faster and have pretty much the equivalent or more capability.

You can, however, place the :style-map definition of :rod in a .zprint.edn in your project (i.e., in the same directory as your project.clj) and then you can do one of the following:

  • put :search-config? true in every user's ~/.zprintrc file
  • put :search-config? true in your :zprint { ... } key-value pair in your project.clj.

I would recommend the second, as it means that you don't have to have every user mess with their probably non-existent ~/.zprintrc or ~/.zprint.edn files.

So, here is the .zprint.edn file you put in your project:

√ projects/zprint % more .zprint.edn
{:style-map
   {:rod {:fn-map
            {"defn"
               [:fn
                {:list
                   {:option-fn (partial rodguide {:multi-arity-nl? true})}}]}}}}

and you just add :search-config? true to the :zprint key in your project.clj. And you should be in business.

When 1.2.3 comes out, you can remove the .zprint.edn file and remove the :search-config? true from your project.clj, and it should all still work.

Let me know if you have any problems with this.

@vemv
Copy link
Contributor Author

vemv commented Mar 3, 2022

Thanks much!

Sounding great.

For clarity, in the next stable release will [:community :rod] work as intended? It would be great to keep composing two high-level directives.

@kkinnear
Copy link
Owner

kkinnear commented Mar 3, 2022

Yes, in the next stable release, that I expect to be 1.2.3, [:community :rod] will compose correctly.

@kkinnear
Copy link
Owner

This is fixed in 1.2.3. Thanks for noticing it and submitting an issue.

@vemv
Copy link
Contributor Author

vemv commented Apr 12, 2022

Awesome! Most likely I'll be giving it use asap.

Obviously I'll keep an eye open on #229 also - feel free to keep me in the loop.

@vemv vemv closed this as completed Apr 12, 2022
@vemv
Copy link
Contributor Author

vemv commented Apr 15, 2022

Fix works like a charm!

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