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
46.84k stars 2.68k forks source link

Tab key width vs Tab character width #14080

Open DarkArc opened 2 months ago

DarkArc commented 2 months ago

Check for existing issues

Describe the feature

I'm working in a code base where tabs are 8 spaces and should be rendered as such. However, the typical indent within a block scope is 2 spaces.

It would be nice if there was a separate setting for the width of a tab character and how many spaces are typed when the tab key is pressed.

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

No response

notpeter commented 1 month ago

Is this something that would be handled by the tab_size configuration option? This can set this globally and/or override on a per language basis.

Or are you asking for the ability take an 8space indentation in a file and only display it as the visual width of 2spaces?

DarkArc commented 1 month ago

@notpeter no, the tab_size doesn't affect the rendered width. Even with:

      "hard_tabs": true,
      "tab_size": 8,

Code that should look like this:

        int     hi;     /* Comment about hi
                           that continues. */

Looks like this:

  int     hi;     /* Comment about hi
         that continues. */

Additionally in this code base, sometimes you want 8-spaces, sometimes you want a tab that's 8-spaces wide. So, I need both "hard" and "soft" tabs. Meanwhile, most of the indentation is 2 spaces.

Basically, global variables are set up using tabs in older files, spaces in newer files, and things like indentation inside of blocks are always set up using 2 spaces.

Here's some "sample" code:

int             var_a;  /* Comment about var_a
                           that continues. */

int     var_b;
            /* Comment about var_b. */

enum x : int {
  A,
  B,
  C
};

int foo() {
  int c = var_a;
  if (c == 10) {
    return var_b;
  }
  return c;
}

In Emacs I currently use: <tab> = auto indent <C-tab> = insert 8 spaces <C-q C-i> = insert a tab character