2

There seems to be a slight difference in how emacs, with whitespace-mode enabled, displays tabs compared to e.g. terminals: When a tab would lead to only one (visual) space being displayed before the next tab stop, it seems like emacs skips to the next tab stop instead.

This can best be illustrated with an example. In the following text, if there is a single tab character between the last digit and the "t", both emacs and the terminal display the text identically at a tab width of 8:

123456 t xxxxxxxxx 

But if I add just one digit, effectively shrinking the space for the tab to one character, terminals still place the letter "t" as before:

1234567 t xxxxxxxxx 

But emacs "skips" to the next tab stop, and effectively inserts 8+1 spaces for display:

1234567 t xxxxxxxxx 

It's like emacs somehow wants there to always be at least two spaces for every tab stop when displaying.

I particularly notice this issue when editing assembly files, where a tab width of 4 is common, and the frequent mix of 3 character and 4 character assembly instructions really wreaks havoc on the formatting.

Where does this difference come from, and can I change it (buffer-locally)?

11
  • 2
    I can't reproduce this in any Emacs version that I have around, either with emacs -Q or with my configuration, either in a GUI or in a terminal. Please share precise instructions to reproduce this (Emacs version, OS, interface, any steps to take beyond typing in emacs -Q). Commented Apr 8 at 20:13
  • 2
    I'm able to reproduce the issue if I enable whitespace-mode. It's also mentioned in the comments in the definition of whitespace-display-mappings. Can you confirm if you are using it? Commented Apr 9 at 6:01
  • 1
    @matteol: Nice find! That's why it's important to start with emacs -Q as Gilles suggested: the OP could have tested with emacs -Q and emacs -q to verify that the problem does not occur in that case, and then bisected the init file to find the culprit. Commented Apr 9 at 13:13
  • 1
    Please add this information to the question, so I can write an answer that can be useful to other users, comments can be deleted in any moment. Commented Apr 10 at 4:22
  • 1
    Just use the "Edit" link and edit the question text to be more accurate. No Answers have been posted, so you won't be invalidating anything by rewriting the original text, so just rewrite it as if you knew then what you know now. (If there were pre-existing Answers, it would be prudent to also take those into account in some way, so that people reading the Q&A had the context.) Commented Apr 11 at 7:15

1 Answer 1

2

It's a known defect of whitespace-mode, documented in a comment of the variable whitespace-display-mappings. With the default configuration whitespace-mode adds the "»" character to mark the presence of a tab, this moves the tab to the next TAB column when there is only a column left for it. A possible solution is to disable this additional character and rely only on faces.

(with-eval-after-load 'whitespace (setopt whitespace-display-mappings (cl-delete-if (lambda (k) (eq (car k) 'tab-mark)) whitespace-display-mappings))) 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.