Emacs:在启动时从上次会话重新打开缓冲区?
每天我启动emacs并打开前一天打开的完全相同的文件。有什么我可以添加到init.el文件,所以它会重新打开我上次退出emacs时使用的所有缓冲区?Emacs:在启动时从上次会话重新打开缓冲区?
您可以保存在桌面与 手动命令M-X桌面保存。您可以 也使 桌面自动保存,当你退出Emacs,并 最后 保存的桌面自动恢复Emacs启动时:使用 的定制缓冲液(见易 定制)设置 桌面节省模式来t代表未来 会议,或在您的 〜/ .emacs文件中加入这一行:
(desktop-save-mode 1)
您可以使用下面的函数在你的.emacs文件中打开文件:
(find-file“/ home/me/path-to-file”)
根据你的解决方案,提问者应该每次都在她的dotemacs中输入最近打开的文件名。不是很有希望。 – 2009-04-30 08:29:45
虽然我怀疑这个问题是在寻找emacs的“桌面”功能(参见上面的答案),但Lewap的方法可能是有用的,一套使用的文件确实是完全相同的文件集。事实上,我们可以走得更远了一步,定义“配置文件”如果一个人有不同的组经常使用的文件...晨间例如:
(let ((profile
(read-from-minibuffer "Choose a profile (acad,dist,lisp,comp,rpg): ")
))
(cond
((string-match "acad" profile)
(dired "/home/thomp/acad")
(dired "/home/thomp/acad/papers")
)
((string-match "lisp" profile)
(setup-slime)
(lisp-miscellany)
(open-lisp-dirs)
)
((string-match "rpg" profile)
(find-file "/home/thomp/comp/lisp/rp-geneval/README")
(dired "/home/thomp/comp/lisp/rp-geneval/rp-geneval")
... etc.
如果你发现你经常来回切换不同套之间在您工作时经常使用的文件,请考虑使用perspectives并使用所需的一组常规使用的文件填充每个透视图。
您可以对基本桌面功能进行有用的增强。特别方便的(IMO)是在会话期间自动保存桌面的方法,否则,如果系统崩溃,您将与您开始会话的桌面文件卡住 - 如果您倾向于保持Emacs运行多个每天一次。
http://www.emacswiki.org/emacs/DeskTop
维基也有对一般会话之间持久化数据的有用信息:
http://www.emacswiki.org/emacs/SessionManagement
对于台式机而言,我认为Desktop Recover看起来特别有前途的,但是我还没试过了。
(find-file-noselect "/my/file")
会默默打开它,即不提高缓冲区。只是说。
编辑这条命令是不是 interactive;为了测试它,你必须评估表达式,例如通过将光标定位在最后一个括号之后并击中C-x C-e
下调这个是不是很酷;这个命令绝对有效,并且在这个问题的范围之内。
对于存储/恢复缓冲器/标签(特别是elscreen选项卡):我用elscreen和我管理存储的方式/恢复桌面会话和elscreen卡配置是在我的.emacs文件中的以下代码(所使用的名称是不言自明的,如果每次启动emacs时都不应执行存储/恢复功能,只需用“(push#'elscreen-store kill-emacs-hook)”和“(elscreen-restore)”注释行):
(defvar emacs-configuration-directory
"~/.emacs.d/"
"The directory where the emacs configuration files are stored.")
(defvar elscreen-tab-configuration-store-filename
(concat emacs-configuration-directory ".elscreen")
"The file where the elscreen tab configuration is stored.")
(defun elscreen-store()
"Store the elscreen tab configuration."
(interactive)
(if (desktop-save emacs-configuration-directory)
(with-temp-file elscreen-tab-configuration-store-filename
(insert (prin1-to-string (elscreen-get-screen-to-name-alist))))))
(push #'elscreen-store kill-emacs-hook)
(defun elscreen-restore()
"Restore the elscreen tab configuration."
(interactive)
(if (desktop-read)
(let ((screens (reverse
(read
(with-temp-buffer
(insert-file-contents elscreen-tab-configuration-store-filename)
(buffer-string))))))
(while screens
(setq screen (car (car screens)))
(setq buffers (split-string (cdr (car screens)) ":"))
(if (eq screen 0)
(switch-to-buffer (car buffers))
(elscreen-find-and-goto-by-buffer (car buffers) t t))
(while (cdr buffers)
(switch-to-buffer-other-window (car (cdr buffers)))
(setq buffers (cdr buffers)))
(setq screens (cdr screens))))))
(elscreen-restore)
似乎在Emacs 21和22+中桌面处理有所不同。该主题在此页面上进行了描述:http://www.emacswiki.org/emacs/DeskTop。 – hji 2009-06-08 12:53:30