-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add indent_method property for nontrivial indentation methods #38
base: master
Are you sure you want to change the base?
Conversation
Both As I wrote in editorconfig/editorconfig#323 (comment), there is already a property named As the property value For example something like that. * - ``align_style``
- Set to ``space`` or ``tab`` or ``elastic_tab`` to use a simple spaces or simple tabs or one elastic
tabstops respectively (when supported). The tabstop value is defined by align_size and may override the ``indent_style``
or ``indent_size`` settings as required.
* - ``align_size``
- Set to a whole number defining the number of columns used for each align level. If `align_style` equals `tabs` it should be a multiple of `tab_width`. If `align_style` equals `elastic_tabs` only one tab is used but the editor can stretch it up to that size. If it is set to `smart` the editor can use some heuristics to find the best width. The values are case insensitive. With that:
Even with that some case remains:
|
Thanks for your comment. I proposed the property with the The proposal is also based on jedmaos comments (editorconfig/editorconfig#323 (comment)) where we got a common ground that any alignment might affect (ignore) any indentation settings. I considered introducing some extra property as you describe here - i guess there won't be that many different alignment/indentation strategies justifying the complexity of adding two properties. It is - in my opinion - unlikely that any of these "complex" indentation mechanisms are universally described and implemented by "simple" text editors. So this is anyways a setting for developers of an IDE (alike) or a plugin, so i guess everything they need to know is which strategy to apply. If this assumption is true, our I don't see it as our business to actually specify how smart_tabs or whatsoever should work - that's why i would appreciate to create a small description which "just" holds enough information to get a clue what this setting might lead to. In any case we would have to reference to a further external resource for more information. Using a slightly more general approach would allow us to add support for future indentation methods more easily. |
I agree with @florianb that we should keep the tone of the discussion civil. That said, I like @Naheulf's approach of separating indentation and alignment into two separate properties. I'm 👍 for I have two open questions:
It seems that configuration files do not contain the version number of the specification, so editors have to decide on a per-property level whether they support the current specification or not. This seems a bit sloppy, unless you plan to introduce new properties every time you want to add values to existing properties. I'm not a fan of this approach. |
Good points @cowwoc - thank you. I took the opportunity to do a little non-representative research on how often f.e. elastic tabstop support was requested. I got the following impression:
My whole point is about being able to add future alignment/indentation configs when the requirement arrives. So to answer your second question: the editorconfig plugins shall ignore unrecognized keys and values. Outdated plugins will still use the indent-settings as defined. There is a version number for the specification and implementing tools may reference to a specification-version. Also one additional thought about the indentation vs alignment debate: i have still no substantial reason to call it |
Sorry for my language. I edited my previous message to make it less hard. The
In this example both
I didn't think about that in my previous message. |
Dear @Naheulf - thank you very much for your apology, I have adjusted my answer as well. Thank you also for the additional information - i get it now i guess (i sometimes need a bit). Based on the recent "research" about the smart tabs capability i am thinking that the applied functionality falls into two categories:
In this example the tab width is 7. Then there is
I haven't tested this personally but the VS docs state on the indentation setting:
This reads like the alignment is calculated. I hope this behavior makes a specification of a dedicated |
I have personally never seen anyone use tabs for alignment. Have you? Every IDE I've seen defines "smart tabs" as "tabs for indentation, spaces for alignment" because alignment requires 1-character granularity and tabs don't provide that. |
Not sure how this adds to the discussion but i have seen tabs being used for indentation as well as for alignment. And there are editors and tool supporting this (f.e. ReSharper). I have no clue how many people use this and i don't feel obligated to fight for tabs for alignment. All i say is that how things are getting aligned is a function known to the implementors of editors and plugins, and they calculate the number of spaces and whatsoever on their own - and i say that even for a label as widely spread as "smart tabs" there are different implementations of what it will do. |
Fair enough. |
Another approach we can consider is creating hierarchical properties for each kind of formatting style. I'm going to use dummy property names so please gloss over that details:
or
or
or
This way we don't have to break our heads trying to come up with properties that would extend to future approaches. Only Again, the actual property names/values could be changed but the basic idea is that each mechanism would get its own unique properties without having to worry about other mechanisms. |
Okay both of you are having concerns about a missing align_size property. Do you have a specific problem for which you need the align_size property at once? |
The only use-case that is driving me is "smart_tabs". From my perspective I don't really
|
I see - there is already a indent_size and a tab_width setting so i just feel like i shouldn't light hearted run for a third size property. There are thoughts going into that direction (f.e. see editorconfig/editorconfig#482) and i expect the whole standard to evolve more or less soon. |
I want to cast my vote to the To be honest, I don't see many use cases for anything other than |
I'd also like to use My personal style, which I'd like to be supported some day®, is to indent with tabs (it's the next best thing due to a missing native indentation glyph in ASCII), align with spaces, and by default I align with a single space (which is not standard "Smart Tabs", which considers the content of the previous line to align to a variable amount of spaces), but maybe more when it's more aesthetically meaningful. class Demo:
▶️"""
▶️Demonstrate smart tabs indentation with single space continuation lines
▶️"""
▶️def __init__(
▶️ x, # single space continuation line alignment
▶️ y,
▶️):
▶️▶️self.data = some_function(
▶️▶️ c=(
▶️▶️ 1, # aesthetic alignment with the one below
▶️▶️ + 1,
▶️▶️ ),
▶️▶️ d={
▶️▶️ "e": "f": {
▶️▶️ "g": "h",
▶️▶️ },
▶️▶️ },
▶️▶️ i=[
▶️▶️ [ 1, 2, 3],
▶️▶️ [-4, -5, -6], # numbers aligned too for more clarity
▶️▶️ ],
▶️▶️) class Demo {
private: # Some people happen to indent this (and goto labels) relative to the parent scope, not the current scope... and I align them
▶️int a;
▶️int b;
public:
▶️Demo()
▶️ : a(1)
▶️ , b(2)
▶️{
▶️ here:
▶️▶️if (false) {
▶️▶️▶️goto here;
▶️▶️}
▶️▶️
▶️▶️switch(a): {
▶️▶️ case 1:
▶️▶️▶️b = 3;
▶️▶️▶️break;
▶️▶️}
▶️}
}; So a config something like:
I'm not a huge fan of "semantic" alignment to the end of a function name, as it shifts lines when a function name changes. The "evil" effect of tabs on alignment of right-side comments when tab size varies doesn't bother me, the amount of code that is commented causing this (ie. right-side-commented across indentation levels), is pretty minimal. I don't use it, but Elastic Tabs is also more an alignment method than an indentation method, with a tab having a varying width determined after an analysis of the surrounding text. |
I personally agree that |
Hey @xuhdev - i'd like to get this PR done.. :) I am not sure i understand your comment right, you vote for staying with After that i try to figure out if we need a more detailed description to also reference the implications on former settings (like indent_style). I am really thankful for everyone participating in this discussion 🙏 - i think we should make this feature available and we should primarily check if we block any future extension of the spec with this approach (which we are - in my opinion - not doing). I still recommend stay with "intend" as the prefix since people will/might connect this to the handling of invisibles at the beginning of the line, and since this might have impact on other indent-settings it seems to be a good idea to make that clear with the setting-name as well. |
This PR aims to solve the requirement of editorconfig/editorconfig#323 to add support for `smart_tabs`. I propose to add a generic `indent_method` property to be able to 1. add support for non-trivial indentation methods 2. allow a backward compatible definition of indentation methods. Therefore the `indent_method` may override indent size and style if required. I added two common (?) methods for the beginning: `smart_tabs` and `elastic_tabs`, the list may grow in the future. I would prefer to also explain what `smart_tabs` and `elastic_tabs` refer to, for this it would be necessary to write a small explanation to avoid the risk any referenced website goes down. What do you think?
bd80dc2
to
137262f
Compare
At the risk of sounding pedantic... indentation and alignment serve different purposes and are not interchangeable so this shouldn't be a coin toss kind of decision:
Key Differences
A striking example is that it is possible to indent with tabs and align with spaces (which is ensuring that specific characters line up vertically in a column, regardless of how wide a tab is set to display, and allows for different individual preferences on tab width, which IMHO is quite flexible and respectful) and if it's not supported, it kind of means something's not right in the design. |
This PR aims to solve the requirement of editorconfig/editorconfig#323 to add support for
smart_tabs
.I propose to add a generic
indent_method
property to be able toindent_method
may override indent size and style if required.I added two common (?) methods for the beginning:
smart_tabs
andelastic_tabstops
, the list may grow in the future.I would prefer to also explain what
smart_tabs
andelastic_tabstops
refer to, for this it would be necessary to write a small explanation to avoid the risk any referenced website goes down.What do you think?
edit: renamed elastic_tabs to elastic_tabstops