这两天我在考虑emacs daemon下的布局保存与恢复。
最后选择了 easysession 和 activities ,前者用于保存整体的会话加载并在多个会话间切换,后者可以依据需要选择性的载入项目并恢复到对应的tab-bar中。这样尽可能的减小了一次性恢复过多buffer和布局的缺陷,还保留了很大程度的方便性和灵活性。
此前 desktop.el 与 easysession 在daemon 下都存在无法恢复布局的问题和相关Bug,但在与 easysession 项目的维护者 jamescherti 进行交流后已修复,现在其可以在 non-daemon 和 daemon 模式提供相当一致的且舒适的会话恢复与切换体验,大伙可以试试,我个人感觉很棒。
在 jamescherti 的建议下我将 desktop.el 的问题反馈给了 emacs 开发人员,得到了 Eli Zaretskii 的回复以及他给出的patch,我测试后得到了预期效果,现在该patch应该已经被合并到 emacs master 分支。
相关 Issue 可以查看在这个链接中查看https://github.com/jamescherti/easysession.el/issues/52
大伙可以猛猛用 emacs daemon 了
patch:
diff --git a/lisp/desktop.el b/lisp/desktop.el
index 7496103..436644c 100644
--- a/lisp/desktop.el
+++ b/lisp/desktop.el
@@ -1064,7 +1064,10 @@ desktop-file-name
;; ----------------------------------------------------------------------------
(defun desktop--check-dont-save (frame)
- (not (frame-parameter frame 'desktop-dont-save)))
+ (and (not (frame-parameter frame 'desktop-dont-save))
+ (not (and (daemonp)
+ (equal (terminal-name (frame-terminal frame))
+ "initial_terminal")))))
(defconst desktop--app-id `(desktop . ,desktop-file-version))
diff --git a/lisp/frameset.el b/lisp/frameset.el
index 85a90f6..a822b0d 100644
--- a/lisp/frameset.el
+++ b/lisp/frameset.el
@@ -1362,9 +1362,15 @@ frameset-restore
;; Clean up the frame list
(when cleanup-frames
(let ((map nil)
- (cleanup (if (eq cleanup-frames t)
- (lambda (frame action)
- (when (memq action '(:rejected :ignored))
+ (cleanup
+ (if (eq cleanup-frames t)
+ (lambda (frame action)
+ (when (and (memq action '(:rejected :ignored))
+ (not
+ (and (daemonp)
+ (equal (terminal-name (frame-terminal
+ frame))
+ "initial_terminal"))))
(delete-frame frame)))
cleanup-frames)))
(maphash (lambda (frame _action) (push frame map)) frameset--action-map)