Set tab width in GUI terminal

rxvtterminalxterm

I found that

setterm -regtabs 4

doesn't work in xterm or urxvt.

But, this

xterm_set_tabs () { 
  TERM=linux;
  export $TERM;
  setterm -regtabs 4
}

will circumvent the problem.

But, I suspect it is suboptimal as (1) I get a gfx bug I can't otherwise explain (at least, if I get the tab stuff right that possibility is ruled out), and (2) when I ssh to my school's Solaris, and run emacs -nw, it says the terminal "linux" is unknown! So then I have to change it back to "xterm". Of course, this is silly as all the while I'm using the same terminal.

Also, perhaps not relying on tabs at all is a good rule of thumb!

Best Answer

The setterm utility is intended for use with the Linux console. According to the console_codes manual page:

The Linux console implements a large subset of the VT102 and ECMA-48/ISO 6429/ANSI X3.64 terminal controls, plus certain private- mode sequences for changing the color palette, character-set mapping, and so on.

Since the program is hard-coded,

/* -regtabs. */
if (ctl->opt_regtabs && vc_only(ctl, "--regtabs")) {
    int i;

    fputs("\033[3g\r", stdout);
    for (i = ctl->opt_rt_len + 1; i <= TABS_MAX; i += ctl->opt_rt_len)
        printf("\033[%dC\033H", ctl->opt_rt_len);
    putchar('\r');
}

it just happens to work with xterm since xterm implements VT100 controls (plus more).

As for large subset, that is debatable. In a quick count of the items in console_codes, I see 79 control sequences. That is far less than any of the xterm look-alikes documented in the xterm FAQ Comparing versions, by counting controls. By itself, 79 is not large. The VT102 itself (not an xterm look-alike) had 104. ISO-6429 (aka ECMA-48) documents 20 modes and 162 sequences. Whether you count the total as 182 or 162, 50% is not a large subset.

Rather than using a Linux console utility, there is a more portable choice: the tabs utility (in POSIX as well as Solaris). It is part of the ncurses utilities (and probably installed on your Linux system).

For the example given in the question, you could do this:

tabs -4

That uses the terminal database, rather than being hard-coded. Tabs and the control sequences to set them are documented in ECMA-48 and other places such as the terminfo(5) manual page.

And tabs works with xterm.

Related Question