Subject: Re: bug#21867: 25.0.50; lossage's log doesn't treat characters read by read-char as separate commands

From: Lars Ingebrigtsen <[email-masked]>
Date: Thu, 01 Aug 2019 20:05:29 +0200

Zachary Kanfer <[email-masked]> writes:

> The way that lossage now shows different commands on different lines is
> really useful, but I found a way where it's not treating two different
> things as different commands. To reproduce:
>
> emacs -Q
>
> open the scratch buffer
>
> insert this whole s-expression:
>
> (read-char)
>
> Then, with point at the end of that line, type:
>
> C-x C-e a C-h l
>
> This evaluates the (read-char) sexp which reads the `a` typed, then
> views lossage.
>
> The last lines of lossage are:
>
>  C-x C-e [eval-last-sexp]
>  a C-h l [view-lossage]
>
> Note that the log line calling view-lossage also includes "a", the
> command read by read-char. I would expect the lossage buffer to be
> something like this:
>
>  C-x C-e [eval-last-sexp]
>  a [char read by read-char]
>  C-h l [view-lossage]
>
> This does not happen with read-string; one gets logs like:
>
>  C-x C-e [eval-last-sexp]
>  p [self-insert-command]
>  a [self-insert-command]
>  n [self-insert-command]
>  t [self-insert-command]
>  s [self-insert-command]
>  <return> [exit-minibuffer]
>  C-h l [view-lossage]

(I'm going through old bug reports that have unfortunately not gotten
any responses.)

I'm seeing the same thing in Emacs 27 -- C-x C-e on the `(read-char)'
and then a couple of <down>s:

 C-x C-e		;; eval-last-sexp
 a <down>		;; next-line
 <down>			;; next-line

This is what's returned by `recent-keys':

 24 5
 (nil . eval-last-sexp)
 97 down
 (nil . next-line)
 down
 (nil . next-line)

97 is the ?a.

The reason is that `read-char' does this:

  /* Store these characters into recent_keys, the dribble file if any,
     and the keyboard macro being defined, if any.  */
  record_char (c);
  recorded = true;
  if (! NILP (also_record))
    record_char (also_record);

But...  it's not clear what `read-char' should put into recent_keys
here, which is a not-very-clear structure.  Perhaps (nil . "char read by
read-char") after the char and then adjust `view-lossage'?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no