gpt4 book ai didi

emacs - 如何在Emacs中拦截Ctrl-G

转载 作者:行者123 更新时间:2023-12-04 05:05:36 24 4
gpt4 key购买 nike

我有一个Emacs的elisp脚本,如果用户按下Ctrl + G,我想对其进行清理。我使用'read-event'来捕获所有事件,但这不能捕获Ctrl + G。当按Ctrl + G时,它将停止执行。

在XEmacs中,当您调用next-command-event时,它将为您提供所有事件,包括用户按下Ctrl + G时的事件。 Emacs中必须有一些等效项。

最佳答案

您可以使用with-local-quit来确定是否按下了C-g:

根据efunneko的建议,解决了吞咽停止的方法。

(defun my-c-g-test ()
"test catching control-g"
(interactive)
(let ((inhibit-quit t))
(unless (with-local-quit
(y-or-n-p "arg you gonna type C-g?")
t)
(progn
(message "you hit C-g")
(setq quit-flag nil)))))

注意:with-local-quit返回最后一个表达式的值,如果按下 nil,则返回 C-g,因此请确保在未按下 C-g时返回非零的值。我发现 quitting上的elisp文档很有用。一个相关的区域是 nonlocal exits,特别是 unwind-protect ,它不仅适用于退出。

关于emacs - 如何在Emacs中拦截Ctrl-G,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/884498/

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