If I understand what you want, I'd suggest that it is better to forget about timers and waiting a slight delay (i.e., to distinguish the intention of <menu>
as a command from its use as a prefix key).
The approach I recommend, and use quite a bit, is to define a prefix key (in your case, e.g., <menu>
), and then put the command that you were thinking of using for <menu>
on <menu> <menu>
. That's as quick as hitting <menu>
once and trying to rely on some tiny delay etc.
And it allows the command you think of as being on <menu>
(really it is on <menu> <menu>
) to be repeatable.
I typically make such a command repeatable, so that <menu> <menu> <menu>
repeats the command once, <menu> <menu> <menu> <menu>
repeats it twice, and so on. IOW, I tend to use this trick for commands that I really want to repeat easily, by just holding down a key.
Here's a simple example, from a suggestion I made more generally to emacs-devel@gnu.org
back in 2009, HERE. In that mailing-list message, if you scroll down to #9 you will see the proposal to use such keys, #12 shows this same example, and #15 addresses your question directly. The thread title is "have cake will eat,eat cake will have - krazy key koncept kontroversy", and its subject is exactly the question you raised.
;; This function builds a repeatable version of its argument COMMAND.
(defun repeat-command (command)
"Repeat COMMAND."
(interactive)
(let ((repeat-previous-repeated-command command)
(last-repeatable-command 'repeat))
(repeat nil)))
Here is how you could then define `C-x', which is already a prefix
key, as also a repeatable key for an action command, in this case,
`backward-char':
(defun backward-char-repeat ()
"Like `backward-char', but repeatable even on a prefix key."
(interactive)
(repeat-command 'backward-char))
(define-key ctl-x-map "C-x" 'backward-char-repeat)
Now just holding down `C-x' invokes `backward-char' repeatedly - once
you've gotten past the first `C-x' (the prefix).
As I say, I've long used this technique to be able to (a) have "repeating prefix keys" and (b) still have other keys defined on them.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…