* was a command called via M-x?
@ 2014-07-17 8:31 Eric Abrahamsen
2014-07-17 13:57 ` Drew Adams
0 siblings, 1 reply; 3+ messages in thread
From: Eric Abrahamsen @ 2014-07-17 8:31 UTC (permalink / raw
To: help-gnu-emacs
I've written most of a tiny library, built on top of alert.el, that's
supposed to be used for demonstration screencasts: it watches for
interactive function calls, and pops the name of the function up as a
libnotify bubble if certain conditions are met (or logs it to a buffer
etc etc, anything that alert can do). It's pretty much done, except for
one last question.
I want the bubbles to show the command name, the prefix arg, and the key
sequence that was used to call the command. All that works fine, except
if the command was called via M-x, ie `execute-extended-command'. In
that case, `this-command-keys' returns "RET", which isn't quite right --
I'd rather it showed "M-x" or whatever. This is the basics of how it
works (this is put into the post-command-hook):
(let* ((command-name (symbol-name this-command))
(pref-arg current-prefix-arg)
(keys (this-command-keys))
(key-string (key-description keys))
(title-string (if pref-arg
(format "%s %s" pref-arg key-string)
(format "%s" key-string))))
(alert command-name :title title-string))
I don't want to just check for "RET" and replace it with "M-x", because
the command might very well have been called with "RET". Do I have any
other way of knowing for sure that the command was called using
`execute-extended-command'? last-command doesn't seem to get it
either...
Thanks,
Eric
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: was a command called via M-x?
2014-07-17 8:31 was a command called via M-x? Eric Abrahamsen
@ 2014-07-17 13:57 ` Drew Adams
2014-07-19 12:37 ` Eric Abrahamsen
0 siblings, 1 reply; 3+ messages in thread
From: Drew Adams @ 2014-07-17 13:57 UTC (permalink / raw
To: Eric Abrahamsen, help-gnu-emacs
> (let* ((command-name (symbol-name this-command))
> (pref-arg current-prefix-arg)
> (keys (this-command-keys))
> (key-string (key-description keys))
> (title-string (if pref-arg
> (format "%s %s" pref-arg key-string)
> (format "%s" key-string))))
> (alert command-name :title title-string))
>
> I don't want to just check for "RET" and replace it with "M-x", because
> the command might very well have been called with "RET". Do I have any
> other way of knowing for sure that the command was called using
> `execute-extended-command'? last-command doesn't seem to get it
> either...
You might want to show more of how your code is invoked etc.
`execute-extended-command' changes `this-command'. The command invoked
by `execute-extended-command' is instead the value of `real-this-command',
and you can get its key binding (if there is one) using:
(where-is-internal real-this-command overriding-local-map t) instead of
(this-command-keys).
But if you want `execute-extended-command' or `M-x' instead of that
information, then you will probably need to either advise that function
or (depending on when you need the info) advise `read-extended-command',
recording for yourself the fact that `execute-extended-command' was
invoked.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: was a command called via M-x?
2014-07-17 13:57 ` Drew Adams
@ 2014-07-19 12:37 ` Eric Abrahamsen
0 siblings, 0 replies; 3+ messages in thread
From: Eric Abrahamsen @ 2014-07-19 12:37 UTC (permalink / raw
To: help-gnu-emacs
Drew Adams <drew.adams@oracle.com> writes:
>> (let* ((command-name (symbol-name this-command))
>> (pref-arg current-prefix-arg)
>> (keys (this-command-keys))
>> (key-string (key-description keys))
>> (title-string (if pref-arg
>> (format "%s %s" pref-arg key-string)
>> (format "%s" key-string))))
>> (alert command-name :title title-string))
>>
>> I don't want to just check for "RET" and replace it with "M-x", because
>> the command might very well have been called with "RET". Do I have any
>> other way of knowing for sure that the command was called using
>> `execute-extended-command'? last-command doesn't seem to get it
>> either...
>
> You might want to show more of how your code is invoked etc.
>
> `execute-extended-command' changes `this-command'. The command invoked
> by `execute-extended-command' is instead the value of `real-this-command',
> and you can get its key binding (if there is one) using:
> (where-is-internal real-this-command overriding-local-map t) instead of
> (this-command-keys).
>
> But if you want `execute-extended-command' or `M-x' instead of that
> information, then you will probably need to either advise that function
> or (depending on when you need the info) advise `read-extended-command',
> recording for yourself the fact that `execute-extended-command' was
> invoked.
Hmm, that's sounding like maybe more work than it's worth. Let me clean
up the module as it is, and have another hard look at it.
Thanks,
Eric
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-07-19 12:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-17 8:31 was a command called via M-x? Eric Abrahamsen
2014-07-17 13:57 ` Drew Adams
2014-07-19 12:37 ` Eric Abrahamsen
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.