-
Notifications
You must be signed in to change notification settings - Fork 119
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
Support for associative syntax allignment #36
Comments
There are. I was also going to add in a configurable "tolerance", so it can be set to align only if the spacing won't exceed a certain value. e.g. (let [x :foo
ab :bar
baz :quz
something-very-long :bang]
…) |
FWIW, my team would advocate for doing the following: (let [x :foo
ab :bar
baz :quz
something-very-long :bang]
…) → (let [x
:foo
ab
:bar
baz
:quz
something-very-long
:bang]
…) Which could be another configuration toggle. |
If this is going to be an option I'd love to have a setting where it removes any such alignment. |
+1 |
I've started work on this and have made some good progress. Not sure yet but this may involve #39 as well. |
+1 |
I'm plugging away at this one (some discussion in #77) but have taken a pause to see if I can update rewrite-cljs to include rewrite-clj support I'd like to use to support my change. Another good use case for alignment I just noticed is the |
Other candidates for align might |
I can take a crack at this one again after an upgrade to rewrite-clj v1. |
Scope of alignmentI would be happy with a simple on/off all or nothing mechanism for aligning. However, there isn't universal agreement on aligning, so a mechanism to specify which things to align seems useful. I assume a similar approach to clj-kondo that you can include or exclude specific patterns (allowing users to add their own in a config file - which would make the change smaller perhaps) Aligning for these functions would be greatlet, let-fn, loop, for, cond, case, condp, require, ... Aligning of hash-map data structure
Long argument alignmentI would be happy aligning long arguments in line with other arguments. Blank lines should break alignment in formUsing Clojure mode
|
Thanks @practicalli-john, I think the blank line boundary idea is pretty clever! |
I spent some time today refreshing my brain on where I was at with this feature. It looks like I got as far as handling maps and binding args. When associative alignment is enabled, all maps are aligned and bindings args for forms with specific rules are also aligned. Cljfmt would include reasonable default alignment rules. So @practicalli-john, this means my current strategy can handle The current rule for For I have yet to think about Just brainstorming, but I expect folks might be interested in aligning a collection of maps as well? [{:a 1234 :b 2 :c 44}
{:a 7 :b 8212 :c 8}] This is a good point to decide what we'd like this feature to do. |
@lread looks good to me! IMO user should be able to choose what forms/macros will use this new feature, for example users that want that on most forms but not on require ones |
Thanks for chiming in @ericdallo!
WIP config currently does NOT include:
|
Yeah! I dig that quite a bit. :) |
Ok, my WIP now includes initial support for tabular alignment of argument subsets, to support forms like Still don't have:
Also thinking of naming for this feature. Is "associative syntax alignment" maybe easier to digest if described as "tabular alignment"? At some point we'll have to pester @weavejester to see if we are on a track that makes sense to him. |
I already saw some people referring to it as "vertical alignment", but your suggestion LGTM as well |
Thanks, much appreciated! I was thinking that regular indentation can also, kind of, be a form of vertical alignment, and that tabular might be more descriptive? |
Reviewing my code it seems alignment for hash-map and binding forms (defn, let and :require in an ns form) would cover 99% of all my coding. Especially if a blank line separated groups of alignments There are lots of other good ideas discussed here. Thanks for working on this. |
When I originally suggested this feature I had mostly associate forms in mind (except for that At the same time 'tabular alignment' or 'vertical alignment' doesn't feel self-documenting to me. Once I know what's being referred to then I feel like I would get why it was named that way. But not knowing what it refers to I think I'd be scratching my head whereas 'associative syntax' at least gives me a clue as to what part of the syntax we're talking about. But I'm obviously biased on that point and I don't have another suggestion. ¯\_(ツ)_/¯ Naming's hard. Let's just go with |
@timvisher yeah, I get what you mean by biases, my wee brain is glued on "tabular" now.
😄 |
@practicalli-john I too think this is a nice convention. I'll underline this one on my todo list. |
Linking my input on how to treat ”groups” from another thread #77 (comment) |
Thanks @PEZ, I'll paste it here for easy referencing:
|
As a reference, an example project that seems to have wholly embraced tabular alignment is re-com. |
I like the newline separation of groups but I don't particularly like the ungrouping between lines of differing numbers of elements. I think if the elements are all in a contiguous series of lines it makes more sense to treat them all as a group. It's interesting in this particular example you've got going that it suggests to me at least that the data structure is wrong. I can't understand why we'd have a single vector of that many elements all with different groupings. I'd want something more like a vector of vectors, and then what would the alignment be?
or
? This all feels a little too clever to me, TBH. Of course I think I'm still stuck on the 'associative' aspect of this. A vector is only potentially associative if its pairs. If it's anything else then it's just a list of tuples. But since we seem to want to extend this to the notion of tabular alignment maybe that makes sense. ¯_(ツ)_/¯ |
@timvisher, thanks for the observation. The newlines separation of groups seems uncontroversial to me as well. For your vector of vector example, is the only differences the placement of While we are on the topic of clever behaviour, while poking around re-com sources, I see things like this: (def alert-box-args-desc
(when include-args-desc?
[{:name :id :required false :type "anything" :description [:span "a unique identifier, usually an integer or string."]}
{:name :alert-type :required false :default :info :type "keyword" :validate-fn alert-type? :description [:span "one of " alert-types-list]}
{:name :heading :required false :type "string | hiccup" :validate-fn string-or-hiccup? :description [:span "displayed as a larger heading. One of " [:code ":heading"] " or " [:code ":body"] " should be provided"]}
{:name :body :required false :type "string | hiccup" :validate-fn string-or-hiccup? :description "displayed within the body of the alert"}
{:name :padding :required false :default "15px" :type "string" :validate-fn string? :description "padding surounding the alert"}
{:name :closeable? :required false :default false :type "boolean" :description [:span "if true, render a close button. " [:code ":on-close"] " should be supplied"]}
{:name :on-close :required false :type ":id -> nil" :validate-fn fn? :description [:span "called when the user clicks the close 'X' button. Passed the " [:code ":id"] " of the alert to close"]}
{:name :class :required false :type "string" :validate-fn string? :description "CSS class names, space separated (applies to the outer container)"}
{:name :style :required false :type "CSS style map" :validate-fn css-style? :description "CSS styles to add or override (applies to the outer container)"}
{:name :attr :required false :type "HTML attr map" :validate-fn html-attr? :description [:span "HTML attributes, like " [:code ":on-mouse-move"] [:br] "No " [:code ":class"] " or " [:code ":style"] "allowed (applies to the outer container)"]}
{:name :parts :required false :type "map" :validate-fn (parts? alert-box-parts) :description "See Parts section below."}
{:name :src :required false :type "map" :validate-fn map? :description [:span "Used in dev builds to assist with debugging. Source code coordinates map containing keys" [:code ":file"] "and" [:code ":line"] ". See 'Debugging'."]}
{:name :debug-as :required false :type "map" :validate-fn map? :description [:span "Used in dev builds to assist with debugging, when one component is used implement another component, and we want the implementation component to masquerade as the original component in debug output, such as component stacks. A map optionally containing keys" [:code ":component"] "and" [:code ":args"] "."]}])) In this vector of maps, the alignment understands that some keyword-value pairs can be missing. Also a note: cljfmt does not currently format comments and neither will tabular indentation. |
I've been asked to share my 2c here, so here we go. In my, admittedly not so humble, opinion, this particular issue #36 is a perfect example of feature creep. It's been created more than 6 years ago. And yet, the discussion about what to include is still ongoing. Now there's even some confusion about the naming - simply because the old "associative syntax alignment" name cannot represent all the features that have crept in. In my, this time even less humble, opinion, these are the things that need to be done to bring it to fruition, at least in some sense. To make it useful for as many users and as early as possible, and not wait till we have a specification and a configuration grammar for all the corner cases that are used by a handful of projects (people behind which might not be interested in cljfmt at all):
|
Good points, @p-himik. Some context about #77:
I agree the scope for it is fine, might need some little tweaking. E.g. separate flags for |
Thanks for chiming in @p-himik! I think you make some good points. One important thing to remember is that this is open source work where contributors are all volunteers with varying amounts of free time, interest and patience. So while it might seem that some team is taking 6 years to deliver a feature, there really has been no focused team working on this. From time to time some person has picked up the torch and taken a stab at it. Perhaps you will be the next person to do so. |
I took a stab at it: #299 Trivial attempt. Comments welcome. |
Are there plans to support associative syntax alignment?
The text was updated successfully, but these errors were encountered: