6

I encounter this issue when i set whitespace-style to (face tabs trailing tab-mark) and turn on whitespace-mode.

When whitespace-mode is turned off, everything looks well:

before-turn-on-whitespace-mode

When whitespace-mode is turned on, it seems as if a tab mark » are actually inserted before tab char and the indentation looks strange:

after-turn-on-whitespace-mode

Is this a bug of whitespace-mode? How can i solve it?

2 Answers 2

4

This is a known problem as made evident in a comment in whitespace.el:

(defcustom whitespace-display-mappings
  '(
    (space-mark   ?\     [?\u00B7]     [?.])        ; space - centered dot
    (space-mark   ?\xA0  [?\u00A4]     [?_])        ; hard space - currency
    ;; NEWLINE is displayed using the face `whitespace-newline'
    (newline-mark ?\n    [?$ ?\n])          ; eol - dollar sign
    ;; (newline-mark ?\n    [?\u21B5 ?\n] [?$ ?\n]) ; eol - downwards arrow
    ;; (newline-mark ?\n    [?\u00B6 ?\n] [?$ ?\n]) ; eol - pilcrow
    ;; (newline-mark ?\n    [?\u00AF ?\n]  [?$ ?\n])    ; eol - overscore
    ;; (newline-mark ?\n    [?\u00AC ?\n]  [?$ ?\n])    ; eol - negation
    ;; (newline-mark ?\n    [?\u00B0 ?\n]  [?$ ?\n])    ; eol - degrees
    ;;
    ;; WARNING: the mapping below has a problem.
    ;; When a TAB occupies exactly one column, it will display the
    ;; character ?\xBB at that column followed by a TAB which goes to
    ;; the next TAB column.
    ;; If this is a problem for you, please, comment the line below.
    (tab-mark     ?\t    [?\u00BB ?\t] [?\\ ?\t])   ; tab - left quote mark
    )
  ...)

Considering that a display mapping introduces an extra preceding character, I don't see any way of solving this with whitespace-mode's current mode of operation. Try using the described workaround instead.

3
  • Got it. BTW, Is there any other method to indicate a tab character visually except by whitespace-mode or by tab background highlighting(such as highlight-chars)?
    – littleqz
    May 19, 2016 at 10:46
  • Well, you could always write your own package displaying things differently. For instance a composition (think prettify-symbols-mode) or overlay (with a display property set to a string as wide as the tab) approach could be interesting.
    – wasamasa
    May 19, 2016 at 16:48
  • Ok, I will try to write such a package although i don't know much about overlays. It seems to be very interesting. Thank you Wasamasa!
    – littleqz
    May 19, 2016 at 22:30
1

The whitespace4r.el fixes this problem:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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