3

"Edit, Line, Reindent" doesn't work for HAML. Is there a command that will auto-format HAML? Any ideas? thanks

fuskie
  • 85
  • 6
  • Does this post answer your question? http://stackoverflow.com/questions/9495007/indenting-code-in-sublime-text-2 – MarkoHiel May 02 '13 at 21:42

1 Answers1

1

Automatically re-indenting HAML is not possible, because the amount of spaces in front determines where the element is nested or should come after the previous element.

Consider the following case:

.table
      .row

When you re-indent it might to

.table
.row

while want you want is

.table
  .row

In the above example I used meaningful names and we might be able to understand that row is a child of table but the editor does not.

Even if we did somehow did teach the editor that rows are always part of a table, it doesn't mean that is always the case.

The following example shows you why

.table
  .row
     .table
        .row
                  .row Which table has two rows?

Afterall both

.table
  .row
    .table
      .row
      .row

and

.table
  .row
    .table
      .row
  .row

are valid solutions. The first option has the inner table have two rows, while the second option is that outer table has two rows.

tl;dr-version: There is no auto-indent function for HAML in Sublime Text and there will most likely never be one as it is almost impossible to determine what the HAML-author means.

DevWouter
  • 125
  • 6