mlf176f2 pushed a commit to branch externals/ergoemacs-mode in repository elpa.
commit 87480c19f9b7c9ff24c249de9c1de413ec4a0084 Author: Matthew L. Fidler <[email protected]> Date: Mon Jun 23 08:37:08 2014 -0500 Clean up open last closed buffer. (Issue #237) --- ergoemacs-functions.el | 21 ++++++++++++++------- ergoemacs-mode.el | 2 ++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ergoemacs-functions.el b/ergoemacs-functions.el index a210229..ea6ef26 100644 --- a/ergoemacs-functions.el +++ b/ergoemacs-functions.el @@ -1267,6 +1267,14 @@ by `ergoemacs-maximum-number-of-files-to-open'. ;; status to offer save ;; This custome kill buffer is close-current-buffer. (defvar ergoemacs-single-command-keys) +(defun ergoemacs-save-buffer-to-recently-closed () + "If the buffer is a file, add the path to the list `ergoemacs-recently-closed-buffers'" + (when (not (equal buffer-file-name nil)) + (setq ergoemacs-recently-closed-buffers + (cons (cons (buffer-name) (buffer-file-name)) ergoemacs-recently-closed-buffers)) + (when (> (length ergoemacs-recently-closed-buffers) ergoemacs-recently-closed-buffers-max) + (setq ergoemacs-recently-closed-buffers (butlast ergoemacs-recently-closed-buffers 1))))) + (declare-function ergoemacs-get-override-function "ergoemacs-shortcuts.el") (declare-function minibuffer-keyboard-quit "delsel.el") (declare-function org-edit-src-save "org-src.el") @@ -1280,7 +1288,6 @@ Similar to (kill-buffer (current-buffer)) with the following addition: • If the buffer is editing a source file in an org-mode file, prompt the user to save before closing. • If the buffer is editing a CAPTUREd task in an org-mode file, prompt the user to save before closing. • If the buffer is editing a magit commit, prompt the user to save the commit before closing. -• If the buffer is a file, add the path to the list `ergoemacs-recently-closed-buffers'. • If it is the minibuffer, exit the minibuffer A emacs buffer is one who's name starts with *. @@ -1328,11 +1335,6 @@ Else it is a user buffer." (org-edit-src-save) (set-buffer-modified-p nil))) ;; save to a list of closed buffer - (when (not (equal buffer-file-name nil)) - (setq ergoemacs-recently-closed-buffers - (cons (cons (buffer-name) (buffer-file-name)) ergoemacs-recently-closed-buffers)) - (when (> (length ergoemacs-recently-closed-buffers) ergoemacs-recently-closed-buffers-max) - (setq ergoemacs-recently-closed-buffers (butlast ergoemacs-recently-closed-buffers 1)))) (kill-buffer (current-buffer)) ;; if emacs buffer, switch to a user buffer (if (string-match "^*" (buffer-name)) @@ -1344,7 +1346,12 @@ Else it is a user buffer." (defun ergoemacs-open-last-closed () "Open the last closed file." (interactive) - (find-file (cdr (pop ergoemacs-recently-closed-buffers)) ) ) + (let ((file (cdr (pop ergoemacs-recently-closed-buffers)))) + (if file + (if (file-exists-p file) + (find-file file) + (error "File %s seems to have been deleted." file)) + (error "No recent file has been closed")))) ;;; Text scaling functions (defun ergoemacs-text-scale-normal-size () diff --git a/ergoemacs-mode.el b/ergoemacs-mode.el index d0f15ff..0b48376 100644 --- a/ergoemacs-mode.el +++ b/ergoemacs-mode.el @@ -478,6 +478,7 @@ bindings the keymap is: (ergoemacs-enable-c-advices) (setq ergoemacs-unbind-keys t) (add-hook 'pre-command-hook 'ergoemacs-pre-command-hook) + (add-hook 'kill-buffer-hook 'ergoemacs-save-buffer-to-recently-closed) (ergoemacs-populate-pre-command-hook) (ergoemacs-debug-heading "Ergoemacs-mode turned ON.")) ;; turn off ergoemacs-mode @@ -499,6 +500,7 @@ bindings the keymap is: (when am (set am ergoemacs-old-ns-alternate-modifier)))) (remove-hook 'pre-command-hook 'ergoemacs-pre-command-hook) + (remove-hook 'kill-buffer-hook 'ergoemacs-save-buffer-to-recently-closed) (ergoemacs-populate-pre-command-hook t) ;; Revert `substitute-command-keys' and `completing-read' (ergoemacs-enable-c-advices 'disable)
