-
Notifications
You must be signed in to change notification settings - Fork 49
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
Adding Better Clojure Formatting from Tonsky #301
Comments
An interesting question about the Tonsky's Better Clojure Formatting. Near as I can tell, his rules are what I call "indent only" kinds of rules. That is to say that I don't think his rules every cause the addition of another line. In part because there is no concept of "width" in Tonky's rules, so there would never be a reason to move something onto another line. Or, presumably, move something that was on a subsequent line up to a previous line. I don't have any examples of the TCBF (Tonsky's Better Clojure Formatting) applied to complex situations. If I take his simple examples off of the web-page you linked me to above, I can exactly reproduce them with the standard
They really are the same:
Will the zprint I just reviewed zprint's :indent-only documentation, and I noticed that I used mostly the examples from the TBCF page there. I also remember that there was some discussion about aligning things that were already aligned, which zprint does using
If you don't like the way that
I hope that |
Hey, |
Hey, |
Yes, Now, I have an idea of how to get you most of what you want, but first I need to know from you what you want to see justified. I'm guessing that you want to have I presume that you have noticed that justification isn't always chosen as the "best" approach, in that there are plenty of reasons that justification just doesn't look better so it is skipped. There are lots of things you (or I) can tune to make justification happen more frequently, though they don't necessarily make the output actually look all that much better. Anyway, let me know where you particularly want justification, and I'll see what I can do to make that work for you along with something that works mostly like |
Great, what I am interested in is justification of let, map, cond, case. (If it's easy to set it up on all binding then great) The thing is that I support your opinion on this, I also don't find justification very useful in some cases but still If I don't set it up then I will not be able to use my neovim for job related projects because that is one of the rules set by engineers in my company. So basically what I need is TBCF + justification on some bindings. |
I have something for you to try. In order to get justification, this approach does not use First, let me draw a distinction between indenting tools and full-on formatting tools. An indenting tool essentially leaves everything on the line that it originally appeared on, and doesn't add or delete line endings. It attempts to indent everything on each line to its appropriate place on the line. A full-on formatting tool basically ignores all white space, and formats the file based on its internal rules. Why do I make this distinction? Because a full-on formatting tool will produce exactly the same output given any semantically identical input. That is, you can add or delete whitespace and newlines anywhere in the input, and the full-on formatting tool will always produce the same output. An indenting tool will not, of course, because it only adjusts where things are on their own lines. This is not to say that either is better or worse, but they are certainly different. To the best of my knowledge, the TBCF formatting approach is an indenting approach. I do not believe that it says anything about what lines to place things on. Note these examples:
It shows how the TBCF rules will format these lines, but it doesn't say "put the args on the same line as the defn" or "put the args on a line below the defn". Thus, the TBCF rules don't specify exactly what the file is to look like -- it specifies exactly what the indents should look like given whatever file you have. As it happens, classic zprint (not using Now when I configure zprint with
The point here is that your local coding standards probably indicate what lines you should place things on, and probably they don't conflict with what zprint is going to do -- particularly since with So, here is an example of what I cooked up to meet your needs:
The examples show how it works. There is one place where I want to point something out. In
You can also see why (at the suggestion of a user) I implemented the variance based justification. I don't know how this will play with your local standards requiring justification. Let me explain the entire option map I'm using:
First, there are approximately 122 things defined in the Next, in Next, we load the If you want to have other functions with pairs (or bindings) be justified, you can add them to the That's all I can think of right now. I hope that this gets you some of the way toward where you want to go. Let me know if this doesn't work, and I'll see what I can do. I think it is close. Thanks, by the way, for asking. I enjoy trying to figure out how to get zprint to meet people's needs, and this is certainly an interesting challenge. |
Thank you for this detailed explanation, it will help a lot if I need to change anything. If I stumble on some case where it needs tweaking I will let you know. |
Hey Kim, Sorry for the delay in getting back to you. I've made some tweaks to my .zprintrc file, mainly removing commas during formatting as they're considered bad practice in Clojure code. The style closely resembles Tonsky's Better Clojure Formatting (BCF), with just a few minor adjustments needed for proper indentation ( If you think that anything needs to be added to this zprint config please tell me, to me it looks like a close match ). You can find the modified .zprintrc file here: https://github.com/radovanne3/neovim/blob/27e802c50bf66b7f98cbf28c093204f139db201f/.zprintrc Since null-ls isn't maintained anymore, I've adapted my setup to work with none-ls instead. Here's how I've configured it: https://github.com/radovanne3/neovim/blob/27e802c50bf66b7f98cbf28c093204f139db201f/lua/verde/none-ls.lua To avoid conflicts with the default zprint program on Mac, I've renamed your zprint executable to zprintm. Given that the BCF style is, I guess, being used, perhaps it could be nice if you included as one of the predefined styles. This way, it would be easier for everyone to adopt. Because of not being able to use BCF style in neovim before I used Emacs, but now I don't need anymore. Either way, thank you for support! ( Before replying here I replied to one closed issue of mine, that was a mistake. ) |
Hey,
Neovim users usually have a hard time setting up formatting for their needs,
and some of us are not using community standard formatting..
Is it possible to add Better Clojure Formatting from Tonsky as one of the styles that can be applied?
https://tonsky.me/blog/clojurefmt/
Thanks.
The text was updated successfully, but these errors were encountered: