[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#11983: 24.1; Electric-command-loop broken?
From: |
Roland Winkler |
Subject: |
bug#11983: 24.1; Electric-command-loop broken? |
Date: |
Thu, 19 Jul 2012 16:29:53 -0500 |
On Thu Jul 19 2012 Stefan Monnier wrote:
> The best I could understand of what it's trying to do is summarized in
> the commentary I added:
>
> ;; - electric modes and buffers: modes that typically pop-up in a
> ;; modal kind of way a transient buffer that automatically
> ;; disappears as soon as the user is done with it.
>
> > (this is used by BBDB 3):
>
> Could you maybe then describe the expected behavior, from the user's
> point of view? Adding docstrings, and/or improving comments would be
> very welcome.
My understanding of this is the following (better suggestions
welcome):
Imagine you have an unwind-protect form. It allows you to execute
whatever noninteractive code, and you can be sure that in the end
it executes cleanup-form. Now imagine you want to do the same
thing interactively: you want to run some commands interactively,
and in the end you want to be sure you execute cleanup-form, no
matter what happens. The code for this is
(unwind-protect
(catch 'return-tag
(Electric-command-loop 'return-tag))
(cleanup-form))
Electric-command-loop throws 'return-tag if you type
C-g (keyboard-quit). Or you can make commands electric by letting
them throw 'return-tag. But any other command is executed inside
the temporary command loop implemented by Electric-command-loop
without ever leaving this loop. In particular, this temporary
command loop catches all errors that do not throw 'return-tag.
So in short: Electric-command-loop allows one to execute commands
in an `unwind-protect'ed temporary command loop.
Maybe there is a simpler way to implement such a functionality.
A typical application is suggested by the function
Electric-pop-up-window which pops up a window fairly aggresively
(see bug#11985): You quickly execute some command in the electric
window. When you are done, this code guarantees that cleanup-form
gets executed.
> > - The doc string says
> > ;; Given third argument non-nil, it
> > ;; INHIBITS quitting unless the user types C-g at toplevel. This is
> > ;; so user can do things like C-u C-g and not get thrown out.
> > Yet it appears to me, that even for C-u C-g the user gets thrown out.
>
> I have no idea what this "C-u C-g" refers to, indeed.
If you type a plain C-g, Electric-command-loop throws
'return-tag. Now the idea is that if you type C-u, then you
change your mind and want to cancel it by typing C-g, then the
code should not leave the temporary command loop.