1

Launch Emacs with emacs -Q, insert a line contains only a \t (| represents the cursor):

\t|

M-x whitespace-mode, it should looks like (_ represents visual space):

»________$

Insert 2 spaces at the beginning of the line, it should now looks like:

··»______$

But what i want is:

··»________$

I'm a little confused why Emacs doesn't display the \t and 2 spaces before separately. Is the before 2 spaces really inserted? Can anyone help me?

Edit:

I encounter this problem when using whitespace-mode to show tab mark. The details can be found here.

2

1 Answer 1

2

Tabs are not displayed as a fixed amount of spaces but as whitespace stretching up to the next tab stop. The elisp manual says:

The tab character (character code 9) displays as whitespace stretching up to the next tab stop column. *Note (emacs)Text Display::. The variable ‘tab-width’ controls the number of spaces per tab stop (see below).

C-h vtab-width says (emphasis mine):

...

Documentation: Distance between tab stops (for display of tab characters), in columns. NOTE: This controls the display width of a TAB character, and not the size of an indentation step. This should be an integer greater than zero.

1
  • Therefore, spaces should come after tabs.
    – nispio
    Commented May 17, 2016 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.