[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

`kill-buffer-and-window' is too noisy (patch)

From: Paul Pogonyshev
Subject: `kill-buffer-and-window' is too noisy (patch)
Date: Sat, 30 Aug 2003 17:22:46 +0000
User-agent: KMail/1.5.9

`kill-buffer-and-window' currently has a strange behaviour.  It asks user
whether to kill the buffer even if it is not modified, while `kill-buffer'
does not.

When the buffer is modified, the situation is even worse. First,
`kill-buffer-and-window' asks if to kill the buffer.  Then it deletes the
selected window thus hiding the buffer and then another question pops up:
`kill-buffer' has discovered the buffer is modified and asks if to kill it
again (and the buffer itself is hidden by now)!

The patch below must fix both problems.  I kept the order of killing
(first window, then buffer) using a hook.

Even if the window cannot be deleted, the buffer will be killed.  It seems
to be more logical, since otherwise `kill-buffer' queries may be ignored.

2003-08-30  Paul Pogonyshev  <address@hidden>

        * window.el (kill-buffer-and-window): Remove `yes-or-no-p' so that
        the function is less noisy.  Now only `kill-buffer' can ask

--- window.el.~1.89.~   2003-02-04 12:15:11.000000000 +0000
+++ window.el   2003-08-30 17:13:01.000000000 +0000
@@ -532,11 +532,18 @@ Return non-nil if the window was shrunk.
 (defun kill-buffer-and-window ()
   "Kill the current buffer and delete the selected window."
-  (if (yes-or-no-p (format "Kill buffer `%s'? " (buffer-name)))
-      (let ((buffer (current-buffer)))
-       (delete-window (selected-window))
-       (kill-buffer buffer))
-    (error "Aborted")))
+  (let ((window-to-delete (selected-window))
+       (delete-window-hook (lambda ()
+                             (condition-case nil
+                                 (delete-window)
+                               (error nil)))))
+    (add-hook 'kill-buffer-hook delete-window-hook t t)
+    (if (kill-buffer (current-buffer))
+       ;; If `delete-window' failed before, we rerun it to regenerate
+       ;; the error so it can be seen in the minibuffer.
+       (when (eq (selected-window) window-to-delete)
+         (delete-window))
+      (remove-hook 'kill-buffer-hook delete-window-hook t))))
 (defun quit-window (&optional kill window)
   "Quit the current buffer.  Bury it, and maybe delete the selected frame.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]