Emacs:在启动时从上次会话重新打开缓冲区?

每天我启动emacs并打开前一天打开的完全相同的文件。 有什么我可以添加到init.el文件,所以它会重新打开我上次退出emacs时使用的所有缓冲区?

您可以使用Emacs桌面库 :

您可以使用命令Mx desktop-save手动保存桌面。 您还可以启用在退出Emacs时自动保存桌面,以及在Emacs启动时自动恢复上次保存的桌面:使用自定义缓冲区(请参阅轻松自定义)为将来的会话设置桌面保存模式为t,或添加这个行在你的〜/ .emacs文件中:

(desktop-save-mode 1) 

虽然我怀疑这个问题是在寻找emacs的“桌面”function(见上面的答案),但是Lewap的方法是非常有用的,如果一组文件真的是完全相同的文件集。 事实上,如果人们有不同的经常使用的文件集,可以进一步定义“configuration文件”…例如:

 (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. 

如果您发现在工作时经常在不同的常用文件集之间来回切换,请考虑使用透视图并使用所需的一组常规使用的文件填充每个透视图。

对于存储/恢​​复缓冲区/选项卡(特别是elscreen选项卡):我使用elscreen和我pipe理存储/恢复桌面会话和elscreen选项卡configuration的方式是在我的.emacs文件中的以下代码(使用的名称是不言自明的如果每次emacs启动时都不应该执行存储/恢复function,只需用“(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) tt)) (while (cdr buffers) (switch-to-buffer-other-window (car (cdr buffers))) (setq buffers (cdr buffers))) (setq screens (cdr screens)))))) (elscreen-restore) 

您可以使用以下函数在.emacs文件中打开文件:

(find-file“/ home / me / path-to-file”)

您可以对基本桌面function进行有用的增强。 特别方便(IMO)是在会话期间自动保存桌面的方法,否则,如果系统崩溃,您将与您开始会话的桌面文件卡住 – 如果您倾向于保持Emacs运行多个一天的时间。

http://www.emacswiki.org/emacs/DeskTop

一般来说,维基还提供了有关在会话之间保持数据的有用信息:

http://www.emacswiki.org/emacs/SessionManagement

对于台式电脑,我认为桌面恢复看起来特别有前途,但是我还没有尝试过。

(find-file-noselect "/my/file")会默默地打开它,即不提高缓冲区。 只是说。

编辑这个命令不是交互式的; 为了testing它,你必须评估expression式,例如把光标放在最后一个圆括号之后并且敲击Cx Ce

下调这个并不酷 。 这个命令肯定有效,并且在这个问题的范围之内。