aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Rudalics2011-09-08 08:28:37 +0200
committerMartin Rudalics2011-09-08 08:28:37 +0200
commit8b0874b51923c5a21dc5c1e4e1c672d16214e4cf (patch)
tree6bd931158db101e6deefef05221abb92db2c495d
parentdcdc460c01cea51a03392b62416ed637adec80cb (diff)
downloademacs-8b0874b51923c5a21dc5c1e4e1c672d16214e4cf.tar.gz
emacs-8b0874b51923c5a21dc5c1e4e1c672d16214e4cf.zip
Rewrite window/frame auto-deletion code. (Bug#9419) and (Bug#9456)
* window.el (frame-auto-delete): Rename to window-auto-delete. Make it control auto-deletion of windows and/or frames. (window-deletable-p): New argument FORCE. Rewrite conditions for deleting window/frame. (Bug#9419) (switch-to-prev-buffer, replace-buffer-in-windows, quit-window): Rewrite handling of case when window/frame can be deleted. (delete-windows-on): Call window-deletable-p with new FORCE argument t. (Bug#9456)
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/window.el116
2 files changed, 64 insertions, 63 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 9d9d564fa15..c314cdf201d 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12011-09-08 Martin Rudalics <rudalics@gmx.at>
2
3 * window.el (frame-auto-delete): Rename to window-auto-delete.
4 Make it control auto-deletion of windows and/or frames.
5 (window-deletable-p): New argument FORCE. Rewrite conditions
6 for deleting window/frame. (Bug#9419)
7 (switch-to-prev-buffer, replace-buffer-in-windows, quit-window):
8 Rewrite handling of case when window/frame can be deleted.
9 (delete-windows-on): Call window-deletable-p with new FORCE
10 argument t. (Bug#9456)
11
12011-09-07 Chong Yidong <cyd@stupidchicken.com> 122011-09-07 Chong Yidong <cyd@stupidchicken.com>
2 13
3 * help-mode.el (help-mode): Restore autoload. 14 * help-mode.el (help-mode): Restore autoload.
diff --git a/lisp/window.el b/lisp/window.el
index 5272841a9c7..d771f9ffdcd 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -2258,77 +2258,75 @@ and no others."
2258 (next-window base-window (if nomini 'arg) all-frames)))) 2258 (next-window base-window (if nomini 'arg) all-frames))))
2259 2259
2260;;; Deleting windows. 2260;;; Deleting windows.
2261(defcustom frame-auto-delete 'automatic 2261(defcustom window-auto-delete t
2262 "If non-nil, quitting a window can delete its frame. 2262 "If non-nil, quitting a window can delete the window.
2263If this variable is nil, functions that quit a window never 2263If this variable is t, functions that quit a window can delete
2264delete the associated frame. If this variable's value is the 2264the window and, if applicable, the corresponding frame. If it is
2265symbol `automatic', a frame is deleted only if the window is 2265'frame, these functions can delete a window and its frame,
2266dedicated or was created by `display-buffer'. If this variable 2266provided there are no other windows on the frame. If it is
2267is t, a frame can be always deleted, even if it was created by 2267'window, these functions can delete the window, provided there
2268`make-frame-command'. Other values should not be used. 2268are other windows on the corresponding frame. If this variable
2269 2269is nil, functions that quit a window never delete the window or
2270Note that a frame will be effectively deleted if and only if 2270the associated frame.
2271
2272Note that a frame can be effectively deleted if and only if
2271another frame still exists. 2273another frame still exists.
2272 2274
2273Functions quitting a window and consequently affected by this 2275Functions quitting a window and consequently affected by this
2274variable are `switch-to-prev-buffer', `delete-windows-on', 2276variable are `switch-to-prev-buffer' including its callers like
2275`replace-buffer-in-windows' and `quit-window'." 2277`bury-buffer', `replace-buffer-in-windows' and its callers like
2278`kill-buffer', and `quit-window'."
2276 :type '(choice 2279 :type '(choice
2277 (const :tag "Never" nil) 2280 (const :tag "Always" t)
2278 (const :tag "Automatic" automatic) 2281 (const :tag "Window" window)
2279 (const :tag "Always" t)) 2282 (const :tag "Frame" frame)
2280 :group 'windows 2283 (const :tag "Never" nil))
2281 :group 'frames) 2284 :group 'windows)
2282 2285
2283(defun window-deletable-p (&optional window) 2286(defun window-deletable-p (&optional window force)
2284 "Return t if WINDOW can be safely deleted from its frame. 2287 "Return t if WINDOW can be safely deleted from its frame.
2285Return `frame' if deleting WINDOW should also delete its 2288Return `frame' if deleting WINDOW should also delete its
2286frame." 2289frame.
2290
2291Optional argument FORCE non-nil means return non-nil unless
2292WINDOW is the root window of the only visible frame. FORCE nil
2293or omitted means return nil unless WINDOW is either dedicated to
2294its buffer or has no previous buffer to show instead."
2287 (setq window (window-normalize-any-window window)) 2295 (setq window (window-normalize-any-window window))
2296
2288 (unless ignore-window-parameters 2297 (unless ignore-window-parameters
2289 ;; Handle atomicity. 2298 ;; Handle atomicity.
2290 (when (window-parameter window 'window-atom) 2299 (when (window-parameter window 'window-atom)
2291 (setq window (window-atom-root window)))) 2300 (setq window (window-atom-root window))))
2292 (let ((parent (window-parent window)) 2301
2293 (frame (window-frame window)) 2302 (let* ((parent (window-parent window))
2294 (buffer (window-buffer window)) 2303 (frame (window-frame window))
2295 (dedicated (and (window-buffer window) (window-dedicated-p window))) 2304 (buffer (window-buffer window))
2296 (quit-restore (window-parameter window 'quit-restore))) 2305 (dedicated (and (window-buffer window) (window-dedicated-p window)))
2306 ;; prev non-nil means there is another buffer we can show
2307 ;; in WINDOW instead.
2308 (prev (and (window-prev-buffers window)
2309 (or (cdr (window-prev-buffers window))
2310 (not (eq (caar (window-prev-buffers window))
2311 buffer))))))
2297 (cond 2312 (cond
2298 ((frame-root-window-p window) 2313 ((frame-root-window-p window)
2299 ;; Don't delete FRAME if `frame-auto-delete' is nil. 2314 (when (and (or force dedicated
2300 (when (and (or (eq frame-auto-delete t) 2315 (and (not prev) (memq window-auto-delete '(t frame))))
2301 (and (eq frame-auto-delete 'automatic)
2302 ;; Delete FRAME only if it's either dedicated
2303 ;; or quit-restore's car is `new-frame' and
2304 ;; WINDOW still displays the same buffer
2305 (or dedicated
2306 (and (eq (car-safe quit-restore) 'new-frame)
2307 (eq (nth 1 quit-restore)
2308 (window-buffer window))))))
2309 ;; Don't delete FRAME if we have another buffer in
2310 ;; WINDOW's previous buffers. Bug#9419.
2311 (or (not (window-prev-buffers window))
2312 (eq (caar (window-prev-buffers window)) buffer))
2313 ;; Don't try to delete FRAME when there are no other
2314 ;; visible frames left.
2315 (other-visible-frames-p frame)) 2316 (other-visible-frames-p frame))
2317 ;; We can delete WINDOW's frame if (1) either FORCE is non-nil,
2318 ;; WINDOW is dedicated to its buffer, or there are no previous
2319 ;; buffers to show and (2) there are other visible frames left.
2316 'frame)) 2320 'frame))
2317 ;; Don't delete WINDOW if we find another buffer in WINDOW's 2321 ((and (or force dedicated
2318 ;; previous buffers. 2322 (and (not prev) (memq window-auto-delete '(t window))))
2319 ((and (or (not (window-prev-buffers window))
2320 (eq (caar (window-prev-buffers window)) buffer))
2321 ;; Delete WINDOW only if it's dedicated or quit-restore's car
2322 ;; is `new-frame' or `new-window' and it still displays the
2323 ;; same buffer.
2324 (or dedicated
2325 (and (memq (car-safe quit-restore) '(new-window new-frame))
2326 (eq (nth 1 quit-restore) (window-buffer window))))
2327 ;; Don't delete the last main window.
2328 (or ignore-window-parameters 2323 (or ignore-window-parameters
2329 (not (eq (window-parameter window 'window-side) 'none)) 2324 (not (eq (window-parameter window 'window-side) 'none))
2330 (and parent 2325 (and parent
2331 (eq (window-parameter parent 'window-side) 'none)))) 2326 (eq (window-parameter parent 'window-side) 'none))))
2327 ;; We can delete WINDOW if (1) either FORCE is non-nil, WINDOW is
2328 ;; dedicated to its buffer, or there are no previous buffers to
2329 ;; show and (2) WINDOW is not the main window of its frame.
2332 t)))) 2330 t))))
2333 2331
2334(defun window-or-subwindow-p (subwindow window) 2332(defun window-or-subwindow-p (subwindow window)
@@ -2601,11 +2599,7 @@ shall not be switched to in future invocations of this command."
2601 ;; When BURY-OR-KILL is non-nil, there's no previous buffer for 2599 ;; When BURY-OR-KILL is non-nil, there's no previous buffer for
2602 ;; this window, and we can delete the window (or the frame) do 2600 ;; this window, and we can delete the window (or the frame) do
2603 ;; that. 2601 ;; that.
2604 ((and bury-or-kill 2602 ((and bury-or-kill (setq deletable (window-deletable-p window)))
2605 (or (not (window-prev-buffers window))
2606 (and (eq (caar (window-prev-buffers window)) old-buffer)
2607 (not (cdr (car (window-prev-buffers window))))))
2608 (setq deletable (window-deletable-p window)))
2609 (if (eq deletable 'frame) 2603 (if (eq deletable 'frame)
2610 (delete-frame (window-frame window)) 2604 (delete-frame (window-frame window))
2611 (delete-window window))) 2605 (delete-window window)))
@@ -2877,7 +2871,7 @@ frames left."
2877 (all-frames (cond ((not frame) t) ((eq frame t) nil) (t frame)))) 2871 (all-frames (cond ((not frame) t) ((eq frame t) nil) (t frame))))
2878 (dolist (window (window-list-1 nil nil all-frames)) 2872 (dolist (window (window-list-1 nil nil all-frames))
2879 (if (eq (window-buffer window) buffer) 2873 (if (eq (window-buffer window) buffer)
2880 (let ((deletable (window-deletable-p window))) 2874 (let ((deletable (window-deletable-p window t)))
2881 (cond 2875 (cond
2882 ((eq deletable 'frame) 2876 ((eq deletable 'frame)
2883 ;; Delete frame. 2877 ;; Delete frame.
@@ -2913,7 +2907,7 @@ all window-local buffer lists."
2913 ((eq deletable 'frame) 2907 ((eq deletable 'frame)
2914 ;; Delete frame. 2908 ;; Delete frame.
2915 (delete-frame (window-frame window))) 2909 (delete-frame (window-frame window)))
2916 ((and (window-dedicated-p window) deletable) 2910 (deletable
2917 ;; Delete window. 2911 ;; Delete window.
2918 (delete-window window)) 2912 (delete-window window))
2919 (t 2913 (t
@@ -2939,11 +2933,7 @@ one. If non-nil, reset `quit-restore' parameter to nil."
2939 (quit-restore (window-parameter window 'quit-restore)) 2933 (quit-restore (window-parameter window 'quit-restore))
2940 deletable resize) 2934 deletable resize)
2941 (cond 2935 (cond
2942 ((and (or (and (memq (car-safe quit-restore) '(new-window new-frame)) 2936 ((setq deletable (window-deletable-p window))
2943 ;; Check that WINDOW's buffer is still the same.
2944 (eq (window-buffer window) (nth 1 quit-restore)))
2945 (window-dedicated-p window))
2946 (setq deletable (window-deletable-p window)))
2947 ;; Check if WINDOW's frame can be deleted. 2937 ;; Check if WINDOW's frame can be deleted.
2948 (if (eq deletable 'frame) 2938 (if (eq deletable 'frame)
2949 (delete-frame (window-frame window)) 2939 (delete-frame (window-frame window))