Implement buffer-kill undoing

`C-x k` now kills the current buffer without a question. `C-x M-k` undoes it.
This commit is contained in:
Gergely Polonkai 2016-11-21 11:40:02 +01:00
parent 0ae7c9f240
commit 11e0e9bb25
2 changed files with 22 additions and 0 deletions

View File

@ -1026,6 +1026,8 @@
("C-d" . delete-current-buffer-file) ("C-d" . delete-current-buffer-file)
("~" . toggle-char-case) ("~" . toggle-char-case)
("|" . toggle-window-split) ("|" . toggle-window-split)
("k" . gpolonkai/kill-this-buffer)
("M-k" . gpolonkai/undo-buffer-kill)
:map isearch-mode-map :map isearch-mode-map
("<C-return>" . isearch-exit-other-end) ("<C-return>" . isearch-exit-other-end)
:map gpolonkai/pers-map :map gpolonkai/pers-map

View File

@ -164,3 +164,23 @@ http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-l
(when (and (eq major-mode 'org-mode) (when (and (eq major-mode 'org-mode)
(= (point) last-pos)) (= (point) last-pos))
(org-end-of-line)))) (org-end-of-line))))
(defvar gpolonkai/last-killed-buffer-file-name
nil
"The last killed buffer. Used by `gpolonkai/kill-this-buffer'
and `gpolonkai/undo-buffer-kill'.")
(defun gpolonkai/kill-this-buffer ()
"Kill the current buffer, but save the buffer file name so it can be undone."
(interactive)
(setq gpolonkai/last-killed-buffer-file-name (buffer-file-name))
(kill-this-buffer))
(defun gpolonkai/undo-buffer-kill ()
"Undo killing the last buffer. Esentially it visits the file again."
(interactive)
(if gpolonkai/last-killed-buffer-file-name
(progn
(find-file gpolonkai/last-killed-buffer-file-name)
(setq gpolonkai/last-killed-buffer-file-name))
(message "The buffer last killed didnt visit a file.")))