[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

was a command called via M-x?

From: Eric Abrahamsen
Subject: was a command called via M-x?
Date: Thu, 17 Jul 2014 16:31:50 +0800
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4.50 (gnu/linux)

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]