Emacs: how to bind a key twice?

I use Emacs (23) and I bind a key combination C-.to a function:

(global-set-key (kbd "C-.") 'myfunction)

Is it possible to link a quick "double click" key? For example, I would like to call a function myfunctionwhen entering .quickly twice.

+3
source share
4 answers

There is nothing built in, but you can use this code. Set up variables dc-single-click-cmdand dc-double-click-cmdto the team that you want.

Note: this leads to a slight delay, b / c code must wait a little while to determine if the event was a single or double click.

(defvar dc-single-click-cmd 'dc-example-single-click)
(defvar dc-double-click-cmd 'dc-example-double-click)
(defvar dc-click-timer nil
  "Pending single-click event.")
(defun dc-example-single-click ()
  (interactive)
  (message "A single click just happened."))
(defun dc-example-double-click ()
  (interactive)
  (message "Wait!  I meant double click."))
(defun dc-click-cmd ()
  "Either kick off a single click, or a double click."
  (interactive)
  (if dc-click-timer
      (progn
        (cancel-timer dc-click-timer)
        (setq dc-click-timer nil)
        (call-interactively dc-double-click-cmd))
    (setq dc-click-timer (run-at-time (when double-click-time 
                                            (/ 1000.0 double-click-time))
                                      nil
                                      'dc-call-single-click))))
(defun dc-call-single-click ()
  "spawn the single click"
  (setq dc-click-timer nil)
  (call-interactively dc-single-click-cmd))
+5
source

KeyChord - .

( : KeyChord (), , , , , .)

+2

(defun myfunction2 () (Interactive) (if (not (eq last-command 'myfunction2)) (insert ".") (setq this-command no) (delete-backward-char 1) (call-interactiveively) myfunction)) )

(defun myfunction () (Interactive) (message "MYFUNCTION"))

(global key set "." myfunction2)

0
source

https://github.com/k-talo/double-type.el offers similar functionality to what you are looking for.

0
source

Source: https://habr.com/ru/post/1790493/


All Articles