* key interception in major mode
@ 2006-01-14 18:53 Anton V. Belyaev
2006-01-15 2:14 ` Ian Zimmerman
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Anton V. Belyaev @ 2006-01-14 18:53 UTC (permalink / raw)
I am writing my own major mode. How can I make my own function called
on every key press?
I tried to create a copy of global map, replacing self-insert-command
function with my own, but failed. Maybe there is another way to achieve
key interception in major mode?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: key interception in major mode
2006-01-14 18:53 key interception in major mode Anton V. Belyaev
@ 2006-01-15 2:14 ` Ian Zimmerman
2006-01-15 2:47 ` Stefan Monnier
[not found] ` <mailman.1135.1137291437.26925.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 6+ messages in thread
From: Ian Zimmerman @ 2006-01-15 2:14 UTC (permalink / raw)
Cc: help-gnu-emacs
Anton> I am writing my own major mode. How can I make my own function
Anton> called on every key press? I tried to create a copy of global
Anton> map, replacing self-insert-command function with my own, but
Anton> failed. Maybe there is another way to achieve key interception in
Anton> major mode?
First of all, it is not clear what you mean by "called on every key
press". `self-insert-command' certainly isn't called on every key press
from my POV; for example, it isn't called when you press the TAB key.
(unless a major mode overrides its binding in the global map, of
course).
That said, here is one way (though probably not the cleanest way) of
doing something along the lines you did: define an advice (see the
online help for `defadvice') for `self-insert-command'; the adviced
function should first check the major mode (variable `major-mode')
and either do your thing or else the usual thing (`ad-do-it').
--
A true pessimist won't be discouraged by a little success.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: key interception in major mode
2006-01-14 18:53 key interception in major mode Anton V. Belyaev
2006-01-15 2:14 ` Ian Zimmerman
@ 2006-01-15 2:47 ` Stefan Monnier
2006-01-15 10:47 ` Anton V. Belyaev
[not found] ` <mailman.1135.1137291437.26925.help-gnu-emacs@gnu.org>
2 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2006-01-15 2:47 UTC (permalink / raw)
> I am writing my own major mode. How can I make my own function called
> on every key press?
(define-key my-major-mode-map [t] 'my-own-special-catch-all-function)
Most likely it's not going to do what you want, tho. Please give us
more details.
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: key interception in major mode
[not found] ` <mailman.1135.1137291437.26925.help-gnu-emacs@gnu.org>
@ 2006-01-15 10:39 ` Anton V. Belyaev
0 siblings, 0 replies; 6+ messages in thread
From: Anton V. Belyaev @ 2006-01-15 10:39 UTC (permalink / raw)
Thank you for your solution. Though it doesnt look clean it should work
anyway :)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: key interception in major mode
2006-01-15 2:47 ` Stefan Monnier
@ 2006-01-15 10:47 ` Anton V. Belyaev
2006-01-18 4:04 ` Stefan Monnier
0 siblings, 1 reply; 6+ messages in thread
From: Anton V. Belyaev @ 2006-01-15 10:47 UTC (permalink / raw)
Thank you for your reply.
I want to handle all the aphabetic characters. Of cource I could
(define-key) for all of them, but it is not a clean solution either.
For example, it should be possible to track all the keypresses for
certaiin buffer. Another example: I want to write a mode, where every
word starts with a capital letter. So on every character typed I should
insert upper or lower case letter.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: key interception in major mode
2006-01-15 10:47 ` Anton V. Belyaev
@ 2006-01-18 4:04 ` Stefan Monnier
0 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2006-01-18 4:04 UTC (permalink / raw)
> Thank you for your reply.
> I want to handle all the aphabetic characters. Of cource I could
> (define-key) for all of them, but it is not a clean solution either.
> For example, it should be possible to track all the keypresses for
> certaiin buffer. Another example: I want to write a mode, where every
> word starts with a capital letter. So on every character typed I should
> insert upper or lower case letter.
Check autocap.el for an example. I'm not sure what it uses, tho.
In any case, I guess post-command-hook is one way to do it.
auto-fill-function is another.
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-01-18 4:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-14 18:53 key interception in major mode Anton V. Belyaev
2006-01-15 2:14 ` Ian Zimmerman
2006-01-15 2:47 ` Stefan Monnier
2006-01-15 10:47 ` Anton V. Belyaev
2006-01-18 4:04 ` Stefan Monnier
[not found] ` <mailman.1135.1137291437.26925.help-gnu-emacs@gnu.org>
2006-01-15 10:39 ` Anton V. Belyaev
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).