branch: elpa/magit
commit 29c6241993797174f89cb9f1a1a62f44c099722b
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>
magit-bury{,-or-kill-}buffer: Offer to quit related Ediff session
Killing a buffer, which is used by an Ediff session, renders that
unusable, so we prevent that. We could just refuse to kill the
buffer and be done with it, but since the user indicated that they
want to quit something, instead offer to quit the whole Ediff session.
Do not first check whether the buffer would only be buried as that
would also make little sense in an Ediff context. (And if the user
really wants to bury the buffer, they can use `bury-buffer'.)
---
lisp/magit-files.el | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/lisp/magit-files.el b/lisp/magit-files.el
index 302eaca012..f34d12c8c4 100644
--- a/lisp/magit-files.el
+++ b/lisp/magit-files.el
@@ -31,6 +31,8 @@
(require 'magit)
+(declare-function ediff-quit "ediff-util" (reverse-default-keep-variants))
+
;;; Find Blob
(define-obsolete-variable-alias 'magit-find-file-hook
@@ -390,18 +392,32 @@ Currently this only adds the following key bindings.
:package-version '(magit . "2.3.0"))
(defun magit-bury-buffer (&optional kill-buffer)
- "Bury the current buffer, or with a prefix argument kill it."
+ "Bury the current buffer, or with a prefix argument kill it.
+
+If the buffer is used by an Ediff session, refuse to kill or bury just
+that buffer. That former would break the session and the latter makes
+little sense in this context. Instead offer to quit the whole session."
(interactive "P")
- (if kill-buffer (kill-buffer) (bury-buffer)))
+ (cond ((bound-and-true-p ediff-this-buffer-ediff-sessions)
+ (ediff-quit nil))
+ (kill-buffer (kill-buffer))
+ ((bury-buffer))))
(defun magit-bury-or-kill-buffer (&optional bury-buffer)
"Bury the current buffer if displayed in multiple windows, else kill it.
-With a prefix argument only bury the buffer even if it is only displayed
-in a single window."
+
+With a prefix argument only bury the buffer even if it is only
+displayed in a single window.
+
+If the buffer is used by an Ediff session, refuse to kill or bury just
+that buffer. That former would break the session and the latter makes
+little sense in this context. Instead offer to quit the whole session."
(interactive "P")
- (if (or bury-buffer (cdr (get-buffer-window-list nil nil t)))
- (bury-buffer)
- (kill-buffer)))
+ (cond ((bound-and-true-p ediff-this-buffer-ediff-sessions)
+ (ediff-quit nil))
+ ((or bury-buffer (cdr (get-buffer-window-list nil nil t)))
+ (bury-buffer))
+ ((kill-buffer))))
(defun magit-kill-this-buffer ()
"Kill the current buffer."