gpt4 book ai didi

emacs - 如何使用 'home' 键创建 emacs 键和弦

转载 作者:行者123 更新时间:2023-12-04 00:43:25 25 4
gpt4 key购买 nike

我想按两次“home”键将我带到缓冲区的开头。我无法正确使用语法。以下不起作用,我无法通过谷歌找到答案...

;; key chords
(require 'key-chord)
(key-chord-mode 1)
;(setq key-chord-two-keys-delay 0.2)
;(key-chord-define-global "(home)(home)" 'beginning-of-buffer)
;(key-chord-define-global "[(home)(home)]" 'beginning-of-buffer)
;(key-chord-define-global (home)(home) 'beginning-of-buffer)
;(key-chord-define-global [home][home] 'beginning-of-buffer)

更新:我已经切换到按键组合包,它可以处理多个按键,包括主页键。

最佳答案

听起来像key-chord在这种情况下无济于事,因为 <home>不在其支持的字符范围内。

我相信以下内容应该可以满足您的需求,并且可以轻松地将相同的模式用于其他不受支持的键1:

(defvar my-double-key-timeout 0.25
"The number of seconds to wait for a second key press.")

(defun my-home ()
"Move to the beginning of the current line on the first key stroke,
and to the beginning of the buffer if there is a second key stroke
within `my-double-key-timeout' seconds."
(interactive)
(let ((last-called (get this-command 'my-last-call-time)))
(if (and (eq last-command this-command)
last-called
(<= (time-to-seconds (time-since last-called))
my-double-key-timeout))
(beginning-of-buffer)
(move-beginning-of-line nil)))
(put this-command 'my-last-call-time (current-time)))

(global-set-key (kbd "<home>") 'my-home)

请注意 this-command将评估为 my-home当函数运行时,我们设置 my-last-call-time my-home 上的属性(property)符号,从而巧妙地避免需要维护一个单独的变量来记住上次调用此函数的时间,这使得该函数很好地独立和可重用:要创建另一个类似的函数,您只需更改 (beginning-of-buffer)(move-beginning-of-line nil) .

1 明显的警告是,如果您触发双键行为,两个命令将连续执行,因此不要将此方法用于将要执行的命令成为一个问题。

(相反,优势是我们不会弄乱计时器。)

关于emacs - 如何使用 'home' 键创建 emacs 键和弦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25572489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com