dotemacs

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

commit 51d34e97dd4d7a15df49f80de4f666823224d266
parent 51fc131a05ca7d1a2eef9e874d29a2d40a4daf2a
Author: Lukas Henkel <lh@entf.net>
Date:   Fri,  3 Sep 2021 20:32:09 +0200

Safer buffer killing

Diffstat:
Mconfig.org | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/config.org b/config.org @@ -130,6 +130,28 @@ Doesn't have a default keybinding. #+begin_src emacs-lisp (global-set-key (kbd "C-x C-M-t") #'transpose-regions) #+end_src +** Killing the current buffer +There is a button in the toolbar to kill the current buffer, but there is no default keybinding. Also, I'd like for it to confirm if I have any unsaved changes. +#+begin_src emacs-lisp + (require 'seq) + + (defun lh/kill-this-buffer () + "Kills the current buffer, asks for confirmation if there are any unsaved changes" + (interactive) + (when (if (buffer-modified-p) + (y-or-n-p "Buffer has unsaved changes, are you sure? ") + t) + (kill-this-buffer))) + + (global-set-key (kbd "C-x K") #'lh/kill-this-buffer) + + ; Not sure if there is a better way to do this... + (let ((kill-menu (car (seq-filter (lambda (x) + (eq (cadddr x) #'kill-this-buffer)) + (cdr tool-bar-map))))) + (unless (null kill-menu) + (setf (cadddr kill-menu) #'lh/kill-this-buffer))) +#+end_src * Dependencies ** request #+begin_src emacs-lisp