[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Character repeation detection
From: |
Pascal J. Bourguignon |
Subject: |
Re: Character repeation detection |
Date: |
Sun, 09 Mar 2014 18:39:51 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Yuri Khan <yuri.v.khan@gmail.com> writes:
> On Sun, Mar 9, 2014 at 12:47 PM, Tom <adatgyujto@gmail.com> wrote:
>
>> Is there a function or package to detect if a character is typed
>> repeatedly? E.g. if a is typed 3 or more times in a row (aaa...)
>> then call a function.
>>
>> Is there an existing solution for this?
>>
>> It would even be better if it had repetition suppression, that is
>> if I leave my finger on a key so I type a string of a certain character
>> (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa) then after the first 3 repetition
>> the function is called and the rest of the repeated characters are
>> removed from the keyboard buffer.
;; To correct some rebound problem I had with a keyboard, disable
;; two spaces in a row, unless it's preceded by a punctuation, or
;; explicitely requested.
(defun pjb-electric-space-rebound (p)
(interactive "P")
;; (message "p=%S" p)
(cond
((null p)
(let ((recent (recent-keys)))
;; (message "recent=%S"(equal (subseq recent (1- (length recent))) [32]))
(if (equal (subseq recent (- (length recent) 2)) [32 32])
(when (let ((pt (point)))
(when (< (+ (point-min) 2) pt)
(unwind-protect
(progn
(forward-char -2)
(looking-at "[.;!?] "))
(goto-char pt))))
(insert " "))
(insert " "))))
((eq p '-))
((integerp p) (insert (make-string p 32)))
((and (listp p) (integerp (car p))) (insert (make-string (car p) 32)))
(t (error "Unknown raw prefix argument %S" p))))
;; (global-set-key (kbd "SPC") 'pjb-electric-space-rebound)
(defun pjb-electric-ellipsis (p)
"... --> …"
(interactive "P")
(cond
((null p)
(let ((recent (recent-keys)))
(if (and (equal (subseq recent (- (length recent) 2)) [?. ?.])
(equal (buffer-substring (- (point) 2) (point)) ".."))
(progn
(delete-region (- (point) 2) (point))
(insert "…"))
(insert "."))))
((eq p '-))
((integerp p) (insert (make-string p ?.)))
((and (listp p) (integerp (car p))) (insert (make-string (car p) ?.)))
(t (error "Unknown raw prefix argument %S" p))))
(global-set-key (kbd ".") 'pjb-electric-ellipsis)
--
__Pascal Bourguignon__
http://www.informatimago.com/
"Le mercure monte ? C'est le moment d'acheter !"
- Re: Character repeation detection, (continued)
- Re: Character repeation detection, Tom, 2014/03/09
- Re: Character repeation detection, Stefan Monnier, 2014/03/09
- Message not available
- Re: Character repeation detection, Dan Espen, 2014/03/09
- Re: Character repeation detection, Tom, 2014/03/09
- Message not available
- Re: Character repeation detection, Joost Kremers, 2014/03/09
- Re: Character repeation detection, Eric Abrahamsen, 2014/03/09
Re: Character repeation detection, Yuri Khan, 2014/03/09
Message not available
- Re: Character repeation detection,
Pascal J. Bourguignon <=