Subject: bug#31692: Emacs sometimes drops key events

From: Radon Rosborough <[email-masked]>
Date: Sat, 2 Jun 2018 20:21:32 -0600

For the past year or two, my Emacs has occasionally had fits where it
drops some of my key events. The symptom is that I type something like
"radian" and I get "rdian".

This happens more often when things are laggy in general, but also
happens at other times. Usually, my Emacs will get into a state where
it'll do it a lot, at least for a little while, but I can't reliably
reproduce that state.

I noticed that whenever a key is dropped, the text "Quit" is logged in
the *Messages* buffer. However, `keyboard-quit' doesn't get called; I
checked by adding an advice. Something in the C code causes a quit
event to be signaled and also aborts the processing of my key event,
apparently.

I have confirmed that the problem still happens when none of Flycheck,
Company, ElDoc are active. So it's not any of those. I haven't managed
to reproduce the problem when Aggressive Indent is disabled, but that
doesn't necessarily mean that Aggressive Indent is the problem. It
could just be that Aggressive Indent makes my Emacs much slower, and
so the bug is more likely to be observed.

Typically, the dropped key does not even show up in the lossage (C-h
l). However, one time I did notice this curious phenomenon:

     r [self-insert-command]
     a d [self-insert-command]
     i [self-insert-command]
     a [self-insert-command]
     n [self-insert-command]

Where I typed "radian" but what was inserted was "rdian". The
corresponding excerpt of the vector returned by `recent-keys' was:

     114
     (nil . self-insert-command)
     97 100
     (nil . self-insert-command)
     105
     (nil . self-insert-command)
     97
     (nil . self-insert-command)
     110
     (nil . self-insert-command)

In the terminal, I've noticed things like the letters A-D getting
inserted when I use the arrow keys. I presume that this is because one
of the events in the escape sequence is eaten by this bug, and the
rest of it gets misinterpreted.

I have no idea how to go about debugging this, and unfortunately I
don't know how to reliably reproduce the problem. But it's been with
me a long time and it doesn't look like it's going away on its own.
Can someone give me pointers on how to work towards a solution?

Environment information:
  Emacs - 26.1, Homebrew, --with-cocoa --with-modules
  OS - macOS, 10.11.6
  Configuration - https://github.com/raxod502/radian

Thanks,
Radon