Last active
July 22, 2016 13:37
-
-
Save jidaikobo-shibata/35b4d739a149f70e86298f71e5b1f9e7 to your computer and use it in GitHub Desktop.
Emacs(Elisp): Preserve last buffers and its each point to reopen. 終了時のバッファとポイントを記憶して、起動時に同じ状態で開くelispです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; ------------------------------------------------------------ | |
;;; 起動時には最後に作業していたファイルを開く | |
;; gist-description: Emacs(Elisp): Preserve last buffers and its each point to reopen. 終了時のバッファとポイントを記憶して、起動時に同じ状態で開くelispです。 | |
;; gist-id: 35b4d739a149f70e86298f71e5b1f9e7 | |
;; gist-name: preserve-last-buffers-and-point.el | |
;; gist-private: nil | |
(defvar my-hist-dir (expand-file-name "~/.emacs.d/histories/")) | |
(defvar my-hist-last-files (concat my-hist-dir "last-files")) | |
(add-hook 'kill-emacs-hook | |
(lambda () | |
(let ((strings "") | |
buf-path) | |
(with-temp-buffer | |
(dolist (buf (buffer-list)) | |
(save-current-buffer | |
(setq buf-path (buffer-file-name buf)) | |
(when (and buf-path (file-exists-p buf-path)) | |
(set-buffer buf) | |
(setq strings | |
(concat strings "\n" buf-path ":" (number-to-string (point))))))) | |
(insert (string-trim strings)) | |
(write-file my-hist-last-files))))) | |
(when (file-exists-p my-hist-last-files) | |
(let (tmp | |
path | |
pt | |
(files (split-string | |
(with-temp-buffer | |
(insert-file-contents my-hist-last-files) | |
(buffer-string)) | |
"\n"))) | |
(when files | |
(dolist (file files) | |
(setq tmp (split-string file ":")) | |
(setq path (car tmp)) | |
(setq pt (string-to-number(car (reverse tmp)))) | |
(when (file-exists-p path) | |
(find-file path) | |
(goto-char pt)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment