Subject: Re: bug#24213: 25.1.50; Fishy use of delete-window in register.el

From: Andreas Politz <[email-masked]>
Date: Wed, 31 Aug 2016 21:04:36 +0200

I finally got around to this.  The changes in the following diff seem to
be all clear cut cases, where the window is created by
display-buffer/pop-to-buffer without any special window-handling logic
attached.  Let me know what you think.  

diff --git a/lisp/finder.el b/lisp/finder.el
index da537a5..7f08024 100644
--- a/lisp/finder.el
+++ b/lisp/finder.el
@@ -455,7 +455,7 @@ finder-exit
   "Exit Finder mode.
 Delete the window and kill all Finder-related buffers."
   (interactive)
-  (ignore-errors (delete-window))
+  (quit-window)
   (let ((buf "*Finder*"))
     (and (get-buffer buf) (kill-buffer buf))))
 
diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index 67b023d..36f148b 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -2445,13 +2445,9 @@ image-dired-gallery-generate
       (insert "</html>"))))
 
 (defun image-dired-kill-buffer-and-window ()
-  "Kill the current buffer and, if possible, also the window."
+  "Kill the current buffer and quit it's window."
   (interactive)
-  (let ((buffer (current-buffer)))
-    (condition-case nil
-        (delete-window (selected-window))
-      (error nil))
-    (kill-buffer buffer)))
+  (quit-window t))
 
 (defvar image-dired-widget-list nil
   "List to keep track of meta data in edit buffer.")
diff --git a/lisp/progmodes/idlwave.el b/lisp/progmodes/idlwave.el
index 9cb2ca7..2215e52 100644
--- a/lisp/progmodes/idlwave.el
+++ b/lisp/progmodes/idlwave.el
@@ -8272,7 +8272,7 @@ idlwave-quit-help
       (select-window olh-window)
       (idlwave-help-quit))
     (when (window-live-p ri-window)
-      (delete-window ri-window))))
+      (quit-window nil ri-window))))
 
 (defun idlwave-display-calling-sequence (name type class
 					      &optional initial-class)
diff --git a/lisp/progmodes/verilog-mode.el b/lisp/progmodes/verilog-mode.el
index fd2e96a..a96ddae 100644
--- a/lisp/progmodes/verilog-mode.el
+++ b/lisp/progmodes/verilog-mode.el
@@ -7486,8 +7486,7 @@ verilog-complete-word
 	       (display-completion-list allcomp))
 	     ;; Wait for a key press. Then delete *Completion*  window
 	     (momentary-string-display "" (point))
-	     (delete-window (get-buffer-window (get-buffer "*Completions*")))
-	     )))))
+	     (quit-window nil (get-buffer-window "*Completions*")))))))
 
 (defun verilog-show-completions ()
   "Show all possible completions at current point."
@@ -7506,7 +7505,7 @@ verilog-show-completions
       (display-completion-list allcomp))
     ;; Wait for a key press. Then delete *Completion*  window
     (momentary-string-display "" (point))
-    (delete-window (get-buffer-window (get-buffer "*Completions*")))))
+    (quit-window nil (get-buffer-window "*Completions*"))))

 (defun verilog-get-default-symbol ()
diff --git a/lisp/startup.el b/lisp/startup.el
index fcdc376..0b21f4f 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -1765,9 +1765,7 @@ fancy-startup-tail
 		  (customize-set-variable 'inhibit-startup-screen t)
 		  (customize-mark-to-save 'inhibit-startup-screen)
 		  (custom-save-all))
-		(let ((w (get-buffer-window "*GNU Emacs*")))
-		  (and w (not (one-window-p)) (delete-window w)))
-		(kill-buffer "*GNU Emacs*")))
+		(quit-windows-on "*GNU Emacs*" t)))
      "  ")
     (when (or user-init-file custom-file)
       (let ((checked (create-image "checked.xpm"
diff --git a/lisp/strokes.el b/lisp/strokes.el
index 5a2020d..215f24b 100644
--- a/lisp/strokes.el
+++ b/lisp/strokes.el
@@ -1216,9 +1216,7 @@ strokes-xpm-for-stroke
 
 ;;(defun strokes-edit-quit ()
 ;;  (interactive)
-;;  (or (one-window-p t 0)
-;;      (delete-window))
-;;  (kill-buffer "*Strokes List*"))
+;;  (quit-windows-on "*Strokes List*" t))
 
 ;;(define-derived-mode edit-strokes-mode list-mode
 ;;  "Edit-Strokes"