From 44763451f1a440e2cbbea02a5c20e9a769f42bad Mon Sep 17 00:00:00 2001 From: Jesse Alama Date: Sat, 21 Feb 2009 18:54:13 -0800 Subject: [PATCH] Permit cancelling log edits. * magit.el: Permit cancelling log edits. magit-log-edit-confirm-cancellation: New defcustom. magit-log-edit-map: New keybinding: C-c C-k to cancel the log. magit-log-edit-cancel-log-message: New function. magit-pop-to-log-edit: Indicate that cancellation is possible. --- magit.el | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/magit.el b/magit.el index 808e2449..d0a9ec57 100644 --- a/magit.el +++ b/magit.el @@ -101,6 +101,11 @@ Setting this to nil will make it do nothing, setting it to t will arrange things (const :tag "Immediately" 0) (integer :tag "After this many seconds"))) +(defcustom magit-log-edit-confirm-cancellation nil + "Require acknowledgement before cancelling the log edit buffer." + :group 'magit + :type 'boolean) + (defface magit-header '((t)) "Face for generic header lines. @@ -2167,6 +2172,7 @@ in log buffer." (define-key map (kbd "C-c C-a") 'magit-log-edit-toggle-amending) (define-key map (kbd "M-p") 'log-edit-previous-comment) (define-key map (kbd "M-n") 'log-edit-next-comment) + (define-key map (kbd "C-c C-k") 'magit-log-edit-cancel-log-message) map)) (defvar magit-pre-log-edit-window-configuration nil) @@ -2306,6 +2312,17 @@ Prefix arg means justify as well." (set-window-configuration magit-pre-log-edit-window-configuration) (setq magit-pre-log-edit-window-configuration nil)))) +(defun magit-log-edit-cancel-log-message () + (interactive) + (when (or (not magit-log-edit-confirm-cancellation) + (yes-or-no-p + "Really cancel editing the log (any changes will be lost)?")) + (erase-buffer) + (bury-buffer) + (when magit-pre-log-edit-window-configuration + (set-window-configuration magit-pre-log-edit-window-configuration) + (setq magit-pre-log-edit-window-configuration nil)))) + (defun magit-log-edit-toggle-amending () (interactive) (let* ((fields (magit-log-edit-get-fields)) @@ -2325,7 +2342,7 @@ Prefix arg means justify as well." (pop-to-buffer buf) (setq default-directory dir) (magit-log-edit-mode) - (message "Type C-c C-c to %s." operation))) + (message "Type C-c C-c to %s (C-c C-k to cancel)." operation))) (defun magit-log-edit () (interactive)