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

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

Re: Character repeation detection


From: Jambunathan K
Subject: Re: Character repeation detection
Date: Sun, 09 Mar 2014 20:59:10 +0530
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Tom <adatgyujto@gmail.com> writes:

> 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.

Here is a quick one that checks for 2 characters in a row.

Are you sure you don't want flyspell-mode and only this. What is your
usecase.  Why would you want this?

    (defvar-local my-last-command-event nil)

    (defun my-self-insert-command (N)
      (interactive "p")
      (if (eq my-last-command-event last-command-event)
          (minibuffer-message "Refusing to insert %c" last-command-event)
        (setq my-last-command-event last-command-event)
        (self-insert-command N)))

    (defun my-post-command-hook ()
      (unless (eq this-command 'my-self-insert-command)
        (setq my-last-command-event nil)))

    (add-hook 'post-command-hook 'my-post-command-hook)

    (substitute-key-definition 'self-insert-command
                               'my-self-insert-command
                               (current-global-map))



reply via email to

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