3

防止意外退出Emacs

 3 years ago
source link: https://www.lujun9972.win/blog/2017/04/15/%E9%98%B2%E6%AD%A2%E6%84%8F%E5%A4%96%E9%80%80%E5%87%BAemacs/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

防止意外退出Emacs

不知道你有没有遇到过这样的问题,有时候会不小心按到 C-c C-x,造成Emacs意外退出.

这个时候如果有个提示确认的动作就好了.

通过配置 confirm-kill-emacs 就能够实现这一功能. 关于 confirm-kill-emacs 的说明如下:

How to ask for confirmation when leaving Emacs.
If nil, the default, don’t ask at all.  If the value is non-nil, it should
be a predicate function; for example ‘yes-or-no-p’.

不过如果直接把它设置成 yes-or-no-p 的话,那么每次退出都要按一下 y 才行,又有点麻烦. 最后能设定一个时间,超过这个时间则默认自动退出. 这个行为可以使用 y-or-n-p-timeout 来实现.

;; 为防止不小心按到C-c C-x,在退出Emacs前需要确认
(setq confirm-kill-emacs (lambda (prompt) (y-or-n-p-with-timeout "是否退出Emacs:(" 10 "y")))

这样,在按下 C-c C-x 后Emacs会提示你"是否退出Emacs",这个时候按下 n 则不会退出Emacs,若10秒内没有输入,则自动退出.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK