comparison src/window.c @ 1207:02cf044d5fce

[xemacs-hg @ 2003-01-14 16:54:02 by michaels] 2003-01-11 Mike Sperber <mike@xemacs.org> * window.c (Fdelete_window): Make sure that f->last_nonminibuf_window is set to a live window once we're done. (contains_window): Abstract this code out of Fdelete_window. 2003-01-10 Mike Sperber <mike@xemacs.org> * window.c (Fdelete_other_windows): Prevent crash for combination windows.
author michaels
date Tue, 14 Jan 2003 16:54:03 +0000
parents e22b0213b713
children cd0abfdb9e9d
comparison
equal deleted inserted replaced
1206:d213714eb925 1207:02cf044d5fce
2148 2148
2149 w->dead = 1; 2149 w->dead = 1;
2150 note_object_deleted (wrap_window (w)); 2150 note_object_deleted (wrap_window (w));
2151 } 2151 }
2152 2152
2153 /* Check if window contains pwindow. */
2154
2155 static int
2156 contains_window (Lisp_Object window, Lisp_Object pwindow)
2157 {
2158 while (!NILP (pwindow))
2159 {
2160 if (EQ (window, pwindow))
2161 return 1;
2162 pwindow = XWINDOW (pwindow)->parent;
2163 }
2164 return 0;
2165 }
2166
2153 DEFUN ("delete-window", Fdelete_window, 0, 2, "", /* 2167 DEFUN ("delete-window", Fdelete_window, 0, 2, "", /*
2154 Remove WINDOW from the display. Default is selected window. 2168 Remove WINDOW from the display. Default is selected window.
2155 If window is the only one on its frame, the frame is deleted as well. 2169 If window is the only one on its frame, the frame is deleted as well.
2156 Normally, you cannot delete the last non-minibuffer-only frame (you must 2170 Normally, you cannot delete the last non-minibuffer-only frame (you must
2157 use `save-buffers-kill-emacs' or `kill-emacs'). However, if optional 2171 use `save-buffers-kill-emacs' or `kill-emacs'). However, if optional
2224 Note that we could be dealing with a non-leaf window 2238 Note that we could be dealing with a non-leaf window
2225 where the selected window is one of our children. 2239 where the selected window is one of our children.
2226 So, we check by scanning all the ancestors of the 2240 So, we check by scanning all the ancestors of the
2227 frame's selected window and comparing each one with 2241 frame's selected window and comparing each one with
2228 WINDOW. */ 2242 WINDOW. */
2229 { 2243 if (contains_window (window, FRAME_SELECTED_WINDOW (f)))
2230 Lisp_Object pwindow; 2244 {
2231 2245 Lisp_Object alternative;
2232 pwindow = FRAME_SELECTED_WINDOW (f); 2246 alternative = Fnext_window (window, Qlambda, Qnil, Qnil);
2233 2247
2234 while (!NILP (pwindow)) 2248 /* #### */
2235 { 2249 /* If we're about to delete the selected window on the
2236 if (EQ (window, pwindow)) 2250 selected frame, then we should use Fselect_window to select
2237 break; 2251 the new window. On the other hand, if we're about to
2238 pwindow = XWINDOW (pwindow)->parent; 2252 delete the selected window on any other frame, we shouldn't do
2239 } 2253 anything but set the frame's selected_window slot. */
2240 2254 if (EQ (frame, Fselected_frame (Qnil)))
2241 if (EQ (window, pwindow)) 2255 Fselect_window (alternative, Qnil);
2242 { 2256 else
2243 /* OK, we found it. */ 2257 set_frame_selected_window (f, alternative);
2244 Lisp_Object alternative; 2258 }
2245 alternative = Fnext_window (window, Qlambda, Qnil, Qnil); 2259
2246 2260 /* Some display parameters (gutter display specifically) depend on
2247 /* If we're about to delete the selected window on the 2261 FRAME_LAST_NONMINIBUF (f) to be set to a live window. Ensure that. */
2248 selected frame, then we should use Fselect_window to select 2262 if (contains_window (window, FRAME_LAST_NONMINIBUF_WINDOW (f)))
2249 the new window. On the other hand, if we're about to 2263 f->last_nonminibuf_window = Fnext_window (window, Qlambda, Qnil, Qnil);
2250 delete the selected window on any other frame, we shouldn't do
2251 anything but set the frame's selected_window slot. */
2252 if (EQ (frame, Fselected_frame (Qnil)))
2253 Fselect_window (alternative, Qnil);
2254 else
2255 set_frame_selected_window (f, alternative);
2256 }
2257 }
2258 2264
2259 /* w->buffer is nil in a non-leaf window; in this case, 2265 /* w->buffer is nil in a non-leaf window; in this case,
2260 get rid of the markers we maintain that point into that buffer. */ 2266 get rid of the markers we maintain that point into that buffer. */
2261 if (!NILP (w->buffer)) 2267 if (!NILP (w->buffer))
2262 { 2268 {
3192 value is reasonable when this function is called. 3198 value is reasonable when this function is called.
3193 */ 3199 */
3194 (window)) 3200 (window))
3195 { 3201 {
3196 struct window *w = decode_window (window); 3202 struct window *w = decode_window (window);
3197 struct buffer *b = XBUFFER (w->buffer); 3203 struct buffer *b;
3198 Charbpos start_pos; 3204 Charbpos start_pos;
3199 int old_top = WINDOW_TOP (w); 3205 int old_top = WINDOW_TOP (w);
3200 3206
3207 if (NILP (WINDOW_BUFFER (w)))
3208 invalid_operation ("Can't delete other windows of combination", window);
3209
3201 window = wrap_window (w); 3210 window = wrap_window (w);
3211 b = XBUFFER (WINDOW_BUFFER (w));
3202 3212
3203 if (MINI_WINDOW_P (w) && old_top > 0) 3213 if (MINI_WINDOW_P (w) && old_top > 0)
3204 invalid_operation ("Can't expand minibuffer to full frame", Qunbound); 3214 invalid_operation ("Can't expand minibuffer to full frame", Qunbound);
3205 3215
3206 /* Ignore dedicated windows. */ 3216 /* Ignore dedicated windows. */