* Emacs attach an action to any key pressed
@ 2013-06-05 5:26 Ivanov Dmitry
2013-06-05 6:44 ` Magnar Sveen
2013-06-05 13:02 ` Stefan Monnier
0 siblings, 2 replies; 6+ messages in thread
From: Ivanov Dmitry @ 2013-06-05 5:26 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 362 bytes --]
Suppose, I have the code:
(defun dummy ()
(interactive)
(message "aaa"))
(local-set-key (kbd "<left>") 'dummy)
When you click <left> key in the current buffer, it will print "aaa".
Is it possible to attach this action to any key pressed?
I looked into "Format of Keymaps" and "Searching Keymaps" in Emacs info
pages, but found no code examples.
[-- Attachment #2: Type: text/html, Size: 525 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Emacs attach an action to any key pressed
2013-06-05 5:26 Emacs attach an action to any key pressed Ivanov Dmitry
@ 2013-06-05 6:44 ` Magnar Sveen
2013-06-05 7:56 ` Ivanov Dmitry
2013-06-05 13:02 ` Stefan Monnier
1 sibling, 1 reply; 6+ messages in thread
From: Magnar Sveen @ 2013-06-05 6:44 UTC (permalink / raw)
To: Ivanov Dmitry; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 526 bytes --]
Sounds like you're looking for the post-command-hook.
- Magnar
On Wed, Jun 5, 2013 at 7:26 AM, Ivanov Dmitry <usr345@gmail.com> wrote:
> Suppose, I have the code:
>
> (defun dummy ()
> (interactive)
> (message "aaa"))
>
> (local-set-key (kbd "<left>") 'dummy)
>
> When you click <left> key in the current buffer, it will print "aaa".
>
> Is it possible to attach this action to any key pressed?
>
> I looked into "Format of Keymaps" and "Searching Keymaps" in Emacs info
> pages, but found no code examples.
>
[-- Attachment #2: Type: text/html, Size: 995 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Emacs attach an action to any key pressed
2013-06-05 6:44 ` Magnar Sveen
@ 2013-06-05 7:56 ` Ivanov Dmitry
2013-06-05 13:24 ` Kevin Rodgers
0 siblings, 1 reply; 6+ messages in thread
From: Ivanov Dmitry @ 2013-06-05 7:56 UTC (permalink / raw)
To: Magnar Sveen; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 303 bytes --]
I tried this:
(defun dummy ()
(interactive)
(message "aaa")
(remove-hook 'post-command-hook 'dummy))
(add-hook 'post-command-hook 'dummy)
It prints "aaa" exactly after I press C-x e on add-hook command. But I want
it to print only when I press any key afterwards. What should I do?
[-- Attachment #2: Type: text/html, Size: 458 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Emacs attach an action to any key pressed
2013-06-05 5:26 Emacs attach an action to any key pressed Ivanov Dmitry
2013-06-05 6:44 ` Magnar Sveen
@ 2013-06-05 13:02 ` Stefan Monnier
2013-06-05 13:48 ` Ivanov Dmitry
1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2013-06-05 13:02 UTC (permalink / raw)
To: Ivanov Dmitry; +Cc: emacs-devel
> Is it possible to attach this action to any key pressed?
Maybe you're looking for
(local-set-key [t] 'dummy)
-- Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Emacs attach an action to any key pressed
2013-06-05 7:56 ` Ivanov Dmitry
@ 2013-06-05 13:24 ` Kevin Rodgers
0 siblings, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2013-06-05 13:24 UTC (permalink / raw)
To: emacs-devel
On 6/5/13 1:56 AM, Ivanov Dmitry wrote:
> I tried this:
>
> (defun dummy ()
> (interactive)
> (message "aaa")
> (remove-hook 'post-command-hook 'dummy))
>
> (add-hook 'post-command-hook 'dummy)
>
> It prints "aaa" exactly after I press C-x e on add-hook command. But I want it
> to print only when I press any key afterwards. What should I do?
(when (read-event "Press any key to continue: ")
(message "aaa"))
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Emacs attach an action to any key pressed
2013-06-05 13:02 ` Stefan Monnier
@ 2013-06-05 13:48 ` Ivanov Dmitry
0 siblings, 0 replies; 6+ messages in thread
From: Ivanov Dmitry @ 2013-06-05 13:48 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 237 bytes --]
On Wed, Jun 5, 2013 at 5:02 PM, Stefan Monnier <monnier@iro.umontreal.ca>wrote:
> > Is it possible to attach this action to any key pressed?
>
> Maybe you're looking for
>
> (local-set-key [t] 'dummy)
>
Yes. It worked great. Thanks.
[-- Attachment #2: Type: text/html, Size: 669 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-06-05 13:48 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-05 5:26 Emacs attach an action to any key pressed Ivanov Dmitry
2013-06-05 6:44 ` Magnar Sveen
2013-06-05 7:56 ` Ivanov Dmitry
2013-06-05 13:24 ` Kevin Rodgers
2013-06-05 13:02 ` Stefan Monnier
2013-06-05 13:48 ` Ivanov Dmitry
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).