billymoon / Stylus

Stylus Package for Sublime Text 2 / 3
Other
129 stars 31 forks source link

Support for Sublime's Reindent Command #39

Closed zackkrida closed 10 years ago

zackkrida commented 10 years ago

I'm not quite sure how it works, or if it would even be compatible with stylus, but Sublime has a reindent command that works great with css, scss, sass, and less. The unofficial sublime docs describe it as follows:

reindent Corrects indentation of the selection with regular expressions set in the syntax’s preferences. The base indentation will be that of the line before the first selected line. Sometimes does not work as expected.

It currently works in stylus when using brackets, but it'd be ideal to have it function without. I wonder if it's possible?

Example: indent

billymoon commented 10 years ago

I would love to see a solution for this, but I don't think it is possible. We use indentation to give meaning to the code. Without it, I don't think it is possible to infer that meaning by any other means. Even colons are optional in stylus, making it very hard.

Consider this contrived example...

<color>
    <red>happy</red>
    <green>days</green>
</color>

My stylus styles without indentation...

color red
color red
text-size large
color green
color green

do I mean...

color red
  color red
  text-size large
  color green
  color green

... which compiles as...

color red {
  color: #f00;
  text-size: large;
  color: #008000;
  color: #008000;
}

or did I mean...

color red
  color red
  text-size large
color green
 color green

... which compiles as...

color red {
  color: #f00;
  text-size: large;
}
color green {
  color: #008000;
}

I think that if this problem could be solved in stylus, it could be solved in a sublime text, but I think it is simply not possible.

As a workaround, there could be a generic sublime plugin which simply indents all but the first line of empty line delimited blocks, but that should not be part of the stylus plugin.