Elastic tabstops - a better way to indent and align code
๐ Abstract
The article discusses the concept of "elastic tabstops" as a better way to indent and align code, compared to the traditional use of tabs or spaces. It explains the problems with the current approaches and proposes a solution that redefines how tabs are interpreted by text editors.
๐ Q&A
[01] Intro - the status quo sucks
1. What are the problems with the current approaches of using tabs or spaces for indentation and alignment?
- The use of tabs or spaces for indentation and alignment can be problematic if programmers on a project cannot agree on the number of spaces a tab should represent.
- Even if all programmers use the same number of spaces for tabs, the use of modern proportional fonts can cause text misalignment.
- Neither tabs nor spaces alone can allow different programmers to view the same file with their preferred indentation and column widths without text getting misaligned.
[02] The solution - move tabstops to fit the text between them and align them with matching tabstops on adjacent lines
1. What is the proposed solution to the problems with tabs and spaces?
- The solution is to redefine how tabs are interpreted by the text editor, treating them as delimiters between table cells rather than as a fixed number of characters.
- This "Tab Separated Columns" approach allows the tabstops to move to fit the text between them and align with matching tabstops on adjacent lines, enabling the use of proportional fonts while maintaining proper alignment.
2. How does the "Tab Separated Columns" approach compare to the traditional fixed-width data files and tab-separated value (TSV) files?
- The "Tab Separated Columns" approach is analogous to the advantages of using delimited files over fixed-width data files, such as the ability to use tools like
sed
to substitute strings without affecting alignment, and the ability to use proportional fonts.
[03] Keep it simple, stupid!
1. What is the key principle behind the elastic tabstops mechanism?
- The elastic tabstops mechanism is designed to be as simple as possible, similar to the simplicity of HTML tables, without unnecessary complexity or context-sensitive rules.
- It does not care about the content between tabs, only the alignment of the text.
2. How does the elastic tabstops mechanism compare to attempts to create complicated, context-sensitive solutions for aligning code?
- The author suggests that a better and simpler solution is to avoid the need for complicated, context-sensitive schemes to align code in specific ways, and instead let the elastic tabstops mechanism handle the alignment automatically.
[04] Forwards compatibility
1. How can users prepare for a transition to elastic tabstops in the future?
- If planning to switch to elastic tabstops in the future, the author suggests using tabs with fixed tabstops every 8 characters (or more) across, or allowing co-workers to use tabs with fixed tabstops of whatever size they like as long as no one tries to line up text for anything other than indentation.
- This approach helps mitigate issues with text not aligning correctly in files where tabs were used with elastic tabstops, as the wider the tabstop spacing, the less likely the text is to misalign.
[05] Current implementations
1. What are some of the current implementations of the elastic tabstops mechanism?
- The author has implemented elastic tabstops in various text editors and tools, including Elastic Notepad, Always Aligned VS, Scintilla, and plugins for Gedit, Pluma, Komodo IDE, jEdit, Code Browser, MultiMarkdown Composer 2, Inform 7, Atom, Notepad++, and Textadept.
- The Go programming language's "tabwriter" package also uses the elastic tabstops mechanism.
2. What are some potential future implementations of the elastic tabstops mechanism?
- The author mentions that it would be great if elastic tabstops were an option in Visual Studio or used by a code formatter, as is the case with Google's gofmt.
- The author also has an Eclipse plugin that is currently stalled until a related bug is fixed.
[06] Incorrect implementations
1. What are some examples of incorrect implementations of the elastic tabstops mechanism?
- The author mentions that the "ElasticTabstops" plugin for SublimeText and the ACE browser-based editor are incorrect implementations, as they insert spaces rather than moving tabstops.
[07] See also
1. What other related technology is mentioned in the article?
- The article mentions the "Input" proportional programming font, which the author says works brilliantly with the elastic tabstops mechanism, and suggests that more fonts like this would be welcome.