zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
49.6k stars 3.04k forks source link

Differentiate between tabs (tab stops) and offsets (indents) #4761

Open davem1972 opened 1 year ago

davem1972 commented 1 year ago

Check for existing issues

Describe the feature

Some editors, (not all!) differentiate between tabs (i.e. tab stops), which simply bumps the cursor to the next tab column and indents/offsets for program statements. For example in Emacs, you can set up tab-width: 8 and c-basic-offset: 3 which means that a tab bumps you to the next column on multiple of 8's (tab stop) but the indent for a if () { ... statement in C would be 3 spaces, not another tab:

    if (foo > bar) {
       printf("foo wins\n");
    } else {
       if (baz > bar) {
          printf("baz wins\n"); // comment is tabbed
       }
    }

Note that the 1st column starts with a tab character, but the indents are 3 spaces. The // comment is tabbed over.

The editors that support this distinction between a tab stop and an indent that I know of are Visual Studio (not VSCode), Emacs, vi/vim, BBEdit. The editors "smart indenting" usually knows the difference between an statement offset indent and an actual tab (although sometimes in Emacs it's necessary to use C-q TAB to get a tab when it wants to indent).

The use-case here is a somewhat large, but "mature" code-base that uses tabs and offsets differently.

If applicable, add mockups / screenshots to help present your vision of the feature

No response

davem1972 commented 1 year ago

FWIW, this is the PR incl. discussion for VSCode to support this feature:

With this PR, you can use the following settings to achieve TAB-8 and 3-offset/indent:

{
  "editor.indentSize": 3,
  "editor.insertSpaces": false,
  "editor.tabSize": 8
}