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

From: Frank Fischer <[email-masked]>
Date: Tue, 26 Feb 2013 15:56:08 +0100

On 02/26, Stefan Monnier wrote:
> >> [ Modulo some dance à la evil-esc-mode to add/remove this binding so
> >> that code that adds escape sequences to this map never bumps into the
> >> [escape] mapping.  ]
> 
> > Maybe one question, because I'm not too familiar with translation
> > keymaps. What do you think is the best solution to this
> > add-escape-sequences-to-input-decode-map-problem? The only possibility
> > that comes into my mind would be to advice `define-key` so that
> > `evil-normal-esc-map` is temporarily put back into `input-decode-map`.
> > Is there a better way than using such an advice?
> 
> I guess an advice might work (it probably wouldn't need to put the map
> back, just let-bind a variable that causes the filter function to return
> evil-normal-esc-map without bothering to sit-for).
> But it doesn't sound very appealing.
> 
> Maybe "enable evil-esc-mode in post-command-hook and disable it in
> pre-command-hook" might work?

I'm a little bit afraid of situations where a new binding is defined
but pre-command-hook has not been called (to restore the original
definition of `input-decode-map`). For example if a new binding is
established in a hook or when Emacs starts. If evil is loaded before
that binding is defined, i.e. input-decode-map is already 'patched',
then it may fail. Of course one could start with an unpatched
input-decode-map and wait for the first post-command-hook.

So the question is: is it guaranteed that a post-command-hook will be
called when Emacs starts and before any user input, and that a call to
`define-key` will always be preceded by a pre-command-hook and
followed by a post-command-hook, no matter how it is called? This
includes any possibility to call `define-key` from a hook or so. I
just do not have the overview to give a reliable judgement on this.
IMO using an advice is more direct and simpler in this particular
situation, although I really don't like it.

Frank