Emacs:如何绑定点击两次的按键?

问题描述 投票:0回答:4

我正在使用 Emacs (23),并且我将

C-.
组合键绑定到一个函数:

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

是否可以绑定快速“双击”按键?例如,我想在快速输入

myfunction
两次时调用函数
.

emacs
4个回答
6
投票

没有任何内置内容,但您可以使用此代码。 将变量

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

2
投票

我相信KeyChord是当今这个问题的规范解决方案。

(免责声明:我自己还没有使用 KeyChord,但很多人都用过,所以我确信它至少值得尝试。)


0
投票

https://github.com/k-talo/double-type.el提供与您正在寻找的类似的功能。


0
投票
(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)
© www.soinside.com 2019 - 2024. All rights reserved.