2 ms·
Interesting, I've not seen this discussed before. JOE uses a variation of the GCD method: https://sourceforge.net/p/joe-editor/mercurial/ci/default/tree/joe/b.
by jhallenworld 11y ago
Interesting, I've not seen this discussed before. JOE uses a variation of the GCD method:
https://sourceforge.net/p/joe-editor/mercurial/ci/default/tree/joe/b.c#l2810 https://sourceforge.net/p/joe-editor/mercurial/ci/default/tr...
Create a histogram of the indentation of the last 250 lines of the file (on the theory that there are more comments at the beginning of the file). The GCD of the three most popular indentations is selected. This way one oddly indented line does not screw it up. It does not ignore single space indentations, since I used to use that. Instead it ignores lines which begin with comment characters, like asterisk or '/'. It can still be confused by block comments like this:
/* first
second
third */
The editor does in theory know the syntax, so it could be enhanced to just ignore comment lines.
Also, it determines if the user prefers to use tabs or spaces for indentation.
- alextgordon 11y agoIn Chocolat we take a similar approach, but the histogram is of the GCDs, not of the indentations. So we just take a sample of 1000 lines, then take the GCD of every pair. The indentation width is simply the most common pair. If it turns out that one bin is not clearly more dominant than the others, then we default to whatever was used last time for that language.