GNU bug report logs -
#4093
Overlay keymap and timers
Previous Next
Reported by: Mihai Bazon <mihai <at> bazon.net>
Date: Sun, 9 Aug 2009 14:00:04 UTC
Severity: normal
Merged with 4081,
10459,
11088
Found in version 24.0.94
Fixed in version 24.4
Done: Dmitry Gutov <dgutov <at> yandex.ru>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 4093 in the body.
You can then email your comments to 4093 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4093
; Package
emacs
.
(Sun, 09 Aug 2009 14:00:04 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Mihai Bazon <mihai <at> bazon.net>
:
New bug report received and forwarded. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Sun, 09 Aug 2009 14:00:04 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):
Actually, it seems it hasn't anything to do with overlays:
(defun my-set-keymap-with-timer ()
(interactive)
(run-with-timer 0.5 nil (lambda()
(use-local-map my-keymap)
(message "Done setting keymap"))))
If we eval the following and M-x my-set-keymap-with-timer, the keymap
will only be enforced after the first keypress (i.e. first press of M-n
says "M-n is undefined", but subsequently it works).
Found another thread about this issue here:
http://www.mail-archive.com/emacs-pretest-bug <at> gnu.org/msg12003.html
Stallman says "we should consider that a serious problem". ;-)
Cheers,
-Mihai
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4093
; Package
emacs
.
(Sun, 09 Aug 2009 21:05:04 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Lennart Borgman <lennart.borgman <at> gmail.com>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Sun, 09 Aug 2009 21:05:04 GMT)
Full text and
rfc822 format available.
Message #10 received at 4093 <at> emacsbugs.donarmstrong.com (full text, mbox):
Yes, this is a really bad thing - sometimes, ie when you need to do just that.
Is there any fundamental difficulty with fixing this?
On Sun, Aug 9, 2009 at 3:49 PM, Mihai Bazon<mihai <at> bazon.net> wrote:
> Actually, it seems it hasn't anything to do with overlays:
>
> (defun my-set-keymap-with-timer ()
> (interactive)
> (run-with-timer 0.5 nil (lambda()
> (use-local-map my-keymap)
> (message "Done setting keymap"))))
>
> If we eval the following and M-x my-set-keymap-with-timer, the keymap
> will only be enforced after the first keypress (i.e. first press of M-n
> says "M-n is undefined", but subsequently it works).
>
> Found another thread about this issue here:
>
> http://www.mail-archive.com/emacs-pretest-bug <at> gnu.org/msg12003.html
>
> Stallman says "we should consider that a serious problem". ;-)
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4093
; Package
emacs
.
(Sun, 09 Aug 2009 21:35:04 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Mihai Bazon <mihai <at> bazon.net>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Sun, 09 Aug 2009 21:35:04 GMT)
Full text and
rfc822 format available.
Message #15 received at 4093 <at> emacsbugs.donarmstrong.com (full text, mbox):
Sorry, looks like I accidentally started a new bug, but this is really a
follow up to
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=4081
Should be marked as duplicate, or whatever..
Lennart Borgman <lennart.borgman <at> gmail.com> wrote:
> Yes, this is a really bad thing
But indeed, it is bad...
I'm calling (top-level) for now, but it's not nice.
Cheers,
-Mihai
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4093
; Package
emacs
.
(Mon, 10 Aug 2009 04:15:04 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Stefan Monnier <monnier <at> iro.umontreal.ca>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Mon, 10 Aug 2009 04:15:04 GMT)
Full text and
rfc822 format available.
Message #20 received at 4093 <at> emacsbugs.donarmstrong.com (full text, mbox):
> Yes, this is a really bad thing - sometimes, ie when you need to do
> just that.
The code in keyboard.c reads the set of active keymaps before reading
the next event. That's most likely the explanation for this behavior.
> Is there any fundamental difficulty with fixing this?
It seems the relevant code is trying to do something clever in case of
low-memory situations, so we may bump into surprises, but other than
that, I can't think of any reason why it should be difficult.
Stefan
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4093
; Package
emacs
.
(Mon, 10 Aug 2009 07:05:05 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Mihai Bazon <mihai <at> bazon.net>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Mon, 10 Aug 2009 07:05:05 GMT)
Full text and
rfc822 format available.
Message #25 received at 4093 <at> emacsbugs.donarmstrong.com (full text, mbox):
Stefan Monnier <monnier <at> iro.umontreal.ca> wrote:
> > Yes, this is a really bad thing - sometimes, ie when you need to do
> > just that.
>
> The code in keyboard.c reads the set of active keymaps before reading
> the next event. That's most likely the explanation for this behavior.
What you are saying does actually make sense. If it set the keymap
*before* serving an event, it should work fine. But I think what
happens is that it sets the keymap *after* executing an event...
I looked at the code but couldn't figure out where is the keymap
computed. Could you point it out?
Cheers,
-Mihai
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4093
; Package
emacs
.
(Mon, 10 Aug 2009 16:35:05 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Stefan Monnier <monnier <at> iro.umontreal.ca>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Mon, 10 Aug 2009 16:35:05 GMT)
Full text and
rfc822 format available.
Message #30 received at 4093 <at> emacsbugs.donarmstrong.com (full text, mbox):
>> > Yes, this is a really bad thing - sometimes, ie when you need to do
>> > just that.
>> The code in keyboard.c reads the set of active keymaps before reading
>> the next event. That's most likely the explanation for this behavior.
> What you are saying does actually make sense. If it set the keymap
> *before* serving an event, it should work fine. But I think what
> happens is that it sets the keymap *after* executing an event...
> I looked at the code but couldn't figure out where is the keymap
> computed. Could you point it out?
The relevant code is in .... read_key_sequence! (only those who've had
to deal with this function understand the "....").
You'll see that it first collects all the active keyamps (see where it
calls current_minor_maps), and later on calls read_char (which can do
redisplay, run timers, run process filters, etc...).
Basically the problem in the case of changing the keymap from a timer
comes down to:
what happens if the use presses C-c, then your code runs then the user
presses C-d: should the C-c C-d be looked up in the original keymaps
or in the new keymaps?
you worry about the case where the timer is run before the C-c, but from
Emacs's current point of view, it's no different whether the timer is
run after 1 key-press, or after 2 key-presses, or after 0 key-presses.
We can probably change the code to collect the list of active keymaps
later (e.g. right after the first key-press).
But maybe an alternative is to provide some way for your Elisp code to
cause a jump back to `replay_sequence' so that you can force the C-c C-d
to be interpreted in the new keymaps even if the C-c had already been
pressed when your code was run.
In any case, this function is a monster, so I'll only consider changes
to it if it makes it simpler (typically by moving code out of it into
some new function). Maybe the idea of a new "need-to-replay-sequence"
variable could be a good way to simplify the code: we could maybe
arrange for most other "goto replay_sequence" to use this new var
(i.e. replace the current code that checks some relevant condition, by
some piece of code elsewhere (where that condition is created) which
sets the var).
Stefan
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4093
; Package
emacs
.
(Mon, 10 Aug 2009 16:35:07 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Lennart Borgman <lennart.borgman <at> gmail.com>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Mon, 10 Aug 2009 16:35:07 GMT)
Full text and
rfc822 format available.
Message #35 received at 4093 <at> emacsbugs.donarmstrong.com (full text, mbox):
On Mon, Aug 10, 2009 at 6:25 PM, Stefan Monnier<monnier <at> iro.umontreal.ca> wrote:
> But maybe an alternative is to provide some way for your Elisp code to
> cause a jump back to `replay_sequence' so that you can force the C-c C-d
> to be interpreted in the new keymaps even if the C-c had already been
> pressed when your code was run.
Sounds good. Would it perhaps be most easy to implement a
`please-replay-sequence' function that tells the command loop to go
one more turn and check the keymaps again and reuse the pending input?
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4093
; Package
emacs
.
(Mon, 10 Aug 2009 17:45:04 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Stefan Monnier <monnier <at> iro.umontreal.ca>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Mon, 10 Aug 2009 17:45:04 GMT)
Full text and
rfc822 format available.
Message #40 received at 4093 <at> emacsbugs.donarmstrong.com (full text, mbox):
>> But maybe an alternative is to provide some way for your Elisp code to
>> cause a jump back to `replay_sequence' so that you can force the C-c C-d
>> to be interpreted in the new keymaps even if the C-c had already been
>> pressed when your code was run.
> Sounds good. Would it perhaps be most easy to implement
> a `please-replay-sequence' function that tells the command loop to go
> one more turn and check the keymaps again and reuse the pending input?
That function couldn't do much more than set a variable and return.
So yes, it could be done and would have the advantage of making it
possible to keep the variable hidden from Elisp. Not sure if that
advantage is of any significance, tho.
Stefan
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4093
; Package
emacs
.
(Mon, 10 Aug 2009 17:50:06 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Lennart Borgman <lennart.borgman <at> gmail.com>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Mon, 10 Aug 2009 17:50:07 GMT)
Full text and
rfc822 format available.
Message #45 received at 4093 <at> emacsbugs.donarmstrong.com (full text, mbox):
On Mon, Aug 10, 2009 at 7:38 PM, Stefan Monnier<monnier <at> iro.umontreal.ca> wrote:
>>> But maybe an alternative is to provide some way for your Elisp code to
>>> cause a jump back to `replay_sequence' so that you can force the C-c C-d
>>> to be interpreted in the new keymaps even if the C-c had already been
>>> pressed when your code was run.
>> Sounds good. Would it perhaps be most easy to implement
>> a `please-replay-sequence' function that tells the command loop to go
>> one more turn and check the keymaps again and reuse the pending input?
>
> That function couldn't do much more than set a variable and return.
> So yes, it could be done and would have the advantage of making it
> possible to keep the variable hidden from Elisp. Not sure if that
> advantage is of any significance, tho.
You mean it is the same approach as you were thinking of? Then I think
the "active voice" used to call the function makes it a bit easier to
understand, but maybe that is just me. Also you can't really doubt how
to use it.
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4093
; Package
emacs
.
(Mon, 10 Aug 2009 18:25:04 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Stefan Monnier <monnier <at> iro.umontreal.ca>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Mon, 10 Aug 2009 18:25:04 GMT)
Full text and
rfc822 format available.
Message #50 received at 4093 <at> emacsbugs.donarmstrong.com (full text, mbox):
> You mean it is the same approach as you were thinking of?
Pretty much. I was thinking of (setq need-to-replay-sequence t) instead.
> Then I think the "active voice" used to call the function makes it
> a bit easier to understand, but maybe that is just me.
To me it sounds a bit misleading since the replay does not happen during
the function call. But `force-mode-line-update' does it like you
propose, so it's not that different.
> Also you can't really doubt how to use it.
Indeed, especially if it doesn't take any arguments ;-).
Stefan
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4093
; Package
emacs
.
(Mon, 10 Aug 2009 18:40:06 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Mihai Bazon <mihai <at> bazon.net>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Mon, 10 Aug 2009 18:40:06 GMT)
Full text and
rfc822 format available.
Message #55 received at 4093 <at> emacsbugs.donarmstrong.com (full text, mbox):
Stefan Monnier <monnier <at> iro.umontreal.ca> wrote:
>
> Basically the problem in the case of changing the keymap from a timer
> comes down to:
>
> what happens if the use presses C-c, then your code runs then the user
> presses C-d: should the C-c C-d be looked up in the original keymaps
> or in the new keymaps?
That's a good question. As an user, if I start typing a combined key
binding then I would expect it to work regardless of whatever happened
in a timer in between. So indeed, it can be a problem to allow a timer
to set a new keymap in this case.
But if there's no prefix key already typed, it would be great if
use-local-map actually did what it's supposed to do, even when ran with
a timer.
Perhaps the proper solution would involve saving the current keymap when
a prefix key has been pressed, and use that keymap until it results in a
command or it's canceled. If a timer changes the keymap in between, the
new keymap should apply only after any pending key binding has been
finished. Not sure if this is doable...
I'm sorry I don't have any knowledge of Emacs internals, and only
limited Lisp knowledge anyway, but I'd love to see a decent work-around
for this...
Cheers,
-Mihai
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4093
; Package
emacs
.
(Mon, 10 Aug 2009 18:40:07 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Lennart Borgman <lennart.borgman <at> gmail.com>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Mon, 10 Aug 2009 18:40:08 GMT)
Full text and
rfc822 format available.
Message #60 received at 4093 <at> emacsbugs.donarmstrong.com (full text, mbox):
On Mon, Aug 10, 2009 at 8:17 PM, Stefan Monnier<monnier <at> iro.umontreal.ca> wrote:
>> You mean it is the same approach as you were thinking of?
>
> Pretty much. I was thinking of (setq need-to-replay-sequence t) instead.
>
>> Then I think the "active voice" used to call the function makes it
>> a bit easier to understand, but maybe that is just me.
>
> To me it sounds a bit misleading since the replay does not happen during
> the function call. But `force-mode-line-update' does it like you
> propose, so it's not that different.
Maybe a better name. But this is of course not as important as the feature.
I do not think that there are many people who dares to touch this part
of the code, but I may be misunderstanding that totally...
Merged 4081 4093.
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> emacsbugs.donarmstrong.com
.
(Mon, 10 Aug 2009 21:05:06 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4093
; Package
emacs
.
(Tue, 11 Aug 2009 17:00:04 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Mihai Bazon <mihai <at> bazon.net>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Tue, 11 Aug 2009 17:00:04 GMT)
Full text and
rfc822 format available.
Message #67 received at 4093 <at> emacsbugs.donarmstrong.com (full text, mbox):
Indeed, that function looks frightening.
It's worth noting that XEmacs doesn't have this problem.
But the code differs drastically.. Hard to figure out a simple fix.
-M
Stefan Monnier <monnier <at> iro.umontreal.ca> wrote:
> >> > Yes, this is a really bad thing - sometimes, ie when you need to do
> >> > just that.
> >> The code in keyboard.c reads the set of active keymaps before reading
> >> the next event. That's most likely the explanation for this behavior.
> > What you are saying does actually make sense. If it set the keymap
> > *before* serving an event, it should work fine. But I think what
> > happens is that it sets the keymap *after* executing an event...
>
> > I looked at the code but couldn't figure out where is the keymap
> > computed. Could you point it out?
>
> The relevant code is in .... read_key_sequence! (only those who've had
> to deal with this function understand the "....").
>
> You'll see that it first collects all the active keyamps (see where it
> calls current_minor_maps), and later on calls read_char (which can do
> redisplay, run timers, run process filters, etc...).
>
> Basically the problem in the case of changing the keymap from a timer
> comes down to:
>
> what happens if the use presses C-c, then your code runs then the user
> presses C-d: should the C-c C-d be looked up in the original keymaps
> or in the new keymaps?
>
> you worry about the case where the timer is run before the C-c, but from
> Emacs's current point of view, it's no different whether the timer is
> run after 1 key-press, or after 2 key-presses, or after 0 key-presses.
>
> We can probably change the code to collect the list of active keymaps
> later (e.g. right after the first key-press).
> But maybe an alternative is to provide some way for your Elisp code to
> cause a jump back to `replay_sequence' so that you can force the C-c C-d
> to be interpreted in the new keymaps even if the C-c had already been
> pressed when your code was run.
>
> In any case, this function is a monster, so I'll only consider changes
> to it if it makes it simpler (typically by moving code out of it into
> some new function). Maybe the idea of a new "need-to-replay-sequence"
> variable could be a good way to simplify the code: we could maybe
> arrange for most other "goto replay_sequence" to use this new var
> (i.e. replace the current code that checks some relevant condition, by
> some piece of code elsewhere (where that condition is created) which
> sets the var).
>
>
> Stefan
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4093
; Package
emacs
.
(Thu, 13 Aug 2009 17:40:05 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Stefan Monnier <monnier <at> IRO.UMontreal.CA>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Thu, 13 Aug 2009 17:40:05 GMT)
Full text and
rfc822 format available.
Message #72 received at 4093 <at> emacsbugs.donarmstrong.com (full text, mbox):
> Indeed, that function looks frightening.
I hoped you'd find it challenging. Oh well!
> It's worth noting that XEmacs doesn't have this problem.
IIRC XEmacs's equivalent function restarts the whole work after every
event, so they look up the keymaps anew, and look them all up anew
(kind of like always jumping back to replay_sequence except that it
additionally recomputes the active keymaps).
> But the code differs drastically..
Yes, the algorithm is completely different.
I have a feeling it's related to the "frightening" above... nah!
Stefan
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#4093
; Package
emacs
.
(Thu, 13 Aug 2009 18:00:04 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Mihai Bazon <mihai <at> bazon.net>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Thu, 13 Aug 2009 18:00:04 GMT)
Full text and
rfc822 format available.
Message #77 received at 4093 <at> emacsbugs.donarmstrong.com (full text, mbox):
Stefan Monnier <monnier <at> IRO.UMontreal.CA> wrote:
> > Indeed, that function looks frightening.
>
> I hoped you'd find it challenging. Oh well!
I'd love to find it challenging, but I don't have time for this,
sorry... :-(
If I felt competitive enough to fix it within hours, or even days, I'd
get on it. But my C skills, though once pretty good, are long forgotten
-- not to mention that that code requires knowledge far beyond "C", you
actually have to know some intimate Emacs internals.
We'll live with it.
-M.
Merged 4081 4093 11088.
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Sun, 25 Mar 2012 19:04:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sun, 02 Nov 2014 12:24:07 GMT)
Full text and
rfc822 format available.
This bug report was last modified 10 years and 232 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.