Indenting with tabs, aligning with spaces

Wishlist feature:

CodeMirror supports a indentWithTabs setting, but it is all-or-nothing; all whitespace from the beginning of the line (up to a remainder) is converted to tabs on indent. However, my favored coding style is neither tabs nor spaces, but rather option number three: Tabs are for indentation. Spaces are for alignment.

CodeMirror already somewhat supports this; you can do this:

#include <iostream>
using namespace std;

int main(int argc, char* argv[]) {
--> for (int i = 1; i <= 100; i++) {
--> --> if      (i % 15 == 0) cout << "Foo Bar" << endl;
--> --> else if (i %  3 == 0) cout << "Foo" << endl;
--> --> else if (i %  5 == 0) cout << "Bar" << endl;
--> --> else                  cout << i << endl;
--> }
}

But it is currently unable to support the following, which is an instance of indentation followed directly by alignment:

enter (s:ss) initNextGroup = Enter s:beginEnter where
--> beginEnter = peek (adj s) initNextGroup

--> peek (t:ts) nextGroup = Peek s t status:peek ts nextGroup' where
--> --> status | t `HashSet.member` pastSeen  = BackEdge
--> -->        | t `HashSet.member` thisGroup = CrossEdge
--> -->        | t `HashSet.member` nextGroup = ForwardEdge
--> -->        | otherwise                    = TreeEdge
--> --> nextGroup' = nextGroup `HashSet.insert` t
--> peek [] nextGroup = enter ss nextGroup

enter [] nextGroup = group nextGroup pastSeen'
--> where pastSeen' = pastSeen `hashUnion` nextGroup

To support this, CodeMirror would require a setting which performs no automatic conversions between spaces and tabs.

There are a number of design considerations that I’m not sure how to answer:

  • Would Shift+Tab be allowed on code with zero leading tabs (only spaces)?
  • When you press Home, would it go to the end of the tabs+spaces, or just the tabs?
  • Similarly, when you press enter, does it copy the tabs+spaces, or just the tabs?
  • If the user did want to convert between tabs and spaces in a region of code (e.g. copy-pasted), how would they?

It’d be nice to survey the decisions made in existing plugins for other software; to be honest, I haven’t used many of them, since I am so used to getting the short end of the stick that in most editors I just disable all automatic formatting outright!

Yes, CodeMirror’s indentation system doesn’t distinguish between indentation and alignment, so it doesn’t support your preferred style.