Emacsclient钩杀 [英] Emacsclient hook on kill

查看:187
本文介绍了Emacsclient钩杀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Emacs中找到一个钩子,Emacs将在emacs服务器正常关闭之前正常启动。
我尝试过kill-emacs-query-functions,kill-emacs-hook,使用elisp的服务器完成钩子,如:

 (add-hook'server-done-hook 
'(lambda()
(savehist-save)


...但是当操作系统关闭时,不会调用它们,因此历史记录不会保存。



也许有人可以提示?



PS我在Gentoo Linux,emacs-vcs-23.2.9999包,只有终端。为了测试所需的行为,使用start-stop-daemon实用程序停止Emacs。

解决方案

在Emacs关闭之前运行某些东西的正确位置如果你想要取消关机或者$ code> kill-emacs-hook kill-emacs-query-function >如果没有。您所面临的问题是,您的操作系统不会通知Emacs以Emacs理解的方式正常关闭,或者以其他方式查看,Emacs不了解您的操作系统的要求,优雅地完成。



从外部关闭Emacs 23的一种优雅方式是运行 emacsclient -n -e'(kill-emacs)' 。这显然不是一个通用的方法来告诉程序正常关闭。



正常的方式在unix上正常关闭进程是发送SIGHUP或SIGTERM信号。不幸的是,Emacs几乎将所有的信号视为致命的,只有在接收到它时才运行紧急自动保存,没有lisp代码。这不能从lisp配置。 请求不同的行为,但拒绝了



部分解决方法(在这里找到)是在 delete-frame-functions 中运行会话保存挂钩。这个钩子很可能在系统关机序列之前运行,无论是关闭最后一个帧还是在X服务器死机时(如果在终端中运行Emacs,将其连接到终端)。确保您不要在 delete-frame-functions 中运行杀死服务器的挂钩。



由方式,如果要使用这个确切的钩子,请注意,您的代码是一种复杂的写入方式(add-hook'server-done-hook'savehist-save) ,因为在 kill-emacs-hook 中已经有 savehist-autosave


I am trying to find a hook in Emacs, which should fire right before emacs server graceful shutdown. I tried kill-emacs-query-functions, kill-emacs-hook, server-done-hook with elisp like :

(add-hook 'server-done-hook
          '(lambda ()
             (savehist-save)
             )
          )

... but none of them is called when OS shuts down, so history is not saved.

Maybe someone could give a hint?

P.S. I am on Gentoo Linux, emacs-vcs-23.2.9999 package, terminal only. For testing desired behaviour Emacs is stopped using start-stop-daemon utility.

解决方案

The right place to run something before Emacs shuts down is either kill-emacs-query-function if you want to be able to cancel the shutdown or kill-emacs-hook if you don't. The problem you're facing is that your OS does not notify Emacs to shut down gracefully in a way that Emacs understands, or to look at it the other way, Emacs does not understand your OS's request to suht down gracefully.

A graceful way of shutting down Emacs 23 from the outside is to run emacsclient -n -e '(kill-emacs)'. That's obviously not a generic way of telling a program to shut down gracefully.

The normal way to shut down a process gracefully on unix is to send it a SIGHUP or SIGTERM signal. Unfortunately, Emacs treats almost all signals as fatal, and only runs an emergency auto save and no lisp code when it receives them. This is not configurable from lisp. A different behavior has been requested, but turned down.

A partial workaround (found here) is to run session saving hooks in delete-frame-functions. This hook is likely to be run before the system shutdown sequence, either when you close your last frame or when the X server dies (taking your terminals with them if you run Emacs in a terminal). Make sure you don't run the hook that kills the server in delete-frame-functions.

By the way, if you were going to use this exact hook, note that your code is a complicated way of writing (add-hook 'server-done-hook 'savehist-save), and that's not useful since there's already savehist-autosave in kill-emacs-hook.

这篇关于Emacsclient钩杀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆