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?

littleqz
  • 117
  • 3

2 Answers2

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.

wasamasa
  • 22,178
  • 1
  • 66
  • 99
  • 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 '16 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 '16 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 '16 at 22:30
1

The whitespace4r.el fixes this problem:

enter image description here

gongqj
  • 241
  • 2
  • 6