Subject: bug#1495: emacs -nw inserts unwanted chars if user is impatient

From: Chong Yidong <[email-masked]>
Date: Thu, 04 Dec 2008 23:10:35 -0500

Dan Nicolaescu <[email-masked]> writes:

> I'm fairly confident this is due to the code in xterm.el that deals
> with modifyOtherKeys, the input probably comes while emacs is waiting
> from an answer from xterm.

This indeed seems to be the problem.

Discard pending input before doing the terminal query seems to fix the
bug for me.  I don't know if it's possible for the user's input to come
inat exactly at the correct moment to fool the terminal query; if so, a
more complicated solution might be required.

Thoughts?

*** trunk/lisp/term/xterm.el.~1.59.~	2008-09-30 20:01:30.000000000 -0400
--- trunk/lisp/term/xterm.el	2008-12-04 23:07:47.000000000 -0500
***************
*** 475,480 ****
--- 475,481 ----
  	  (str nil))
        ;; Try to find out the type of terminal by sending a "Secondary
        ;; Device Attributes (DA)" query.
+       (discard-input)
        (send-string-to-terminal "\e[>0c")
  
        ;; The reply should be of the form: \e [ > NUMBER1 ; NUMBER2 ; NUMBER3 c