[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: was a command called via M-x?
From: |
Drew Adams |
Subject: |
RE: was a command called via M-x? |
Date: |
Thu, 17 Jul 2014 06:57:28 -0700 (PDT) |
> (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.