Reputation: 91600
In Emacs, I want to make a keyboard combination do one thing if I press it once, and another thing if I press it twice. Beyond that I don't care (probably alternating would make the most sense). I know how to make something alternate, but the thing is, I want it to reset whenever I do something else, so that pressing the shortcut once, moving the cursor, and then pressing it again does the pressing once action, not the pressing twice action.
Upvotes: 2
Views: 138
Reputation: 2350
You can use last-command
, for example
(defun eab/etags-find-or-pop ()
(interactive)
(if (memq last-command '(eab/etags-find-or-pop))
(call-interactively 'pop-tag-mark)
(call-interactively 'etags-select-find-tag-at-point)))
(global-set-key (kbd "M-.") 'eab/etags-find-or-pop)
If you press M-.
fisrt time, it calls one thing, and if M-. M-.
(second time) it calls another thing.
Upvotes: 3
Reputation: 28551
The usual way to test this kind of repetition is with (eq this-command last-command)
.
Upvotes: 1