rpeshkov / vscode-text-tables

VSCode extension that brings the power of Emacs table editing
MIT License
38 stars 14 forks source link

Keep table indentation level unchanged during formatting #64

Open igordejanovic opened 3 years ago

igordejanovic commented 3 years ago

It would be nice to keep table indentation level unchanged during formatting. I'm using the extension in the context of a language which uses tables which are nested inside other code elements. Currently, Text Tables always reformat table at the first column.

Emacs orgmode keep indentation according to the first row. So the | of the table beginning is anchored and never moves. User can explicitly indent first line to affect indentation of the whole table.

Example:

        | first | second |
  |  blah blah | this is some text |

after reformatting becomes

        | first     | second            |
        | blah blah | this is some text |

I have investigated the code today and the first idea was to keep the indentation level startCol on the table model during parsing and then indent each line by that value during stringifying. Probably navigation commands should be updated to take indentation into account. For example, pressing Tab when in the indent region should jump into the first column of that row. Are there any gotchas I'm not aware of?

BTW, thanks for the extension. It is really helpful.