1

我希望当我右键单击启动器...图标..并选择退出..并选择文件退出时发生这种情况。我希望在 emacs 退出之前运行此命令..所以当我右键单击启动器图标并选择退出然后运行此命令“wg-update-workgroup”然后 Emacs 退出..我已经尝试了解钩子,但不知道如何添加一个....如果有人能给我我放入初始化文件的确切代码,我将非常感激....尝试将函数绑定到一个键,但得到奇怪的命令 p 错误。

4

2 回答 2

2

Here's the code:

(add-hook 'kill-emacs-hook
          (lambda ()
            (wg-update-workgroup)))

UPD

It seems that the code isn't working for you since wg-update-workgroup needs an argument. You have to test this yourself, since I don't really want to get familiar with the package.

Solution 1:

(add-hook 'kill-emacs-hook
          (lambda ()
            (wg-update-all-workgroups)))

Solution 2:

(add-hook 'kill-emacs-hook
          (lambda ()
            (call-interactively 'wg-update-workgroup)))

UPD: disregard everything from above:)

I'm pretty sure this is what you want:

(setq wg-query-for-save-on-emacs-exit nil)
(push (lambda()(or (ignore-errors
            (wg-update-all-workgroups-and-save)) t))
  kill-emacs-query-functions) 

The first statement removes the extremely annoying y/n query about saving workgroups on exit. The second statement saves everything unconditionally on exit.

Just to list my full configuration:

(require 'workgroups)
(workgroups-mode 1)
(setq wg-query-for-save-on-emacs-exit nil)
(wg-load "~/wg")
(push (lambda()(or (ignore-errors
            (wg-update-all-workgroups-and-save)) t))
  kill-emacs-query-functions)
于 2013-09-07T12:33:46.210 回答
1

你感到困惑是对的。问题是这样的:当 Emacs 开始退出时,workgroups.el 会在 'kill-emacs-hook. 你想要的是这样的:

(add-hook 'kill-emacs-query-functions 'wg-update-all-workgroups)

钩子变量应该看起来像这样:

(wg-update-all-workgroups wg-emacs-exit-query)

我建议使用 'wg-update-all-workgroups 而不是 'wg-update-workgroup 如果像我一样,您在给定的工作组文件中保存了多个工作组。

IMO workgroups.el 是最好的 Emacs 会话管理器。刚刚有人接管了它。我很高兴可能即将推出具有更多功能的新版本:

https://github.com/pashinin/workgroups2/

于 2013-09-08T01:41:08.433 回答