[Top][All Lists]

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

Re: Character repeation detection

From: Tom
Subject: Re: Character repeation detection
Date: Sun, 9 Mar 2014 20:20:54 +0000 (UTC)
User-agent: Loom/3.14 (

Tom <adatgyujto <at>> writes:
> It seems to me it would be more convenient than typing multikey 
> hotkeys and it would give lots of new free bindings in addition to 
> the existing ones.

I created a crude implementation to test the concept.

It invokes occur if you press o 3 times or press o and
keep it pressed. It is active only in buffers with emacs-lisp-mode
major mode for now.

It works, but looks a bit unconventional as the o characters are
deleted automatically.

The only thing missing is restoring the unmodified status
of the buffer if it was unmodified before.

(setq my-char-to-check ?o)

(setq my-char-count 0)

(setq my-start-pos nil)

(defun my-post-command-hook ()
  (when (and (eq major-mode 'emacs-lisp-mode)
             (eq this-command 'self-insert-command))
    (if (not (eq last-command-char my-char-to-check))
        (setq my-char-count 0)

      (if (eq my-char-count 0)
          (setq my-start-pos (1- (point))))

      (incf my-char-count)
      (when (eq my-char-count 3)
        (setq my-char-count 0)
        ;; should restore buffer modified status here
        (delete-region my-start-pos (point))
         0 nil
         (lambda ()
           (add-hook 'post-command-hook 'my-remove-excess-chars)
           (call-interactively 'occur)))))))

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

(defun my-remove-excess-chars ()
  (when (sit-for 0.1)
    (delete-region (point) (line-beginning-position))
    (remove-hook 'post-command-hook 'my-remove-excess-chars)))

reply via email to

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