* execute after char/string
@ 2008-11-27 20:19 Steve Chow
2008-11-27 20:31 ` Barry Margolin
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Steve Chow @ 2008-11-27 20:19 UTC (permalink / raw)
To: help-gnu-emacs
is there a way I can execute a function/macro after I've inserted a
character or string? In this case I'd like execute a function after
typing . or -> in c-mode. I tried using global-set-key but then of
course it won't let me enter those characters into the buffer.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: execute after char/string
2008-11-27 20:19 execute after char/string Steve Chow
@ 2008-11-27 20:31 ` Barry Margolin
2008-11-27 22:15 ` Andreas Politz
2008-11-28 1:35 ` Xah Lee
2008-11-28 2:14 ` Chetan
2 siblings, 1 reply; 5+ messages in thread
From: Barry Margolin @ 2008-11-27 20:31 UTC (permalink / raw)
To: help-gnu-emacs
In article
<9dddf442-089c-495a-af1c-072cc80ad2b0@n33g2000pri.googlegroups.com>,
Steve Chow <msweaksauce@hotmail.com> wrote:
> is there a way I can execute a function/macro after I've inserted a
> character or string? In this case I'd like execute a function after
> typing . or -> in c-mode. I tried using global-set-key but then of
> course it won't let me enter those characters into the buffer.
See after-change-functions.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: execute after char/string
2008-11-27 20:31 ` Barry Margolin
@ 2008-11-27 22:15 ` Andreas Politz
0 siblings, 0 replies; 5+ messages in thread
From: Andreas Politz @ 2008-11-27 22:15 UTC (permalink / raw)
To: help-gnu-emacs
Barry Margolin wrote:
> In article
> <9dddf442-089c-495a-af1c-072cc80ad2b0@n33g2000pri.googlegroups.com>,
> Steve Chow <msweaksauce@hotmail.com> wrote:
>
>> is there a way I can execute a function/macro after I've inserted a
>> character or string? In this case I'd like execute a function after
>> typing . or -> in c-mode. I tried using global-set-key but then of
>> course it won't let me enter those characters into the buffer.
>
> See after-change-functions.
>
A spicedup self-insert-command is much simpler I think.
(defun super-dot-minus-arrow (&optional arg)
(interactive "p")
(self-insert-command arg)
(do-some-more-stuff-when-apropriate))
(define-key your-map (kbd ".") 'super-dot-minus-arrow)
-ap
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: execute after char/string
2008-11-27 20:19 execute after char/string Steve Chow
2008-11-27 20:31 ` Barry Margolin
@ 2008-11-28 1:35 ` Xah Lee
2008-11-28 2:14 ` Chetan
2 siblings, 0 replies; 5+ messages in thread
From: Xah Lee @ 2008-11-28 1:35 UTC (permalink / raw)
To: help-gnu-emacs
On Nov 27, 12:19 pm, Steve Chow <msweaksa...@hotmail.com> wrote:
> is there a way I can execute a function/macro after I've inserted a
> character or string? In this case I'd like execute a function after
> typing . or -> in c-mode. I tried using global-set-key but then of
> course it won't let me enter those characters into the buffer.
this will work:
(defun ff ()
"type period then do y."
(interactive)
(let ()
(self-insert-command 1)
(funcall 'y)
)
)
(global-set-key (kbd ".") 'ff)
the y is whatever your function.
for "->", you could do the above for “>”, and the ff checks whether
previous char is “-”.
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: execute after char/string
2008-11-27 20:19 execute after char/string Steve Chow
2008-11-27 20:31 ` Barry Margolin
2008-11-28 1:35 ` Xah Lee
@ 2008-11-28 2:14 ` Chetan
2 siblings, 0 replies; 5+ messages in thread
From: Chetan @ 2008-11-28 2:14 UTC (permalink / raw)
To: help-gnu-emacs
Steve Chow <msweaksauce@hotmail.com> writes:
> is there a way I can execute a function/macro after I've inserted a
> character or string? In this case I'd like execute a function after
> typing . or -> in c-mode. I tried using global-set-key but then of
> course it won't let me enter those characters into the buffer.
I don't have anything to do after inserting the character, but before.
It goes something like this:
(defun fix-array-index(&optional arg)
(interactive "p")
;; go fix up the index value, if needed
(self-insert-command arg))
And the following in the mode hook:
(local-set-key "]" 'fix-array-index)
with some checks to do it only once.
Chetan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-11-28 2:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-27 20:19 execute after char/string Steve Chow
2008-11-27 20:31 ` Barry Margolin
2008-11-27 22:15 ` Andreas Politz
2008-11-28 1:35 ` Xah Lee
2008-11-28 2:14 ` Chetan
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.