help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Character repeation detection


From: Marcin Borkowski
Subject: Re: Character repeation detection
Date: Sun, 9 Mar 2014 14:47:35 +0100

Dnia 2014-03-09, o godz. 07:12:55
Tom <adatgyujto@gmail.com> napisał(a):

> Tom <adatgyujto <at> gmail.com> writes:
> 
> > 
> > Jambunathan K <kjambunathan <at> gmail.com> writes:
> > 
> > > > Is there an existing solution for this?
> > > 
> > >     M-s h r \(.\)\1 RET
> > > 
> > >     (highlight-regexp "\\(.\\)\\1" (quote highlight))
> > > 
> > 
> > I'm not talking about highlighting. I'd like an actual function
> > call when this happens.
> > 
> 
> And I don't mean 3 or more of the same character in the buffer
> somewhere. I'm interested in detecting  when the user types
> 3 or more of the same character in a row.

An obvious idea that comes to mind is to advise the
`self-insert-command' function.  Can functions written in C be
advised?  (I don't know, I never actually *used* advice.)

If this is not possible, one could remap all self-inserting commands
to e.g. `self-insert-if-not-repeated-too-many-times', which could be
trivially defined to Do The Right Thing™ (possibly using something
like (looking-back "\\(.\\)\\1")).

Note: do you mean "when the user types 3 or more of the same character
in a row", or rather "when a user types a character such that two
characters before point are this very character, too?"  My suggestion
deals with the latter variant, of course, which encompasses more cases
than the former, but seems reasonable to me.

Hth,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Adam Mickiewicz University



reply via email to

[Prev in Thread] Current Thread [Next in Thread]