aboutsummaryrefslogtreecommitdiffstats
path: root/src/window.c
diff options
context:
space:
mode:
authorMartin Rudalics2011-06-06 15:57:49 +0200
committerMartin Rudalics2011-06-06 15:57:49 +0200
commit727e958ef0548f3d8ce02a4a971247f52cc548ce (patch)
tree2b1eb83cafeb3b8c6b337d8fc41451db86f24e98 /src/window.c
parentbf60a96bc62eb465a482f5f95859a1147d0003d8 (diff)
downloademacs-727e958ef0548f3d8ce02a4a971247f52cc548ce.tar.gz
emacs-727e958ef0548f3d8ce02a4a971247f52cc548ce.zip
Move some window-related functions from frame.c to window.c.
* lisp.h: Move EXFUNS for Fframe_root_window, Fframe_first_window and Fset_frame_selected_window to window.h. * window.h: Move EXFUNS for Fframe_root_window, Fframe_first_window and Fset_frame_selected_window here from lisp.h. * frame.c (Fwindow_frame, Fframe_first_window) (Fframe_root_window, Fframe_selected_window) (Fset_frame_selected_window): Move to window.c. (Factive_minibuffer_window): Move to minibuf.c. (Fother_visible_frames_p): New function. * minibuf.c (Factive_minibuffer_window): Move here from frame.c. * window.c (Fwindow_frame): Move here from frame.c. Accept any window as argument. (Fframe_root_window, Fframe_first_window) (Fframe_selected_window): Move here from frame.c. Accept frame or arbitrary window as argument. Update doc-strings. (Fminibuffer_window): Move up in code. (Fwindow_minibuffer_p): Move up in code and simplify. (Fset_frame_selected_window): Move here from frame.c. Marginal rewrite. (Fselected_window, select_window, Fselect_window): Move up in code. Minor doc-string fixes.
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c376
1 files changed, 246 insertions, 130 deletions
diff --git a/src/window.c b/src/window.c
index 894775d6aa3..4e8b98a3237 100644
--- a/src/window.c
+++ b/src/window.c
@@ -168,7 +168,248 @@ A live window is a window that displays a buffer. */)
168{ 168{
169 return WINDOW_LIVE_P (object) ? Qt : Qnil; 169 return WINDOW_LIVE_P (object) ? Qt : Qnil;
170} 170}
171
172/* Frames and windows. */
173DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
174 doc: /* Return the frame that window WINDOW is on.
175WINDOW can be any window and defaults to the selected one. */)
176 (Lisp_Object window)
177{
178 return decode_any_window (window)->frame;
179}
180
181DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
182 doc: /* Return the root window of FRAME_OR_WINDOW.
183If omitted, FRAME_OR_WINDOW defaults to the currently selected frame.
184Else if FRAME_OR_WINDOW denotes any window, return the root window of
185that window's frame. If FRAME_OR_WINDOW denotes a live frame, return
186the root window of that frame. */)
187 (Lisp_Object frame_or_window)
188{
189 Lisp_Object window;
190
191 if (NILP (frame_or_window))
192 window = SELECTED_FRAME ()->root_window;
193 else if (WINDOWP (frame_or_window))
194 window = XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window)))->root_window;
195 else
196 {
197 CHECK_LIVE_FRAME (frame_or_window);
198 window = XFRAME (frame_or_window)->root_window;
199 }
200
201 return window;
202}
203
204DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0,
205 doc: /* Return the window used now for minibuffers.
206If the optional argument FRAME is specified, return the minibuffer window
207used by that frame. */)
208 (Lisp_Object frame)
209{
210 if (NILP (frame))
211 frame = selected_frame;
212 CHECK_LIVE_FRAME (frame);
213 return FRAME_MINIBUF_WINDOW (XFRAME (frame));
214}
215
216DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p,
217 Swindow_minibuffer_p, 0, 1, 0,
218 doc: /* Return non-nil if WINDOW is a minibuffer window.
219WINDOW can be any window and defaults to the selected one. */)
220 (Lisp_Object window)
221{
222 return MINI_WINDOW_P (decode_any_window (window)) ? Qt : Qnil;
223}
224
225/* Don't move this to window.el - this must be a safe routine. */
226DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
227 doc: /* Return the topmost, leftmost live window on FRAME_OR_WINDOW.
228If omitted, FRAME_OR_WINDOW defaults to the currently selected frame.
229Else if FRAME_OR_WINDOW denotes any window, return the first window of
230that window's frame. If FRAME_OR_WINDOW denotes a live frame, return
231the first window of that frame. */)
232 (Lisp_Object frame_or_window)
233{
234 Lisp_Object window;
235
236 if (NILP (frame_or_window))
237 window = SELECTED_FRAME ()->root_window;
238 else if (WINDOWP (frame_or_window))
239 window = XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window)))->root_window;
240 else
241 {
242 CHECK_LIVE_FRAME (frame_or_window);
243 window = XFRAME (frame_or_window)->root_window;
244 }
245
246 while (NILP (XWINDOW (window)->buffer))
247 {
248 if (! NILP (XWINDOW (window)->hchild))
249 window = XWINDOW (window)->hchild;
250 else if (! NILP (XWINDOW (window)->vchild))
251 window = XWINDOW (window)->vchild;
252 else
253 abort ();
254 }
255
256 return window;
257}
258
259DEFUN ("frame-selected-window", Fframe_selected_window,
260 Sframe_selected_window, 0, 1, 0,
261 doc: /* Return the selected window of FRAME_OR_WINDOW.
262If omitted, FRAME_OR_WINDOW defaults to the currently selected frame.
263Else if FRAME_OR_WINDOW denotes any window, return the selected window
264of that window's frame. If FRAME_OR_WINDOW denotes a live frame, return
265the selected window of that frame. */)
266 (Lisp_Object frame_or_window)
267{
268 Lisp_Object window;
269
270 if (NILP (frame_or_window))
271 window = SELECTED_FRAME ()->selected_window;
272 else if (WINDOWP (frame_or_window))
273 window = XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window)))->selected_window;
274 else
275 {
276 CHECK_LIVE_FRAME (frame_or_window);
277 window = XFRAME (frame_or_window)->selected_window;
278 }
279
280 return window;
281}
282
283DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
284 Sset_frame_selected_window, 2, 3, 0,
285 doc: /* Set selected window of FRAME to WINDOW.
286FRAME must be a live frame and defaults to the selected one. If FRAME
287is the selected frame, this makes WINDOW the selected window. Optional
288argument NORECORD non-nil means to neither change the order of recently
289selected windows nor the buffer list. WINDOW must denote a live window.
290Return WINDOW. */)
291 (Lisp_Object frame, Lisp_Object window, Lisp_Object norecord)
292{
293 if (NILP (frame))
294 frame = selected_frame;
295
296 CHECK_LIVE_FRAME (frame);
297 CHECK_LIVE_WINDOW (window);
298
299 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
300 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
301
302 if (EQ (frame, selected_frame))
303 return Fselect_window (window, norecord);
304 else
305 return XFRAME (frame)->selected_window = window;
306}
307
308DEFUN ("selected-window", Fselected_window, Sselected_window, 0, 0, 0,
309 doc: /* Return the selected window.
310The selected window is the window in which the standard cursor for
311selected windows appears and to which many commands apply. */)
312 (void)
313{
314 return selected_window;
315}
316
317/* If select_window is called with inhibit_point_swap non-zero it will
318 not store point of the old selected window's buffer back into that
319 window's pointm slot. This is needed by Fset_window_configuration to
320 avoid that the display routine is called with selected_window set to
321 Qnil causing a subsequent crash. */
322static Lisp_Object
323select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
324{
325 register struct window *w;
326 register struct window *ow;
327 struct frame *sf;
328
329 CHECK_LIVE_WINDOW (window);
330
331 w = XWINDOW (window);
332 w->frozen_window_start_p = 0;
333
334 if (NILP (norecord))
335 {
336 ++window_select_count;
337 XSETFASTINT (w->use_time, window_select_count);
338 record_buffer (w->buffer);
339 }
340
341 if (EQ (window, selected_window) && !inhibit_point_swap)
342 return window;
343
344 sf = SELECTED_FRAME ();
345 if (XFRAME (WINDOW_FRAME (w)) != sf)
346 {
347 XFRAME (WINDOW_FRAME (w))->selected_window = window;
348 /* Use this rather than Fhandle_switch_frame
349 so that FRAME_FOCUS_FRAME is moved appropriately as we
350 move around in the state where a minibuffer in a separate
351 frame is active. */
352 Fselect_frame (WINDOW_FRAME (w), norecord);
353 /* Fselect_frame called us back so we've done all the work already. */
354 eassert (EQ (window, selected_window));
355 return window;
356 }
357 else
358 sf->selected_window = window;
359
360 /* Store the current buffer's actual point into the
361 old selected window. It belongs to that window,
362 and when the window is not selected, must be in the window. */
363 if (!inhibit_point_swap)
364 {
365 ow = XWINDOW (selected_window);
366 if (! NILP (ow->buffer))
367 set_marker_both (ow->pointm, ow->buffer,
368 BUF_PT (XBUFFER (ow->buffer)),
369 BUF_PT_BYTE (XBUFFER (ow->buffer)));
370 }
371
372 selected_window = window;
373
374 Fset_buffer (w->buffer);
375
376 BVAR (XBUFFER (w->buffer), last_selected_window) = window;
377
378 /* Go to the point recorded in the window.
379 This is important when the buffer is in more
380 than one window. It also matters when
381 redisplay_window has altered point after scrolling,
382 because it makes the change only in the window. */
383 {
384 register EMACS_INT new_point = marker_position (w->pointm);
385 if (new_point < BEGV)
386 SET_PT (BEGV);
387 else if (new_point > ZV)
388 SET_PT (ZV);
389 else
390 SET_PT (new_point);
391 }
392
393 windows_or_buffers_changed++;
394 return window;
395}
396
397DEFUN ("select-window", Fselect_window, Sselect_window, 1, 2, 0,
398 doc: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
399Also make WINDOW's buffer current and make WINDOW the frame's selected
400window. Return WINDOW.
401
402Optional second arg NORECORD non-nil means do not put this buffer at the
403front of the buffer list and do not make this window the most recently
404selected one.
171 405
406Note that the main editor command loop sets the current buffer to the
407buffer of the selected window before each command. */)
408 (register Lisp_Object window, Lisp_Object norecord)
409{
410 return select_window (window, norecord, 0);
411}
412
172DEFUN ("window-buffer", Fwindow_buffer, Swindow_buffer, 0, 1, 0, 413DEFUN ("window-buffer", Fwindow_buffer, Swindow_buffer, 0, 1, 0,
173 doc: /* Return the buffer that WINDOW is displaying. 414 doc: /* Return the buffer that WINDOW is displaying.
174WINDOW can be any window and defaults to the selected one. 415WINDOW can be any window and defaults to the selected one.
@@ -276,36 +517,6 @@ make_window (void)
276 return val; 517 return val;
277} 518}
278 519
279DEFUN ("selected-window", Fselected_window, Sselected_window, 0, 0, 0,
280 doc: /* Return the window that the cursor now appears in and commands apply to. */)
281 (void)
282{
283 return selected_window;
284}
285
286DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0,
287 doc: /* Return the window used now for minibuffers.
288If the optional argument FRAME is specified, return the minibuffer window
289used by that frame. */)
290 (Lisp_Object frame)
291{
292 if (NILP (frame))
293 frame = selected_frame;
294 CHECK_LIVE_FRAME (frame);
295 return FRAME_MINIBUF_WINDOW (XFRAME (frame));
296}
297
298DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p,
299 Swindow_minibuffer_p, 0, 1, 0,
300 doc: /* Return non-nil if WINDOW is a minibuffer window.
301WINDOW defaults to the selected window. */)
302 (Lisp_Object window)
303{
304 struct window *w = decode_window (window);
305 return MINI_WINDOW_P (w) ? Qt : Qnil;
306}
307
308
309DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p, 520DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p,
310 Spos_visible_in_window_p, 0, 3, 0, 521 Spos_visible_in_window_p, 0, 3, 0,
311 doc: /* Return non-nil if position POS is currently on the frame in WINDOW. 522 doc: /* Return non-nil if position POS is currently on the frame in WINDOW.
@@ -3527,106 +3738,6 @@ This function runs `window-scroll-functions' before running
3527 return Qnil; 3738 return Qnil;
3528} 3739}
3529 3740
3530/* If select_window is called with inhibit_point_swap non-zero it will
3531 not store point of the old selected window's buffer back into that
3532 window's pointm slot. This is needed by Fset_window_configuration to
3533 avoid that the display routine is called with selected_window set to
3534 Qnil causing a subsequent crash. */
3535
3536static Lisp_Object
3537select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
3538{
3539 register struct window *w;
3540 register struct window *ow;
3541 struct frame *sf;
3542
3543 CHECK_LIVE_WINDOW (window);
3544
3545 w = XWINDOW (window);
3546 w->frozen_window_start_p = 0;
3547
3548 if (NILP (norecord))
3549 {
3550 ++window_select_count;
3551 XSETFASTINT (w->use_time, window_select_count);
3552 record_buffer (w->buffer);
3553 }
3554
3555 if (EQ (window, selected_window) && !inhibit_point_swap)
3556 return window;
3557
3558 sf = SELECTED_FRAME ();
3559 if (XFRAME (WINDOW_FRAME (w)) != sf)
3560 {
3561 XFRAME (WINDOW_FRAME (w))->selected_window = window;
3562 /* Use this rather than Fhandle_switch_frame
3563 so that FRAME_FOCUS_FRAME is moved appropriately as we
3564 move around in the state where a minibuffer in a separate
3565 frame is active. */
3566 Fselect_frame (WINDOW_FRAME (w), norecord);
3567 /* Fselect_frame called us back so we've done all the work already. */
3568 eassert (EQ (window, selected_window));
3569 return window;
3570 }
3571 else
3572 sf->selected_window = window;
3573
3574 /* Store the current buffer's actual point into the
3575 old selected window. It belongs to that window,
3576 and when the window is not selected, must be in the window. */
3577 if (!inhibit_point_swap)
3578 {
3579 ow = XWINDOW (selected_window);
3580 if (! NILP (ow->buffer))
3581 set_marker_both (ow->pointm, ow->buffer,
3582 BUF_PT (XBUFFER (ow->buffer)),
3583 BUF_PT_BYTE (XBUFFER (ow->buffer)));
3584 }
3585
3586 selected_window = window;
3587
3588 Fset_buffer (w->buffer);
3589
3590 BVAR (XBUFFER (w->buffer), last_selected_window) = window;
3591
3592 /* Go to the point recorded in the window.
3593 This is important when the buffer is in more
3594 than one window. It also matters when
3595 redisplay_window has altered point after scrolling,
3596 because it makes the change only in the window. */
3597 {
3598 register EMACS_INT new_point = marker_position (w->pointm);
3599 if (new_point < BEGV)
3600 SET_PT (BEGV);
3601 else if (new_point > ZV)
3602 SET_PT (ZV);
3603 else
3604 SET_PT (new_point);
3605 }
3606
3607 windows_or_buffers_changed++;
3608 return window;
3609}
3610
3611
3612/* Note that selected_window can be nil when this is called from
3613 Fset_window_configuration. */
3614
3615DEFUN ("select-window", Fselect_window, Sselect_window, 1, 2, 0,
3616 doc: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
3617If WINDOW is not already selected, make WINDOW's buffer current
3618and make WINDOW the frame's selected window. Return WINDOW.
3619Optional second arg NORECORD non-nil means do not put this buffer
3620at the front of the list of recently selected ones and do not
3621make this window the most recently selected one.
3622
3623Note that the main editor command loop selects the buffer of the
3624selected window before each command. */)
3625 (register Lisp_Object window, Lisp_Object norecord)
3626{
3627 return select_window (window, norecord, 0);
3628}
3629
3630static Lisp_Object 3741static Lisp_Object
3631select_window_norecord (Lisp_Object window) 3742select_window_norecord (Lisp_Object window)
3632{ 3743{
@@ -7156,6 +7267,11 @@ frame to be redrawn only if it is a tty frame. */);
7156 defsubr (&Swindow_minibuffer_p); 7267 defsubr (&Swindow_minibuffer_p);
7157 defsubr (&Swindowp); 7268 defsubr (&Swindowp);
7158 defsubr (&Swindow_live_p); 7269 defsubr (&Swindow_live_p);
7270 defsubr (&Swindow_frame);
7271 defsubr (&Sframe_root_window);
7272 defsubr (&Sframe_first_window);
7273 defsubr (&Sframe_selected_window);
7274 defsubr (&Sset_frame_selected_window);
7159 defsubr (&Spos_visible_in_window_p); 7275 defsubr (&Spos_visible_in_window_p);
7160 defsubr (&Swindow_line_height); 7276 defsubr (&Swindow_line_height);
7161 defsubr (&Swindow_buffer); 7277 defsubr (&Swindow_buffer);