dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

lh-resurrect.el (961B)


      1 ;; -*- lexical-binding: t; -*-
      2 
      3 (defgroup lh/resurrect nil
      4   "Records killed buffers and allows them to be resurrected."
      5   :group 'convenience
      6   :prefix "lh/resurrect")
      7 
      8 (defvar lh/resurrect-recently-killed nil)
      9 
     10 (defvar lh/resurrect-mode-map
     11   (let ((map (make-sparse-keymap)))
     12     (define-key map (kbd "C-x R") #'lh/resurrect-latest)
     13     map))
     14 
     15 (defun lh/resurrect--kill-buffer-hook ()
     16   (when buffer-file-name
     17     (push buffer-file-name lh/resurrect-recently-killed)))
     18 
     19 (defun lh/resurrect-latest ()
     20   (interactive)
     21   (when-let (fn (pop lh/resurrect-recently-killed))
     22     (find-file fn)))
     23 
     24 (define-minor-mode lh/global-resurrect-mode
     25   "Records killed buffers and allows them to be resurrected."
     26   :global t
     27   :group 'lh/resurrect
     28   :keymap lh/resurrect-mode-map
     29   (if lh/global-resurrect-mode
     30       (add-hook 'kill-buffer-hook #'lh/resurrect--kill-buffer-hook)
     31     (remove-hook 'kill-buffer-hook #'lh/resurrect--kill-buffer-hook)))
     32 
     33 (provide 'lh-resurrect)