我每天都启动emacs并打开前一天打开的完全相同的文件.有什么我可以添加到init.el文件,所以它将重新打开我上次退出emacs时使用的所有缓冲区?
您可以使用Emacs桌面库:
您可以使用Mx desktop-save命令手动保存桌面.您还可以在退出Emacs时启用自动保存桌面,并在Emacs启动时自动恢复上次保存的桌面:使用自定义缓冲区(请参阅轻松自定义)将桌面保存模式设置为t以供将来的会话使用,或者添加〜/ .emacs文件中的这一行:
(desktop-save-mode 1)
虽然我怀疑问题是寻找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.
如果您发现在工作时经常在不同的常规文件集之间来回切换,请考虑使用透视图并使用所需的常规文件集填充每个透视图.
用于存储/恢复缓冲区/选项卡(特别是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)