Subject: bug#46590: 27.1.91; abnormal whitespace-mode behavior

From: Frédéric Baldit <[email-masked]>
Date: Tue, 23 Feb 2021 15:05:47 +0100

Thank you for your message and for pointing out the warning in
whitespace.el code.
Now I can better understand what is triggering this bad display. For
example, the following text yields the same result:
........First line of text in emacs
.......
(eight spaces at beginning of line 1, 7 at beginning of line 2, point
at end of line 2). Then typing TAB inserts 1 TAB symbol (character
'»', \xBB) followed by eight grouped spaces (1 TAB), whereas only one
'»' should be indeed be displayed.

I'm quite surprised by this, because to me it's not so marginal and
unused. Also whitespace.el is now builtin with emacs. And emacs is
such a long-time proven editor, I think it can be quite disappointing to
see such a «flat» (I mean trivial) bug in it.

I just began reading whitespace.el, in particular the use of the
display table, which seems to be crucial here. But I'm just
learning emacs (and emacs lisp), so there could be a long way
before I can truly  (and deeply) understand whitespace.el code and see
how to fix the bug.

I asked myself: should I contact the maintainer of whitespace.el
(Vinicius Jose Latorre) to get some help?

--
  Frédéric Baldit

Le sam. 20 févr. 2021 à 11:27:25 +0200
Eli Zaretskii <[email-masked]> a écrit:

> > Date: Wed, 17 Feb 2021 15:06:14 +0100
> > From: Frédéric Baldit <[email-masked]>
> > 
> > emacs -Q test.txt &
> > 
> > 2) M-x whitespace-mode RET
> > 
> > 3) type the following text («.» for spacebar key):
> > 
> > «....First line of text in emacs», then type RET
> > 
> > 4) DEL DEL to suppress backward two spaces on line 2, then type text
> > «Second one»
> > 
> > 5) M-2 M-b
> > 
> > 6) TAB TAB TAB TAB: point should be at line 2, column 18, vertically
> > aligned with fourth word of line 1 («text»), but it is at column 26:
> > that's the bug.  
> 
> It's a known misfeature of whitespace-mode.  There's a comment in
> whitespace.el to that effect:
> 
>     ;; 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    [?» ?\t] [?\\ ?\t])	; tab - right
> guillemet
> 
> You could customize whitespace-display-mappings to remove tab-mark
> from it, if you want to avoid this issue.
> 
> > Rq1: what is curious (to me) is that deactivating whitespace-mode
> > removes abnormally inserted tab character (8 spaces) and everything
> > is OK.  
> 
> That's because disabling whitespace-mode deactivates the display-table
> mappings, which include the above mapping.
> 
> > Rq2: I noted that with a different text, this behavior of
> > whitespace-mode disappears. For example, if one uses the following
> > first line of text:
> > 
> > «....This.is.a.first.line.of.text.with.a.few.words»,
> > 
> > then the result of typing TAB multiple times is as expected, with or
> > without whitespace-mode activated!  
> 
> Most probably because the "TAB occupies exactly one column" condition
> doesn't happen there.
> 
> Thanks.