Created
August 3, 2010 18:18
-
-
Save nibrahim/506851 to your computer and use it in GitHub Desktop.
Poor mans session management for Emacs
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
; Cheap and dirty session management for Emacs. | |
; Add the location of this file to your load-path, | |
; Do a (require 'nkv-session) in your .emacs | |
; Then hit f9 to load up your session files. | |
; While you work, if you want to remember a file, hit f9 in the buffer. | |
; If you want to remember all the current open buffers, you can simply call nkv/session-save-current-buffers | |
; Whenever you want to save, call nkv/save-session. | |
; Or you can add nkv/save-session to kill-emacs-hook to save the session upon quit automatically. | |
; Next time, hit f9 to reload your files. | |
; | |
; There are better and more robust packages to do this out there. This is just something I did while zoning | |
; out. | |
(setq nkv/session-list '()) | |
(defun nkv/add-to-session-list () | |
(interactive) | |
(if (buffer-file-name) | |
(progn | |
(message (concat "Remembering" (buffer-file-name))) | |
(add-to-list 'nkv/session-list (buffer-file-name))))) | |
(defun nkv/save-session () | |
(interactive) | |
(save-excursion | |
(find-file "~/.emacs-session") | |
(delete-region (point-min) (point-max)) | |
(eval-expression (quote (cons 'setq | |
(cons 'nkv/session-list | |
(list (cons 'quote | |
(list nkv/session-list)))))) | |
t) | |
(save-buffer) | |
(kill-buffer))) | |
(defun nkv/load-session () | |
(interactive) | |
(message "Restoring session") | |
(save-excursion | |
(eval-buffer (find-file "~/.emacs-session")) | |
(dolist (f nkv/session-list) | |
(progn | |
(message (concat "Loading " f)) | |
(find-file f))) | |
(kill-buffer (get-buffer ".emacs-session")))) | |
(defun nkv/session-save-current-buffers () | |
(interactive) | |
(dolist (buf (buffer-list)) | |
(progn | |
(if (buffer-file-name buf) | |
(add-to-list 'nkv/session-list (buffer-file-name buf))))) | |
(nkv/save-session)) | |
(global-set-key (kbd "<f9>") (lambda () (interactive) | |
(nkv/load-session) | |
(global-set-key (kbd "<f9>") 'nkv/add-to-session-list))) | |
(provide 'nkv-session) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment