Subject: bug#13793: 24.3.50; M-x broken in viper and X

From: Frank Fischer <[email-masked]>
Date: Sat, 23 Feb 2013 12:35:01 +0100

Meta bindings do not work if Emacs is started in X and viper is
enabled. To reproduce, type

  emacs -Q
  M-x viper RET
  M-x

the last command M-x shows 'M-x undefined'.

As far as I can tell, the reason is viper's trick with the ESC
key. viper binds (kbd "ESC") to a special command call
`viper-intercept-ESC-key`. The purpose is to make the plain ESC key
usable in terminal mode: viper, being a vi emulator, uses a plain ESC
key to exit insert mode. This special command does the following: If an
ESC event arrives, viper waits for a short period of time for another
event. If no other event arrives, viper assumes that a plain ESC key has
been pressed. Otherwise the the ESC key is interpreted as a prefix of
the second event. Thus, M-x in terminal first calls
`viper-intercept-ESC-key`, this functions waits for the second event,
the 'x', and then calls the binding of 'ESC x'.

In X mode this is not necessary, because the plain ESC key generates the
event 'escape, so it is distinguishable from a prefix ESC. Nevertheless,
the binding of ESC is still active, because viper has to support both, X
and terminal (suppose Emacs is started in server mode, one frame being
X, another being terminal). So in some sense, the trick to make viper
work well in terminal mode now causes a problem in X.

Until Emacs 24.2 this "trick" worked quite well. This changed
recently. I tried to find the changeset that introduced the bug, and I
think it is (I used the git repo)

  commit 11521f1228e447bb68ff7a48a30148b99323c04e
  Author: Stefan Monnier <[email-masked]>
  Date:   Mon Feb 11 14:21:23 2013 -0500

    Clean up read_key_sequence a bit; reread active keymaps after first
    event.

Sorry that I'm not (yet) able to figure out what went wrong exactly, but
I hope this information helps to find a solution.

Best regards,
Frank 

In GNU Emacs 24.3.50.1 (i686-pc-linux-gnu, GTK+ Version 3.4.2)
 of 2013-02-15 on dubnium, modified by Debian
 (emacs-snapshot package, version 2:20130215-1~ppa1~precise1)
Windowing system distributor `The X.Org Foundation', version
11.0.11103000 System Description:	Ubuntu 12.04.2 LTS

Configured using:
 `configure --build i686-linux-gnu --host i686-linux-gnu --prefix=/usr
 --sharedstatedir=/var/lib --libexecdir=/usr/lib --localstatedir=/var
 --infodir=/usr/share/info --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs-snapshot:/etc/emacs:/usr/local/share/emacs/24.3.50/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.3.50/site-lisp:/usr/share/emacs/site-lisp
 --without-compress-info --with-crt-dir=/usr/lib/i386-linux-gnu/
 --with-x=yes --with-x-toolkit=gtk3 --with-imagemagick=yes
 CFLAGS='-DDEBIAN -DSITELOAD_PURESIZE_EXTRA=5000 -g -O2'
 CPPFLAGS='-D_FORTIFY_SOURCE=2' LDFLAGS='-g -Wl,--as-needed
 -znocombreloc''

Important settings:
  value of $LANG: de_DE.UTF-8
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Message

Minor modes in effect:
  mml-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  auto-fill-function: message-do-auto-fill
  transient-mark-mode: t
  abbrev-mode: t

Recent input:
( <right> <right> <right> ) M-q C-c C-c n o <return> 
<up> <up> <up> <up> <up> <up> C-SPC <down> <down> <down> 
<down> <down> <down> C-w <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <down> <down> <down> C-c C-c 
<down> <down> C-c C-c <down> <down> <down> <down> <down> 
<down> <up> C-SPC <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> M-y M-w M-x 
C-g <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up