Subject: bug#1072: Viper version is 3.14 of April 06, 2008; can't exit viper insert mode with ESC using emacsclient -t

From: Stefano Zacchiroli <[email-masked]>
Date: Fri, 14 Nov 2008 14:48:14 +0100

OK, mainly thanks to Romain Francoise, I've made some progress on the
understanding of this bug. Romain pointed me to the fact that viper
initialization depends on whether *when Emacs start* an X11
environment is in use or not.

The client/server architecture offered by emacsclient and by --daemon
defeats the soundness of this approach. To solve the problem once and
for all we need per-client initialization so that when a terminal
client is used Viper can be initialized _locally_ with terminal
settings, dually when a X11 client is used.

The workaround that Romain proposed to me is to add *before* Viper is
loaded the following line in my ~/.emacs

  (setq viper-ESC-key (kbd "ESC"))	;; workaround for #1072

I don't know why :-) , but it solves *part* of the problem.

Still, the behavior of key bindings starting with "M-" is
broken. AFAIU the reason is that viper-ESC-keyseq-timeout is either
set to 0 (which is good for X11) or to 200 (which is good for
terminals). As I typically run the main Emacs in X11, my typical value
is 0; when I spawn terminal clients attached to that Emacs they
inherit the value and stuff like "M-x" first deliver an ESC which
makes Viper quit insert mode.

A possible solution would be to use hooks that set
viper-ESC-keyseq-timeout appropriately depending on the kind of
spawned client, but there are two sub-problems inhibiting them:

0) (my ignorance, probably not really a problem) I'm aware of the hook
   after-create-frame-functions, which can be used to hook the timeout
   to 0 for X11 clients, but I'm not aware of the equivalent for
   console clients, is there one?

1) viper-ESC-keyseq-timeout is a global variable, shared by all Emacs
   clients, can it be made local to a buffer (actually it would be
   enough to make it local to a client, but I don't believe it is
   possible), or there is some Viper magic which would defeat this
   solution not work?

For the moment I'm stuck at exiting from Viper insert mode before
being able to type M-something ...

Cheers.

-- 
Stefano Zacchiroli -o- PhD in Computer Science \ PostDoc @ Univ. Paris 7
zack@{upsilon.cc,pps.jussieu.fr,debian.org} -<>- http://upsilon.cc/zack/
Dietro un grande uomo c'è ..|  .  |. Et ne m'en veux pas si je te tutoie
sempre uno zaino ...........| ..: |.... Je dis tu à tous ceux que j'aime