我正在使用 Emacs (23),并且我将
C-.
组合键绑定到一个函数:
(global-set-key (kbd "C-.") 'myfunction)
是否可以绑定快速“双击”按键?例如,我想在快速输入
myfunction
两次时调用函数 .
。
没有任何内置内容,但您可以使用此代码。 将变量
dc-single-click-cmd
和 dc-double-click-cmd
自定义为您想要的命令。
注意:这会带来轻微的延迟,因为代码需要等待一点时间才能确定事件是单击还是双击。
(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))
我相信KeyChord是当今这个问题的规范解决方案。
(免责声明:我自己还没有使用 KeyChord,但很多人都用过,所以我确信它至少值得尝试。)
https://github.com/k-talo/double-type.el提供与您正在寻找的类似的功能。
(defun myfunction2 ()
(interactive)
(if (not (eq last-command 'myfunction2))
(insert ".")
(setq this-command nil)
(delete-backward-char 1)
(call-interactively 'myfunction)))
(defun myfunction ()
(interactive)
(message "MYFUNCTION"))
(global-set-key "." 'myfunction2)