| 1 | /* Window creation, deletion and examination for GNU Emacs. |
| 2 | Does not include redisplay. |
| 3 | Copyright (C) 1985, 1986, 1987, 1993 Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GNU Emacs. |
| 6 | |
| 7 | GNU Emacs is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2, or (at your option) |
| 10 | any later version. |
| 11 | |
| 12 | GNU Emacs is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with GNU Emacs; see the file COPYING. If not, write to |
| 19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 20 | |
| 21 | #include "config.h" |
| 22 | #include "lisp.h" |
| 23 | #include "buffer.h" |
| 24 | #include "frame.h" |
| 25 | #include "window.h" |
| 26 | #include "commands.h" |
| 27 | #include "indent.h" |
| 28 | #include "termchar.h" |
| 29 | #include "disptab.h" |
| 30 | #include "keyboard.h" |
| 31 | |
| 32 | Lisp_Object Qwindowp, Qwindow_live_p; |
| 33 | |
| 34 | Lisp_Object Fnext_window (), Fdelete_window (), Fselect_window (); |
| 35 | Lisp_Object Fset_window_buffer (), Fsplit_window (), Frecenter (); |
| 36 | |
| 37 | void delete_all_subwindows (); |
| 38 | static struct window *decode_window(); |
| 39 | |
| 40 | /* This is the window in which the terminal's cursor should |
| 41 | be left when nothing is being done with it. This must |
| 42 | always be a leaf window, and its buffer is selected by |
| 43 | the top level editing loop at the end of each command. |
| 44 | |
| 45 | This value is always the same as |
| 46 | FRAME_SELECTED_WINDOW (selected_frame). */ |
| 47 | |
| 48 | Lisp_Object selected_window; |
| 49 | |
| 50 | /* The minibuffer window of the selected frame. |
| 51 | Note that you cannot test for minibufferness of an arbitrary window |
| 52 | by comparing against this; but you can test for minibufferness of |
| 53 | the selected window. */ |
| 54 | Lisp_Object minibuf_window; |
| 55 | |
| 56 | /* Non-nil means it is the window for C-M-v to scroll |
| 57 | when the minibuffer is selected. */ |
| 58 | Lisp_Object Vminibuf_scroll_window; |
| 59 | |
| 60 | /* Non-nil means this is the buffer whose window C-M-v should scroll. */ |
| 61 | Lisp_Object Vother_window_scroll_buffer; |
| 62 | |
| 63 | /* Non-nil means it's function to call to display temp buffers. */ |
| 64 | Lisp_Object Vtemp_buffer_show_function; |
| 65 | |
| 66 | /* If a window gets smaller than either of these, it is removed. */ |
| 67 | int window_min_height; |
| 68 | int window_min_width; |
| 69 | |
| 70 | /* Nonzero implies Fdisplay_buffer should create windows. */ |
| 71 | int pop_up_windows; |
| 72 | |
| 73 | /* Nonzero implies make new frames for Fdisplay_buffer. */ |
| 74 | int pop_up_frames; |
| 75 | |
| 76 | /* Non-nil means use this function instead of default */ |
| 77 | Lisp_Object Vpop_up_frame_function; |
| 78 | |
| 79 | /* Function to call to handle Fdisplay_buffer. */ |
| 80 | Lisp_Object Vdisplay_buffer_function; |
| 81 | |
| 82 | /* Fdisplay_buffer always splits the largest window |
| 83 | if that window is more than this high. */ |
| 84 | int split_height_threshold; |
| 85 | |
| 86 | /* Number of lines of continuity in scrolling by screenfuls. */ |
| 87 | int next_screen_context_lines; |
| 88 | |
| 89 | /* Incremented for each window created. */ |
| 90 | static int sequence_number; |
| 91 | |
| 92 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
| 93 | \f |
| 94 | DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0, |
| 95 | "Returns t if OBJ is a window.") |
| 96 | (obj) |
| 97 | Lisp_Object obj; |
| 98 | { |
| 99 | return XTYPE (obj) == Lisp_Window ? Qt : Qnil; |
| 100 | } |
| 101 | |
| 102 | DEFUN ("window-live-p", Fwindow_live_p, Swindow_live_p, 1, 1, 0, |
| 103 | "Returns t if OBJ is a window which is currently visible.") |
| 104 | (obj) |
| 105 | Lisp_Object obj; |
| 106 | { |
| 107 | return ((XTYPE (obj) == Lisp_Window |
| 108 | && ! NILP (XWINDOW (obj)->buffer)) |
| 109 | ? Qt : Qnil); |
| 110 | } |
| 111 | |
| 112 | Lisp_Object |
| 113 | make_window () |
| 114 | { |
| 115 | register Lisp_Object val; |
| 116 | register struct window *p; |
| 117 | |
| 118 | /* Add sizeof (Lisp_Object) here because sizeof (struct Lisp_Vector) |
| 119 | includes the first element. */ |
| 120 | val = Fmake_vector ( |
| 121 | make_number ((sizeof (struct window) - sizeof (struct Lisp_Vector) |
| 122 | + sizeof (Lisp_Object)) |
| 123 | / sizeof (Lisp_Object)), |
| 124 | Qnil); |
| 125 | XSETTYPE (val, Lisp_Window); |
| 126 | p = XWINDOW (val); |
| 127 | XFASTINT (p->sequence_number) = ++sequence_number; |
| 128 | XFASTINT (p->left) = XFASTINT (p->top) |
| 129 | = XFASTINT (p->height) = XFASTINT (p->width) |
| 130 | = XFASTINT (p->hscroll) = 0; |
| 131 | XFASTINT (p->last_point_x) = XFASTINT (p->last_point_y) = 0; |
| 132 | p->start = Fmake_marker (); |
| 133 | p->pointm = Fmake_marker (); |
| 134 | XFASTINT (p->use_time) = 0; |
| 135 | p->frame = Qnil; |
| 136 | p->display_table = Qnil; |
| 137 | p->dedicated = Qnil; |
| 138 | return val; |
| 139 | } |
| 140 | |
| 141 | DEFUN ("selected-window", Fselected_window, Sselected_window, 0, 0, 0, |
| 142 | "Return the window that the cursor now appears in and commands apply to.") |
| 143 | () |
| 144 | { |
| 145 | return selected_window; |
| 146 | } |
| 147 | |
| 148 | DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0, |
| 149 | "Return the window used now for minibuffers.\n\ |
| 150 | If the optional argument FRAME is specified, return the minibuffer window\n\ |
| 151 | used by that frame.") |
| 152 | (frame) |
| 153 | Lisp_Object frame; |
| 154 | { |
| 155 | #ifdef MULTI_FRAME |
| 156 | if (NILP (frame)) |
| 157 | XSET (frame, Lisp_Frame, selected_frame); |
| 158 | else |
| 159 | CHECK_LIVE_FRAME (frame, 0); |
| 160 | #endif |
| 161 | |
| 162 | return FRAME_MINIBUF_WINDOW (XFRAME (frame)); |
| 163 | } |
| 164 | |
| 165 | DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p, Swindow_minibuffer_p, 0, 1, 0, |
| 166 | "Returns non-nil if WINDOW is a minibuffer window.") |
| 167 | (window) |
| 168 | Lisp_Object window; |
| 169 | { |
| 170 | struct window *w = decode_window (window); |
| 171 | return (MINI_WINDOW_P (w) ? Qt : Qnil); |
| 172 | } |
| 173 | |
| 174 | DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p, |
| 175 | Spos_visible_in_window_p, 0, 2, 0, |
| 176 | "Return t if position POS is currently on the frame in WINDOW.\n\ |
| 177 | Returns nil if that position is scrolled vertically out of view.\n\ |
| 178 | POS defaults to point; WINDOW, to the selected window.") |
| 179 | (pos, window) |
| 180 | Lisp_Object pos, window; |
| 181 | { |
| 182 | register struct window *w; |
| 183 | register int top; |
| 184 | register int height; |
| 185 | register int posint; |
| 186 | register struct buffer *buf; |
| 187 | struct position posval; |
| 188 | |
| 189 | if (NILP (pos)) |
| 190 | posint = point; |
| 191 | else |
| 192 | { |
| 193 | CHECK_NUMBER_COERCE_MARKER (pos, 0); |
| 194 | posint = XINT (pos); |
| 195 | } |
| 196 | |
| 197 | w = decode_window (window); |
| 198 | top = marker_position (w->start); |
| 199 | |
| 200 | if (posint < top) |
| 201 | return Qnil; |
| 202 | |
| 203 | height = XFASTINT (w->height) - ! MINI_WINDOW_P (w); |
| 204 | |
| 205 | buf = XBUFFER (w->buffer); |
| 206 | if (XFASTINT (w->last_modified) >= BUF_MODIFF (buf)) |
| 207 | { |
| 208 | /* If frame is up to date, |
| 209 | use the info recorded about how much text fit on it. */ |
| 210 | if (posint < BUF_Z (buf) - XFASTINT (w->window_end_pos) |
| 211 | || (XFASTINT (w->window_end_vpos) < height)) |
| 212 | return Qt; |
| 213 | return Qnil; |
| 214 | } |
| 215 | else |
| 216 | { |
| 217 | if (posint > BUF_Z (buf)) |
| 218 | return Qnil; |
| 219 | |
| 220 | /* If that info is not correct, calculate afresh */ |
| 221 | posval = *compute_motion (top, 0, 0, posint, height, 0, |
| 222 | window_internal_width (w) - 1, |
| 223 | XINT (w->hscroll), 0); |
| 224 | |
| 225 | return posval.vpos < height ? Qt : Qnil; |
| 226 | } |
| 227 | } |
| 228 | \f |
| 229 | static struct window * |
| 230 | decode_window (window) |
| 231 | register Lisp_Object window; |
| 232 | { |
| 233 | if (NILP (window)) |
| 234 | return XWINDOW (selected_window); |
| 235 | |
| 236 | CHECK_LIVE_WINDOW (window, 0); |
| 237 | return XWINDOW (window); |
| 238 | } |
| 239 | |
| 240 | DEFUN ("window-buffer", Fwindow_buffer, Swindow_buffer, 0, 1, 0, |
| 241 | "Return the buffer that WINDOW is displaying.") |
| 242 | (window) |
| 243 | Lisp_Object window; |
| 244 | { |
| 245 | return decode_window (window)->buffer; |
| 246 | } |
| 247 | |
| 248 | DEFUN ("window-height", Fwindow_height, Swindow_height, 0, 1, 0, |
| 249 | "Return the number of lines in WINDOW (including its mode line).") |
| 250 | (window) |
| 251 | Lisp_Object window; |
| 252 | { |
| 253 | return decode_window (window)->height; |
| 254 | } |
| 255 | |
| 256 | DEFUN ("window-width", Fwindow_width, Swindow_width, 0, 1, 0, |
| 257 | "Return the number of columns in WINDOW.") |
| 258 | (window) |
| 259 | Lisp_Object window; |
| 260 | { |
| 261 | register struct window *w = decode_window (window); |
| 262 | register int width = XFASTINT (w->width); |
| 263 | |
| 264 | return make_number (window_internal_width (w)); |
| 265 | } |
| 266 | |
| 267 | DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0, |
| 268 | "Return the number of columns by which WINDOW is scrolled from left margin.") |
| 269 | (window) |
| 270 | Lisp_Object window; |
| 271 | { |
| 272 | return decode_window (window)->hscroll; |
| 273 | } |
| 274 | |
| 275 | DEFUN ("set-window-hscroll", Fset_window_hscroll, Sset_window_hscroll, 2, 2, 0, |
| 276 | "Set number of columns WINDOW is scrolled from left margin to NCOL.\n\ |
| 277 | NCOL should be zero or positive.") |
| 278 | (window, ncol) |
| 279 | register Lisp_Object window, ncol; |
| 280 | { |
| 281 | register struct window *w; |
| 282 | |
| 283 | CHECK_NUMBER (ncol, 1); |
| 284 | if (XINT (ncol) < 0) XFASTINT (ncol) = 0; |
| 285 | if (XFASTINT (ncol) >= (1 << (SHORTBITS - 1))) |
| 286 | args_out_of_range (ncol, Qnil); |
| 287 | w = decode_window (window); |
| 288 | if (XINT (w->hscroll) != XINT (ncol)) |
| 289 | clip_changed = 1; /* Prevent redisplay shortcuts */ |
| 290 | w->hscroll = ncol; |
| 291 | return ncol; |
| 292 | } |
| 293 | |
| 294 | DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0, |
| 295 | "Return a list of the edge coordinates of WINDOW.\n\ |
| 296 | \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.\n\ |
| 297 | RIGHT is one more than the rightmost column used by WINDOW,\n\ |
| 298 | and BOTTOM is one more than the bottommost row used by WINDOW\n\ |
| 299 | and its mode-line.") |
| 300 | (window) |
| 301 | Lisp_Object window; |
| 302 | { |
| 303 | register struct window *w = decode_window (window); |
| 304 | |
| 305 | return Fcons (w->left, Fcons (w->top, |
| 306 | Fcons (make_number (XFASTINT (w->left) + XFASTINT (w->width)), |
| 307 | Fcons (make_number (XFASTINT (w->top) |
| 308 | + XFASTINT (w->height)), |
| 309 | Qnil)))); |
| 310 | } |
| 311 | |
| 312 | /* Test if the character at column *x, row *y is within window *w. |
| 313 | If it is not, return 0; |
| 314 | if it is in the window's text area, |
| 315 | set *x and *y to its location relative to the upper left corner |
| 316 | of the window, and |
| 317 | return 1; |
| 318 | if it is on the window's modeline, return 2; |
| 319 | if it is on the border between the window and its right sibling, |
| 320 | return 3. */ |
| 321 | static int |
| 322 | coordinates_in_window (w, x, y) |
| 323 | register struct window *w; |
| 324 | register int *x, *y; |
| 325 | { |
| 326 | register int left = XINT (w->left); |
| 327 | register int width = XINT (w->width); |
| 328 | register int window_height = XINT (w->height); |
| 329 | register int top = XFASTINT (w->top); |
| 330 | |
| 331 | if ( *x < left || *x >= left + width |
| 332 | || *y < top || *y >= top + window_height) |
| 333 | return 0; |
| 334 | |
| 335 | /* Is the character is the mode line? */ |
| 336 | if (*y == top + window_height - 1 |
| 337 | && ! MINI_WINDOW_P (w)) |
| 338 | return 2; |
| 339 | |
| 340 | /* Is the character in the right border? */ |
| 341 | if (*x == left + width - 1 |
| 342 | && left + width != FRAME_WIDTH (XFRAME (w->frame))) |
| 343 | return 3; |
| 344 | |
| 345 | *x -= left; |
| 346 | *y -= top; |
| 347 | return 1; |
| 348 | } |
| 349 | |
| 350 | DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p, |
| 351 | Scoordinates_in_window_p, 2, 2, 0, |
| 352 | "Return non-nil if COORDINATES are in WINDOW.\n\ |
| 353 | COORDINATES is a cons of the form (X . Y), X and Y being distances\n\ |
| 354 | measured in characters from the upper-left corner of the frame.\n\ |
| 355 | (0 . 0) denotes the character in the upper left corner of the\n\ |
| 356 | frame.\n\ |
| 357 | If COORDINATES are in the text portion of WINDOW,\n\ |
| 358 | the coordinates relative to the window are returned.\n\ |
| 359 | If they are in the mode line of WINDOW, `mode-line' is returned.\n\ |
| 360 | If they are on the border between WINDOW and its right sibling,\n\ |
| 361 | `vertical-line' is returned.") |
| 362 | (coordinates, window) |
| 363 | register Lisp_Object coordinates, window; |
| 364 | { |
| 365 | int x, y; |
| 366 | |
| 367 | CHECK_LIVE_WINDOW (window, 0); |
| 368 | CHECK_CONS (coordinates, 1); |
| 369 | x = XINT (Fcar (coordinates)); |
| 370 | y = XINT (Fcdr (coordinates)); |
| 371 | |
| 372 | switch (coordinates_in_window (XWINDOW (window), &x, &y)) |
| 373 | { |
| 374 | case 0: /* NOT in window at all. */ |
| 375 | return Qnil; |
| 376 | |
| 377 | case 1: /* In text part of window. */ |
| 378 | return Fcons (x, y); |
| 379 | |
| 380 | case 2: /* In mode line of window. */ |
| 381 | return Qmode_line; |
| 382 | |
| 383 | case 3: /* On right border of window. */ |
| 384 | return Qvertical_line; |
| 385 | |
| 386 | default: |
| 387 | abort (); |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | /* Find the window containing column x, row y, and return it as a |
| 392 | Lisp_Object. If x, y is on the window's modeline, set *part |
| 393 | to 1; if it is on the separating line between the window and its |
| 394 | right sibling, set it to 2; otherwise set it to 0. If there is no |
| 395 | window under x, y return nil and leave *part unmodified. */ |
| 396 | Lisp_Object |
| 397 | window_from_coordinates (frame, x, y, part) |
| 398 | FRAME_PTR frame; |
| 399 | int x, y; |
| 400 | int *part; |
| 401 | { |
| 402 | register Lisp_Object tem, first; |
| 403 | |
| 404 | tem = first = FRAME_SELECTED_WINDOW (frame); |
| 405 | |
| 406 | do |
| 407 | { |
| 408 | int found = coordinates_in_window (XWINDOW (tem), &x, &y); |
| 409 | |
| 410 | if (found) |
| 411 | { |
| 412 | *part = found - 1; |
| 413 | return tem; |
| 414 | } |
| 415 | |
| 416 | tem = Fnext_window (tem, Qt, Qlambda); |
| 417 | } |
| 418 | while (! EQ (tem, first)); |
| 419 | |
| 420 | return Qnil; |
| 421 | } |
| 422 | |
| 423 | DEFUN ("window-at", Fwindow_at, Swindow_at, 2, 3, 0, |
| 424 | "Return window containing coordinates X and Y on FRAME.\n\ |
| 425 | If omitted, FRAME defaults to the currently selected frame.\n\ |
| 426 | The top left corner of the frame is considered to be row 0,\n\ |
| 427 | column 0.") |
| 428 | (x, y, frame) |
| 429 | Lisp_Object x, y, frame; |
| 430 | { |
| 431 | int part; |
| 432 | |
| 433 | #ifdef MULTI_FRAME |
| 434 | if (NILP (frame)) |
| 435 | XSET (frame, Lisp_Frame, selected_frame); |
| 436 | else |
| 437 | CHECK_LIVE_FRAME (frame, 2); |
| 438 | #endif |
| 439 | CHECK_NUMBER (x, 0); |
| 440 | CHECK_NUMBER (y, 1); |
| 441 | |
| 442 | return window_from_coordinates (XFRAME (frame), |
| 443 | XINT (x), XINT (y), |
| 444 | &part); |
| 445 | } |
| 446 | |
| 447 | DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0, |
| 448 | "Return current value of point in WINDOW.\n\ |
| 449 | For a nonselected window, this is the value point would have\n\ |
| 450 | if that window were selected.\n\ |
| 451 | \n\ |
| 452 | Note that, when WINDOW is the selected window and its buffer\n\ |
| 453 | is also currently selected, the value returned is the same as (point).\n\ |
| 454 | It would be more strictly correct to return the `top-level' value\n\ |
| 455 | of point, outside of any save-excursion forms.\n\ |
| 456 | But that is hard to define.") |
| 457 | (window) |
| 458 | Lisp_Object window; |
| 459 | { |
| 460 | register struct window *w = decode_window (window); |
| 461 | |
| 462 | if (w == XWINDOW (selected_window) |
| 463 | && current_buffer == XBUFFER (w->buffer)) |
| 464 | return Fpoint (); |
| 465 | return Fmarker_position (w->pointm); |
| 466 | } |
| 467 | |
| 468 | DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0, |
| 469 | "Return position at which display currently starts in WINDOW.") |
| 470 | (window) |
| 471 | Lisp_Object window; |
| 472 | { |
| 473 | return Fmarker_position (decode_window (window)->start); |
| 474 | } |
| 475 | |
| 476 | DEFUN ("window-end", Fwindow_end, Swindow_end, 0, 1, 0, |
| 477 | "Return position at which display currently ends in WINDOW.") |
| 478 | (window) |
| 479 | Lisp_Object window; |
| 480 | { |
| 481 | Lisp_Object value; |
| 482 | struct window *w = decode_window (window); |
| 483 | |
| 484 | XSET (value, Lisp_Int, |
| 485 | BUF_Z (current_buffer) - XFASTINT (w->window_end_pos)); |
| 486 | |
| 487 | return value; |
| 488 | } |
| 489 | |
| 490 | DEFUN ("set-window-point", Fset_window_point, Sset_window_point, 2, 2, 0, |
| 491 | "Make point value in WINDOW be at position POS in WINDOW's buffer.") |
| 492 | (window, pos) |
| 493 | Lisp_Object window, pos; |
| 494 | { |
| 495 | register struct window *w = decode_window (window); |
| 496 | |
| 497 | CHECK_NUMBER_COERCE_MARKER (pos, 1); |
| 498 | if (w == XWINDOW (selected_window)) |
| 499 | Fgoto_char (pos); |
| 500 | else |
| 501 | set_marker_restricted (w->pointm, pos, w->buffer); |
| 502 | |
| 503 | return pos; |
| 504 | } |
| 505 | |
| 506 | DEFUN ("set-window-start", Fset_window_start, Sset_window_start, 2, 3, 0, |
| 507 | "Make display in WINDOW start at position POS in WINDOW's buffer.\n\ |
| 508 | Optional third arg NOFORCE non-nil inhibits next redisplay\n\ |
| 509 | from overriding motion of point in order to display at this exact start.") |
| 510 | (window, pos, noforce) |
| 511 | Lisp_Object window, pos, noforce; |
| 512 | { |
| 513 | register struct window *w = decode_window (window); |
| 514 | |
| 515 | CHECK_NUMBER_COERCE_MARKER (pos, 1); |
| 516 | set_marker_restricted (w->start, pos, w->buffer); |
| 517 | /* this is not right, but much easier than doing what is right. */ |
| 518 | w->start_at_line_beg = Qnil; |
| 519 | if (NILP (noforce)) |
| 520 | w->force_start = Qt; |
| 521 | w->update_mode_line = Qt; |
| 522 | XFASTINT (w->last_modified) = 0; |
| 523 | if (!EQ (window, selected_window)) |
| 524 | windows_or_buffers_changed++; |
| 525 | return pos; |
| 526 | } |
| 527 | |
| 528 | DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p, |
| 529 | 1, 1, 0, |
| 530 | "Return WINDOW's dedicated object, usually t or nil.\n\ |
| 531 | See also `set-window-dedicated-p'.") |
| 532 | (window) |
| 533 | Lisp_Object window; |
| 534 | { |
| 535 | return decode_window (window)->dedicated; |
| 536 | } |
| 537 | |
| 538 | DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p, |
| 539 | Sset_window_dedicated_p, 2, 2, 0, |
| 540 | "Control whether WINDOW is dedicated to the buffer it displays.\n\ |
| 541 | If it is dedicated, Emacs will not automatically change\n\ |
| 542 | which buffer appears in it.\n\ |
| 543 | The second argument is the new value for the dedication flag;\n\ |
| 544 | non-nil means yes.") |
| 545 | (window, arg) |
| 546 | Lisp_Object window, arg; |
| 547 | { |
| 548 | register struct window *w = decode_window (window); |
| 549 | |
| 550 | if (NILP (arg)) |
| 551 | w->dedicated = Qnil; |
| 552 | else |
| 553 | w->dedicated = Qt; |
| 554 | |
| 555 | return w->dedicated; |
| 556 | } |
| 557 | |
| 558 | DEFUN ("window-display-table", Fwindow_display_table, Swindow_display_table, |
| 559 | 0, 1, 0, |
| 560 | "Return the display-table that WINDOW is using.") |
| 561 | (window) |
| 562 | Lisp_Object window; |
| 563 | { |
| 564 | return decode_window (window)->display_table; |
| 565 | } |
| 566 | |
| 567 | /* Get the display table for use currently on window W. |
| 568 | This is either W's display table or W's buffer's display table. |
| 569 | Ignore the specified tables if they are not valid; |
| 570 | if no valid table is specified, return 0. */ |
| 571 | |
| 572 | struct Lisp_Vector * |
| 573 | window_display_table (w) |
| 574 | struct window *w; |
| 575 | { |
| 576 | Lisp_Object tem; |
| 577 | tem = w->display_table; |
| 578 | if (XTYPE (tem) == Lisp_Vector && XVECTOR (tem)->size == DISP_TABLE_SIZE) |
| 579 | return XVECTOR (tem); |
| 580 | tem = XBUFFER (w->buffer)->display_table; |
| 581 | if (XTYPE (tem) == Lisp_Vector && XVECTOR (tem)->size == DISP_TABLE_SIZE) |
| 582 | return XVECTOR (tem); |
| 583 | tem = Vstandard_display_table; |
| 584 | if (XTYPE (tem) == Lisp_Vector && XVECTOR (tem)->size == DISP_TABLE_SIZE) |
| 585 | return XVECTOR (tem); |
| 586 | return 0; |
| 587 | } |
| 588 | |
| 589 | DEFUN ("set-window-display-table", Fset_window_display_table, Sset_window_display_table, 2, 2, 0, |
| 590 | "Set WINDOW's display-table to TABLE.") |
| 591 | (window, table) |
| 592 | register Lisp_Object window, table; |
| 593 | { |
| 594 | register struct window *w; |
| 595 | register Lisp_Object z; /* Return value. */ |
| 596 | |
| 597 | w = decode_window (window); |
| 598 | w->display_table = table; |
| 599 | return table; |
| 600 | } |
| 601 | \f |
| 602 | /* Record info on buffer window w is displaying |
| 603 | when it is about to cease to display that buffer. */ |
| 604 | static |
| 605 | unshow_buffer (w) |
| 606 | register struct window *w; |
| 607 | { |
| 608 | Lisp_Object buf = w->buffer; |
| 609 | |
| 610 | if (XBUFFER (buf) != XMARKER (w->pointm)->buffer) |
| 611 | abort (); |
| 612 | |
| 613 | if (w == XWINDOW (selected_window) |
| 614 | || ! EQ (buf, XWINDOW (selected_window)->buffer)) |
| 615 | /* Do this except when the selected window's buffer |
| 616 | is being removed from some other window. */ |
| 617 | XBUFFER (buf)->last_window_start = marker_position (w->start); |
| 618 | |
| 619 | /* Point in the selected window's buffer |
| 620 | is actually stored in that buffer, and the window's pointm isn't used. |
| 621 | So don't clobber point in that buffer. */ |
| 622 | if (! EQ (buf, XWINDOW (selected_window)->buffer)) |
| 623 | BUF_PT (XBUFFER (buf)) |
| 624 | = clip_to_bounds (BUF_BEGV (XBUFFER (buf)), |
| 625 | marker_position (w->pointm), |
| 626 | BUF_ZV (XBUFFER (buf))); |
| 627 | } |
| 628 | |
| 629 | /* Put replacement into the window structure in place of old. */ |
| 630 | static |
| 631 | replace_window (old, replacement) |
| 632 | Lisp_Object old, replacement; |
| 633 | { |
| 634 | register Lisp_Object tem; |
| 635 | register struct window *o = XWINDOW (old), *p = XWINDOW (replacement); |
| 636 | |
| 637 | /* If OLD is its frame's root_window, then replacement is the new |
| 638 | root_window for that frame. */ |
| 639 | |
| 640 | if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame)))) |
| 641 | FRAME_ROOT_WINDOW (XFRAME (o->frame)) = replacement; |
| 642 | |
| 643 | p->left = o->left; |
| 644 | p->top = o->top; |
| 645 | p->width = o->width; |
| 646 | p->height = o->height; |
| 647 | |
| 648 | p->next = tem = o->next; |
| 649 | if (!NILP (tem)) |
| 650 | XWINDOW (tem)->prev = replacement; |
| 651 | |
| 652 | p->prev = tem = o->prev; |
| 653 | if (!NILP (tem)) |
| 654 | XWINDOW (tem)->next = replacement; |
| 655 | |
| 656 | p->parent = tem = o->parent; |
| 657 | if (!NILP (tem)) |
| 658 | { |
| 659 | if (EQ (XWINDOW (tem)->vchild, old)) |
| 660 | XWINDOW (tem)->vchild = replacement; |
| 661 | if (EQ (XWINDOW (tem)->hchild, old)) |
| 662 | XWINDOW (tem)->hchild = replacement; |
| 663 | } |
| 664 | |
| 665 | /*** Here, if replacement is a vertical combination |
| 666 | and so is its new parent, we should make replacement's |
| 667 | children be children of that parent instead. ***/ |
| 668 | } |
| 669 | |
| 670 | DEFUN ("delete-window", Fdelete_window, Sdelete_window, 0, 1, "", |
| 671 | "Remove WINDOW from the display. Default is selected window.") |
| 672 | (window) |
| 673 | register Lisp_Object window; |
| 674 | { |
| 675 | register Lisp_Object tem, parent, sib; |
| 676 | register struct window *p; |
| 677 | register struct window *par; |
| 678 | |
| 679 | /* Because this function is called by other C code on non-leaf |
| 680 | windows, the CHECK_LIVE_WINDOW macro would choke inappropriately, |
| 681 | so we can't decode_window here. */ |
| 682 | if (NILP (window)) |
| 683 | window = selected_window; |
| 684 | else |
| 685 | CHECK_WINDOW (window, 0); |
| 686 | p = XWINDOW (window); |
| 687 | |
| 688 | /* It's okay to delete an already-deleted window. */ |
| 689 | if (NILP (p->buffer) |
| 690 | && NILP (p->hchild) |
| 691 | && NILP (p->vchild)) |
| 692 | return Qnil; |
| 693 | |
| 694 | parent = p->parent; |
| 695 | if (NILP (parent)) |
| 696 | error ("Attempt to delete minibuffer or sole ordinary window"); |
| 697 | par = XWINDOW (parent); |
| 698 | |
| 699 | windows_or_buffers_changed++; |
| 700 | |
| 701 | /* Are we trying to delete any frame's selected window? */ |
| 702 | { |
| 703 | FRAME_PTR frame = WINDOW_FRAME (XWINDOW (window)); |
| 704 | |
| 705 | if (EQ (window, FRAME_SELECTED_WINDOW (frame))) |
| 706 | { |
| 707 | Lisp_Object alternative = Fnext_window (window, Qlambda, Qnil); |
| 708 | |
| 709 | /* If we're about to delete the selected window on the |
| 710 | selected frame, then we should use Fselect_window to select |
| 711 | the new window. On the other hand, if we're about to |
| 712 | delete the selected window on any other frame, we shouldn't do |
| 713 | anything but set the frame's selected_window slot. */ |
| 714 | if (EQ (window, selected_window)) |
| 715 | Fselect_window (alternative); |
| 716 | else |
| 717 | FRAME_SELECTED_WINDOW (frame) = alternative; |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | tem = p->buffer; |
| 722 | /* tem is null for dummy parent windows |
| 723 | (which have inferiors but not any contents themselves) */ |
| 724 | if (!NILP (tem)) |
| 725 | { |
| 726 | unshow_buffer (p); |
| 727 | unchain_marker (p->pointm); |
| 728 | unchain_marker (p->start); |
| 729 | } |
| 730 | |
| 731 | tem = p->next; |
| 732 | if (!NILP (tem)) |
| 733 | XWINDOW (tem)->prev = p->prev; |
| 734 | |
| 735 | tem = p->prev; |
| 736 | if (!NILP (tem)) |
| 737 | XWINDOW (tem)->next = p->next; |
| 738 | |
| 739 | if (EQ (window, par->hchild)) |
| 740 | par->hchild = p->next; |
| 741 | if (EQ (window, par->vchild)) |
| 742 | par->vchild = p->next; |
| 743 | |
| 744 | /* Find one of our siblings to give our space to. */ |
| 745 | sib = p->prev; |
| 746 | if (NILP (sib)) |
| 747 | { |
| 748 | /* If p gives its space to its next sibling, that sibling needs |
| 749 | to have its top/left side pulled back to where p's is. |
| 750 | set_window_{height,width} will re-position the sibling's |
| 751 | children. */ |
| 752 | sib = p->next; |
| 753 | XWINDOW (sib)->top = p->top; |
| 754 | XWINDOW (sib)->left = p->left; |
| 755 | } |
| 756 | |
| 757 | /* Stretch that sibling. */ |
| 758 | if (!NILP (par->vchild)) |
| 759 | set_window_height (sib, |
| 760 | XFASTINT (XWINDOW (sib)->height) + XFASTINT (p->height), |
| 761 | 1); |
| 762 | if (!NILP (par->hchild)) |
| 763 | set_window_width (sib, |
| 764 | XFASTINT (XWINDOW (sib)->width) + XFASTINT (p->width), |
| 765 | 1); |
| 766 | |
| 767 | /* If parent now has only one child, |
| 768 | put the child into the parent's place. */ |
| 769 | tem = par->hchild; |
| 770 | if (NILP (tem)) |
| 771 | tem = par->vchild; |
| 772 | if (NILP (XWINDOW (tem)->next)) |
| 773 | replace_window (parent, tem); |
| 774 | |
| 775 | /* Since we may be deleting combination windows, we must make sure that |
| 776 | not only p but all its children have been marked as deleted. */ |
| 777 | if (! NILP (p->hchild)) |
| 778 | delete_all_subwindows (XWINDOW (p->hchild)); |
| 779 | else if (! NILP (p->vchild)) |
| 780 | delete_all_subwindows (XWINDOW (p->vchild)); |
| 781 | |
| 782 | /* Mark this window as deleted. */ |
| 783 | p->buffer = p->hchild = p->vchild = Qnil; |
| 784 | |
| 785 | return Qnil; |
| 786 | } |
| 787 | \f |
| 788 | |
| 789 | extern Lisp_Object next_frame (), prev_frame (); |
| 790 | |
| 791 | DEFUN ("next-window", Fnext_window, Snext_window, 0, 3, 0, |
| 792 | "Return next window after WINDOW in canonical ordering of windows.\n\ |
| 793 | If omitted, WINDOW defaults to the selected window.\n\ |
| 794 | \n\ |
| 795 | Optional second arg MINIBUF t means count the minibuffer window even\n\ |
| 796 | if not active. MINIBUF nil or omitted means count the minibuffer iff\n\ |
| 797 | it is active. MINIBUF neither t nor nil means not to count the\n\ |
| 798 | minibuffer even if it is active.\n\ |
| 799 | \n\ |
| 800 | Several frames may share a single minibuffer; if the minibuffer\n\ |
| 801 | counts, all windows on all frames that share that minibuffer count\n\ |
| 802 | too. This means that next-window may be used to iterate through the\n\ |
| 803 | set of windows even when the minibuffer is on another frame. If the\n\ |
| 804 | minibuffer does not count, only windows from WINDOW's frame count.\n\ |
| 805 | \n\ |
| 806 | Optional third arg ALL-FRAMES t means include windows on all frames.\n\ |
| 807 | ALL-FRAMES nil or omitted means cycle within the frames as specified\n\ |
| 808 | above. If neither nil nor t, restrict to WINDOW's frame.\n\ |
| 809 | \n\ |
| 810 | If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\ |
| 811 | `next-window' to iterate through the entire cycle of acceptable\n\ |
| 812 | windows, eventually ending up back at the window you started with.\n\ |
| 813 | `previous-window' traverses the same cycle, in the reverse order.") |
| 814 | (window, minibuf, all_frames) |
| 815 | register Lisp_Object window, minibuf, all_frames; |
| 816 | { |
| 817 | register Lisp_Object tem; |
| 818 | Lisp_Object start_window; |
| 819 | |
| 820 | if (NILP (window)) |
| 821 | window = selected_window; |
| 822 | else |
| 823 | CHECK_LIVE_WINDOW (window, 0); |
| 824 | |
| 825 | start_window = window; |
| 826 | |
| 827 | /* minibuf == nil may or may not include minibuffers. |
| 828 | Decide if it does. */ |
| 829 | if (NILP (minibuf)) |
| 830 | minibuf = (minibuf_level ? Qt : Qlambda); |
| 831 | |
| 832 | /* all_frames == nil doesn't specify which frames to include. |
| 833 | Decide which frames it includes. */ |
| 834 | if (NILP (all_frames)) |
| 835 | all_frames = (EQ (minibuf, Qt) |
| 836 | ? (FRAME_MINIBUF_WINDOW |
| 837 | (XFRAME |
| 838 | (WINDOW_FRAME |
| 839 | (XWINDOW (window))))) |
| 840 | : Qnil); |
| 841 | else if (! EQ (all_frames, Qt)) |
| 842 | all_frames = Qnil; |
| 843 | /* Now all_frames is t meaning search all frames, |
| 844 | nil meaning search just current frame, |
| 845 | or a window, meaning search the frame that window belongs to. */ |
| 846 | |
| 847 | /* Do this loop at least once, to get the next window, and perhaps |
| 848 | again, if we hit the minibuffer and that is not acceptable. */ |
| 849 | do |
| 850 | { |
| 851 | /* Find a window that actually has a next one. This loop |
| 852 | climbs up the tree. */ |
| 853 | while (tem = XWINDOW (window)->next, NILP (tem)) |
| 854 | if (tem = XWINDOW (window)->parent, !NILP (tem)) |
| 855 | window = tem; |
| 856 | else |
| 857 | { |
| 858 | /* We've reached the end of this frame. |
| 859 | Which other frames are acceptable? */ |
| 860 | tem = WINDOW_FRAME (XWINDOW (window)); |
| 861 | #ifdef MULTI_FRAME |
| 862 | if (! NILP (all_frames)) |
| 863 | tem = next_frame (tem, all_frames); |
| 864 | #endif |
| 865 | tem = FRAME_ROOT_WINDOW (XFRAME (tem)); |
| 866 | |
| 867 | break; |
| 868 | } |
| 869 | |
| 870 | window = tem; |
| 871 | |
| 872 | /* If we're in a combination window, find its first child and |
| 873 | recurse on that. Otherwise, we've found the window we want. */ |
| 874 | while (1) |
| 875 | { |
| 876 | if (!NILP (XWINDOW (window)->hchild)) |
| 877 | window = XWINDOW (window)->hchild; |
| 878 | else if (!NILP (XWINDOW (window)->vchild)) |
| 879 | window = XWINDOW (window)->vchild; |
| 880 | else break; |
| 881 | } |
| 882 | } |
| 883 | /* Which windows are acceptible? |
| 884 | Exit the loop and accept this window if |
| 885 | this isn't a minibuffer window, or |
| 886 | we're accepting minibuffer windows, or |
| 887 | we've come all the way around and we're back at the original window. */ |
| 888 | while (MINI_WINDOW_P (XWINDOW (window)) |
| 889 | && ! EQ (minibuf, Qt) |
| 890 | && ! EQ (window, start_window)); |
| 891 | |
| 892 | return window; |
| 893 | } |
| 894 | |
| 895 | DEFUN ("previous-window", Fprevious_window, Sprevious_window, 0, 3, 0, |
| 896 | "Return the window preceeding WINDOW in canonical ordering of windows.\n\ |
| 897 | If omitted, WINDOW defaults to the selected window.\n\ |
| 898 | \n\ |
| 899 | Optional second arg MINIBUF t means count the minibuffer window even\n\ |
| 900 | if not active. MINIBUF nil or omitted means count the minibuffer iff\n\ |
| 901 | it is active. MINIBUF neither t nor nil means not to count the\n\ |
| 902 | minibuffer even if it is active.\n\ |
| 903 | \n\ |
| 904 | Several frames may share a single minibuffer; if the minibuffer\n\ |
| 905 | counts, all windows on all frames that share that minibuffer count\n\ |
| 906 | too. This means that previous-window may be used to iterate through\n\ |
| 907 | the set of windows even when the minibuffer is on another frame. If\n\ |
| 908 | the minibuffer does not count, only windows from WINDOW's frame\n\ |
| 909 | count.\n\ |
| 910 | \n\ |
| 911 | Optional third arg ALL-FRAMES t means include windows on all frames.\n\ |
| 912 | ALL-FRAMES nil or omitted means cycle within the frames as specified\n\ |
| 913 | above. If neither nil nor t, restrict to WINDOW's frame.\n\ |
| 914 | \n\ |
| 915 | If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\ |
| 916 | `previous-window' to iterate through the entire cycle of acceptable\n\ |
| 917 | windows, eventually ending up back at the window you started with.\n\ |
| 918 | `next-window' traverses the same cycle, in the reverse order.") |
| 919 | (window, minibuf, all_frames) |
| 920 | register Lisp_Object window, minibuf, all_frames; |
| 921 | { |
| 922 | register Lisp_Object tem; |
| 923 | Lisp_Object start_window; |
| 924 | |
| 925 | if (NILP (window)) |
| 926 | window = selected_window; |
| 927 | else |
| 928 | CHECK_LIVE_WINDOW (window, 0); |
| 929 | |
| 930 | start_window = window; |
| 931 | |
| 932 | /* minibuf == nil may or may not include minibuffers. |
| 933 | Decide if it does. */ |
| 934 | if (NILP (minibuf)) |
| 935 | minibuf = (minibuf_level ? Qt : Qlambda); |
| 936 | |
| 937 | /* all_frames == nil doesn't specify which frames to include. |
| 938 | Decide which frames it includes. */ |
| 939 | if (NILP (all_frames)) |
| 940 | all_frames = (EQ (minibuf, Qt) |
| 941 | ? (FRAME_MINIBUF_WINDOW |
| 942 | (XFRAME |
| 943 | (WINDOW_FRAME |
| 944 | (XWINDOW (window))))) |
| 945 | : Qnil); |
| 946 | else if (! EQ (all_frames, Qt)) |
| 947 | all_frames = Qnil; |
| 948 | /* Now all_frames is t meaning search all frames, |
| 949 | nil meaning search just current frame, |
| 950 | or a window, meaning search the frame that window belongs to. */ |
| 951 | |
| 952 | /* Do this loop at least once, to get the previous window, and perhaps |
| 953 | again, if we hit the minibuffer and that is not acceptable. */ |
| 954 | do |
| 955 | { |
| 956 | /* Find a window that actually has a previous one. This loop |
| 957 | climbs up the tree. */ |
| 958 | while (tem = XWINDOW (window)->prev, NILP (tem)) |
| 959 | if (tem = XWINDOW (window)->parent, !NILP (tem)) |
| 960 | window = tem; |
| 961 | else |
| 962 | { |
| 963 | /* We have found the top window on the frame. |
| 964 | Which frames are acceptable? */ |
| 965 | tem = WINDOW_FRAME (XWINDOW (window)); |
| 966 | #ifdef MULTI_FRAME |
| 967 | if (! NILP (all_frames)) |
| 968 | /* It's actually important that we use prev_frame here, |
| 969 | rather than next_frame. All the windows acceptable |
| 970 | according to the given parameters should form a ring; |
| 971 | Fnext_window and Fprevious_window should go back and |
| 972 | forth around the ring. If we use next_frame here, |
| 973 | then Fnext_window and Fprevious_window take different |
| 974 | paths through the set of acceptable windows. |
| 975 | window_loop assumes that these `ring' requirement are |
| 976 | met. */ |
| 977 | tem = prev_frame (tem, all_frames); |
| 978 | #endif |
| 979 | /* If this frame has a minibuffer, find that window first, |
| 980 | because it is conceptually the last window in that frame. */ |
| 981 | if (FRAME_HAS_MINIBUF_P (XFRAME (tem))) |
| 982 | tem = FRAME_MINIBUF_WINDOW (XFRAME (tem)); |
| 983 | else |
| 984 | tem = FRAME_ROOT_WINDOW (XFRAME (tem)); |
| 985 | |
| 986 | break; |
| 987 | } |
| 988 | |
| 989 | window = tem; |
| 990 | /* If we're in a combination window, find its last child and |
| 991 | recurse on that. Otherwise, we've found the window we want. */ |
| 992 | while (1) |
| 993 | { |
| 994 | if (!NILP (XWINDOW (window)->hchild)) |
| 995 | window = XWINDOW (window)->hchild; |
| 996 | else if (!NILP (XWINDOW (window)->vchild)) |
| 997 | window = XWINDOW (window)->vchild; |
| 998 | else break; |
| 999 | while (tem = XWINDOW (window)->next, !NILP (tem)) |
| 1000 | window = tem; |
| 1001 | } |
| 1002 | } |
| 1003 | /* Which windows are acceptable? |
| 1004 | Exit the loop and accept this window if |
| 1005 | this isn't a minibuffer window, or |
| 1006 | we're accepting minibuffer windows, or |
| 1007 | we've come all the way around and we're back at the original window. */ |
| 1008 | while (MINI_WINDOW_P (XWINDOW (window)) |
| 1009 | && !EQ (minibuf, Qt) |
| 1010 | && !EQ (window, start_window)); |
| 1011 | |
| 1012 | return window; |
| 1013 | } |
| 1014 | |
| 1015 | DEFUN ("other-window", Fother_window, Sother_window, 1, 2, "p", |
| 1016 | "Select the ARG'th different window on this frame.\n\ |
| 1017 | All windows on current frame are arranged in a cyclic order.\n\ |
| 1018 | This command selects the window ARG steps away in that order.\n\ |
| 1019 | A negative ARG moves in the opposite order. If the optional second\n\ |
| 1020 | argument ALL_FRAMES is non-nil, cycle through all frames.") |
| 1021 | (n, all_frames) |
| 1022 | register Lisp_Object n, all_frames; |
| 1023 | { |
| 1024 | register int i; |
| 1025 | register Lisp_Object w; |
| 1026 | |
| 1027 | CHECK_NUMBER (n, 0); |
| 1028 | w = selected_window; |
| 1029 | i = XINT (n); |
| 1030 | |
| 1031 | while (i > 0) |
| 1032 | { |
| 1033 | w = Fnext_window (w, Qnil, all_frames); |
| 1034 | i--; |
| 1035 | } |
| 1036 | while (i < 0) |
| 1037 | { |
| 1038 | w = Fprevious_window (w, Qnil, all_frames); |
| 1039 | i++; |
| 1040 | } |
| 1041 | Fselect_window (w); |
| 1042 | return Qnil; |
| 1043 | } |
| 1044 | \f |
| 1045 | /* Look at all windows, performing an operation specified by TYPE |
| 1046 | with argument OBJ. |
| 1047 | If FRAMES is Qt, look at all frames, if Qnil, look at just the selected |
| 1048 | frame. If FRAMES is a frame, just look at windows on that frame. |
| 1049 | If MINI is non-zero, perform the operation on minibuffer windows too. |
| 1050 | */ |
| 1051 | |
| 1052 | enum window_loop |
| 1053 | { |
| 1054 | WINDOW_LOOP_UNUSED, |
| 1055 | GET_BUFFER_WINDOW, /* Arg is buffer */ |
| 1056 | GET_LRU_WINDOW, /* Arg is t for full-width windows only */ |
| 1057 | DELETE_OTHER_WINDOWS, /* Arg is window not to delete */ |
| 1058 | DELETE_BUFFER_WINDOWS, /* Arg is buffer */ |
| 1059 | GET_LARGEST_WINDOW, |
| 1060 | UNSHOW_BUFFER, /* Arg is buffer */ |
| 1061 | }; |
| 1062 | |
| 1063 | static Lisp_Object |
| 1064 | window_loop (type, obj, mini, frames) |
| 1065 | enum window_loop type; |
| 1066 | register Lisp_Object obj, frames; |
| 1067 | int mini; |
| 1068 | { |
| 1069 | register Lisp_Object w; |
| 1070 | register Lisp_Object best_window; |
| 1071 | register Lisp_Object next_window; |
| 1072 | register Lisp_Object last_window; |
| 1073 | FRAME_PTR frame; |
| 1074 | |
| 1075 | #ifdef MULTI_FRAME |
| 1076 | /* If we're only looping through windows on a particular frame, |
| 1077 | frame points to that frame. If we're looping through windows |
| 1078 | on all frames, frame is 0. */ |
| 1079 | if (FRAMEP (frames)) |
| 1080 | frame = XFRAME (frames); |
| 1081 | else if (NILP (frames)) |
| 1082 | frame = selected_frame; |
| 1083 | else |
| 1084 | frame = 0; |
| 1085 | #else |
| 1086 | frame = 0; |
| 1087 | #endif |
| 1088 | |
| 1089 | /* Pick a window to start with. */ |
| 1090 | if (XTYPE (obj) == Lisp_Window) |
| 1091 | w = obj; |
| 1092 | else if (frame) |
| 1093 | w = FRAME_SELECTED_WINDOW (frame); |
| 1094 | else |
| 1095 | w = FRAME_SELECTED_WINDOW (selected_frame); |
| 1096 | |
| 1097 | /* Figure out the last window we're going to mess with. Since |
| 1098 | Fnext_window, given the same options, is guaranteed to go in a |
| 1099 | ring, we can just use Fprevious_window to find the last one. |
| 1100 | |
| 1101 | We can't just wait until we hit the first window again, because |
| 1102 | it might be deleted. */ |
| 1103 | |
| 1104 | #ifdef MULTI_FRAME |
| 1105 | if (frame) |
| 1106 | last_window = Fprevious_window (w, (mini ? Qt : Qnil), Qlambda); |
| 1107 | else |
| 1108 | #endif /* MULTI_FRAME */ |
| 1109 | /* We know frame is 0, so we're looping through all frames. |
| 1110 | Or we know this isn't a MULTI_FRAME Emacs, so who cares? */ |
| 1111 | last_window = Fprevious_window (w, mini ? Qt : Qnil, Qt); |
| 1112 | |
| 1113 | best_window = Qnil; |
| 1114 | for (;;) |
| 1115 | { |
| 1116 | /* Pick the next window now, since some operations will delete |
| 1117 | the current window. */ |
| 1118 | #ifdef MULTI_FRAME |
| 1119 | if (frame) |
| 1120 | next_window = Fnext_window (w, (mini ? Qt : Qnil), Qlambda); |
| 1121 | else |
| 1122 | #endif /* MULTI_FRAME */ |
| 1123 | /* We know frame is 0, so we're looping through all frames. |
| 1124 | Or we know this isn't a MULTI_FRAME Emacs, so who cares? */ |
| 1125 | next_window = Fnext_window (w, mini ? Qt : Qnil, Qt); |
| 1126 | |
| 1127 | if (!MINI_WINDOW_P (XWINDOW (w)) |
| 1128 | || (mini && minibuf_level > 0)) |
| 1129 | switch (type) |
| 1130 | { |
| 1131 | case GET_BUFFER_WINDOW: |
| 1132 | #if 0 |
| 1133 | /* Ignore invisible and iconified frames. */ |
| 1134 | if (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (w)))) |
| 1135 | || FRAME_ICONIFIED_P (XFRAME (WINDOW_FRAME (XWINDOW (w))))) |
| 1136 | break; |
| 1137 | #endif |
| 1138 | if (XBUFFER (XWINDOW (w)->buffer) == XBUFFER (obj)) |
| 1139 | return w; |
| 1140 | break; |
| 1141 | |
| 1142 | case GET_LRU_WINDOW: |
| 1143 | /* t as arg means consider only full-width windows */ |
| 1144 | if (!NILP (obj) && XFASTINT (XWINDOW (w)->width) |
| 1145 | != FRAME_WIDTH (XFRAME (WINDOW_FRAME (XWINDOW (w))))) |
| 1146 | break; |
| 1147 | #if 0 |
| 1148 | /* Ignore invisible and iconified frames. */ |
| 1149 | if (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (w)))) |
| 1150 | || FRAME_ICONIFIED_P (XFRAME (WINDOW_FRAME (XWINDOW (w))))) |
| 1151 | break; |
| 1152 | #endif |
| 1153 | /* Ignore dedicated windows and minibuffers. */ |
| 1154 | if (MINI_WINDOW_P (XWINDOW (w)) |
| 1155 | || !NILP (XWINDOW (w)->dedicated)) |
| 1156 | break; |
| 1157 | if (NILP (best_window) |
| 1158 | || (XFASTINT (XWINDOW (best_window)->use_time) |
| 1159 | > XFASTINT (XWINDOW (w)->use_time))) |
| 1160 | best_window = w; |
| 1161 | break; |
| 1162 | |
| 1163 | case DELETE_OTHER_WINDOWS: |
| 1164 | if (XWINDOW (w) != XWINDOW (obj)) |
| 1165 | Fdelete_window (w); |
| 1166 | break; |
| 1167 | |
| 1168 | case DELETE_BUFFER_WINDOWS: |
| 1169 | if (EQ (XWINDOW (w)->buffer, obj)) |
| 1170 | { |
| 1171 | /* If we're deleting the buffer displayed in the only window |
| 1172 | on the frame, find a new buffer to display there. */ |
| 1173 | if (NILP (XWINDOW (w)->parent)) |
| 1174 | { |
| 1175 | Lisp_Object new_buffer = Fother_buffer (obj, Qnil); |
| 1176 | if (NILP (new_buffer)) |
| 1177 | new_buffer |
| 1178 | = Fget_buffer_create (build_string ("*scratch*")); |
| 1179 | Fset_window_buffer (w, new_buffer); |
| 1180 | Fset_buffer (XWINDOW (w)->buffer); |
| 1181 | } |
| 1182 | else |
| 1183 | Fdelete_window (w); |
| 1184 | } |
| 1185 | break; |
| 1186 | |
| 1187 | case GET_LARGEST_WINDOW: |
| 1188 | #if 0 |
| 1189 | /* Ignore invisible and iconified frames. */ |
| 1190 | if (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (w)))) |
| 1191 | || FRAME_ICONIFIED_P (XFRAME (WINDOW_FRAME (XWINDOW (w))))) |
| 1192 | break; |
| 1193 | #endif |
| 1194 | /* Ignore dedicated windows and minibuffers. */ |
| 1195 | if (MINI_WINDOW_P (XWINDOW (w)) |
| 1196 | || !NILP (XWINDOW (w)->dedicated)) |
| 1197 | break; |
| 1198 | { |
| 1199 | struct window *best_window_ptr = XWINDOW (best_window); |
| 1200 | struct window *w_ptr = XWINDOW (w); |
| 1201 | if (NILP (best_window) || |
| 1202 | (XFASTINT (w_ptr->height) * XFASTINT (w_ptr->width)) |
| 1203 | > (XFASTINT (best_window_ptr->height) |
| 1204 | * XFASTINT (best_window_ptr->width))) |
| 1205 | best_window = w; |
| 1206 | } |
| 1207 | break; |
| 1208 | |
| 1209 | case UNSHOW_BUFFER: |
| 1210 | if (EQ (XWINDOW (w)->buffer, obj)) |
| 1211 | { |
| 1212 | /* Find another buffer to show in this window. */ |
| 1213 | Lisp_Object another_buffer = Fother_buffer (obj, Qnil); |
| 1214 | if (NILP (another_buffer)) |
| 1215 | another_buffer |
| 1216 | = Fget_buffer_create (build_string ("*scratch*")); |
| 1217 | Fset_window_buffer (w, another_buffer); |
| 1218 | if (EQ (w, selected_window)) |
| 1219 | Fset_buffer (XWINDOW (w)->buffer); |
| 1220 | } |
| 1221 | break; |
| 1222 | } |
| 1223 | |
| 1224 | if (EQ (w, last_window)) |
| 1225 | break; |
| 1226 | |
| 1227 | w = next_window; |
| 1228 | } |
| 1229 | |
| 1230 | return best_window; |
| 1231 | } |
| 1232 | |
| 1233 | DEFUN ("get-lru-window", Fget_lru_window, Sget_lru_window, 0, 1, 0, |
| 1234 | "Return the window least recently selected or used for display.\n\ |
| 1235 | If optional argument FRAMES is t, search all frames. If FRAME is a\n\ |
| 1236 | frame, search only that frame.\n") |
| 1237 | (frames) |
| 1238 | Lisp_Object frames; |
| 1239 | { |
| 1240 | register Lisp_Object w; |
| 1241 | /* First try for a window that is full-width */ |
| 1242 | w = window_loop (GET_LRU_WINDOW, Qt, 0, frames); |
| 1243 | if (!NILP (w) && !EQ (w, selected_window)) |
| 1244 | return w; |
| 1245 | /* If none of them, try the rest */ |
| 1246 | return window_loop (GET_LRU_WINDOW, Qnil, 0, frames); |
| 1247 | } |
| 1248 | |
| 1249 | DEFUN ("get-largest-window", Fget_largest_window, Sget_largest_window, 0, 1, 0, |
| 1250 | "Return the largest window in area.\n\ |
| 1251 | If optional argument FRAMES is t, search all frames. If FRAME is a\n\ |
| 1252 | frame, search only that frame.\n") |
| 1253 | (frame) |
| 1254 | Lisp_Object frame; |
| 1255 | { |
| 1256 | return window_loop (GET_LARGEST_WINDOW, Qnil, 0, |
| 1257 | frame); |
| 1258 | } |
| 1259 | |
| 1260 | DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 1, 2, 0, |
| 1261 | "Return a window currently displaying BUFFER, or nil if none.\n\ |
| 1262 | If optional argument FRAMES is t, search all frames. If FRAME is a\n\ |
| 1263 | frame, search only that frame.\n") |
| 1264 | (buffer, frame) |
| 1265 | Lisp_Object buffer, frame; |
| 1266 | { |
| 1267 | buffer = Fget_buffer (buffer); |
| 1268 | if (XTYPE (buffer) == Lisp_Buffer) |
| 1269 | return window_loop (GET_BUFFER_WINDOW, buffer, 1, frame); |
| 1270 | else |
| 1271 | return Qnil; |
| 1272 | } |
| 1273 | |
| 1274 | DEFUN ("delete-other-windows", Fdelete_other_windows, Sdelete_other_windows, |
| 1275 | 0, 1, "", |
| 1276 | "Make WINDOW (or the selected window) fill its frame.\n\ |
| 1277 | Only the frame WINDOW is on is affected.") |
| 1278 | (window) |
| 1279 | Lisp_Object window; |
| 1280 | { |
| 1281 | struct window *w; |
| 1282 | int opoint = point; |
| 1283 | struct buffer *obuf = current_buffer; |
| 1284 | int top; |
| 1285 | |
| 1286 | if (NILP (window)) |
| 1287 | window = selected_window; |
| 1288 | else |
| 1289 | CHECK_LIVE_WINDOW (window, 0); |
| 1290 | |
| 1291 | w = XWINDOW (window); |
| 1292 | top = XFASTINT (w->top); |
| 1293 | |
| 1294 | window_loop (DELETE_OTHER_WINDOWS, window, 0, WINDOW_FRAME (w)); |
| 1295 | |
| 1296 | Fset_buffer (w->buffer); |
| 1297 | SET_PT (marker_position (w->start)); |
| 1298 | Frecenter (make_number (top - FRAME_MENU_BAR_LINES (XFRAME (WINDOW_FRAME (w))))); |
| 1299 | |
| 1300 | set_buffer_internal (obuf); |
| 1301 | SET_PT (opoint); |
| 1302 | return Qnil; |
| 1303 | } |
| 1304 | |
| 1305 | DEFUN ("delete-windows-on", Fdelete_windows_on, Sdelete_windows_on, |
| 1306 | 1, 1, "bDelete windows on (buffer): ", |
| 1307 | "Delete all windows showing BUFFER.") |
| 1308 | (buffer) |
| 1309 | Lisp_Object buffer; |
| 1310 | { |
| 1311 | if (!NILP (buffer)) |
| 1312 | { |
| 1313 | buffer = Fget_buffer (buffer); |
| 1314 | CHECK_BUFFER (buffer, 0); |
| 1315 | window_loop (DELETE_BUFFER_WINDOWS, buffer, 0, Qt); |
| 1316 | } |
| 1317 | return Qnil; |
| 1318 | } |
| 1319 | |
| 1320 | DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows, |
| 1321 | Sreplace_buffer_in_windows, |
| 1322 | 1, 1, "bReplace buffer in windows: ", |
| 1323 | "Replace BUFFER with some other buffer in all windows showing it.") |
| 1324 | (buffer) |
| 1325 | Lisp_Object buffer; |
| 1326 | { |
| 1327 | if (!NILP (buffer)) |
| 1328 | { |
| 1329 | buffer = Fget_buffer (buffer); |
| 1330 | CHECK_BUFFER (buffer, 0); |
| 1331 | window_loop (UNSHOW_BUFFER, buffer, 0, Qt); |
| 1332 | } |
| 1333 | return Qnil; |
| 1334 | } |
| 1335 | \f |
| 1336 | /* Set the height of WINDOW and all its inferiors. */ |
| 1337 | |
| 1338 | /* The smallest acceptable dimensions for a window. Anything smaller |
| 1339 | might crash Emacs. */ |
| 1340 | #define MIN_SAFE_WINDOW_WIDTH (2) |
| 1341 | #define MIN_SAFE_WINDOW_HEIGHT (2) |
| 1342 | |
| 1343 | /* Make sure that window_min_height and window_min_width are |
| 1344 | not too small; if they are, set them to safe minima. */ |
| 1345 | |
| 1346 | static void |
| 1347 | check_min_window_sizes () |
| 1348 | { |
| 1349 | /* Smaller values might permit a crash. */ |
| 1350 | if (window_min_width < MIN_SAFE_WINDOW_WIDTH) |
| 1351 | window_min_width = MIN_SAFE_WINDOW_WIDTH; |
| 1352 | if (window_min_height < MIN_SAFE_WINDOW_HEIGHT) |
| 1353 | window_min_height = MIN_SAFE_WINDOW_HEIGHT; |
| 1354 | } |
| 1355 | |
| 1356 | /* If *ROWS or *COLS are too small a size for FRAME, set them to the |
| 1357 | minimum allowable size. */ |
| 1358 | void |
| 1359 | check_frame_size (frame, rows, cols) |
| 1360 | FRAME_PTR frame; |
| 1361 | int *rows, *cols; |
| 1362 | { |
| 1363 | /* For height, we have to see whether the frame has a minibuffer, and |
| 1364 | whether it wants a mode line. */ |
| 1365 | int min_height = |
| 1366 | ((FRAME_MINIBUF_ONLY_P (frame) |
| 1367 | || ! FRAME_HAS_MINIBUF_P (frame)) |
| 1368 | ? MIN_SAFE_WINDOW_HEIGHT |
| 1369 | : 2 * MIN_SAFE_WINDOW_HEIGHT - 1); |
| 1370 | |
| 1371 | if (*rows < min_height) |
| 1372 | *rows = min_height; |
| 1373 | if (*cols < MIN_SAFE_WINDOW_WIDTH) |
| 1374 | *cols = MIN_SAFE_WINDOW_WIDTH; |
| 1375 | } |
| 1376 | |
| 1377 | /* Normally the window is deleted if it gets too small. |
| 1378 | nodelete nonzero means do not do this. |
| 1379 | (The caller should check later and do so if appropriate) */ |
| 1380 | |
| 1381 | set_window_height (window, height, nodelete) |
| 1382 | Lisp_Object window; |
| 1383 | int height; |
| 1384 | int nodelete; |
| 1385 | { |
| 1386 | register struct window *w = XWINDOW (window); |
| 1387 | register struct window *c; |
| 1388 | int oheight = XFASTINT (w->height); |
| 1389 | int top, pos, lastbot, opos, lastobot; |
| 1390 | Lisp_Object child; |
| 1391 | |
| 1392 | check_min_window_sizes (); |
| 1393 | |
| 1394 | if (!nodelete |
| 1395 | && ! NILP (w->parent) |
| 1396 | && height < window_min_height) |
| 1397 | { |
| 1398 | Fdelete_window (window); |
| 1399 | return; |
| 1400 | } |
| 1401 | |
| 1402 | XFASTINT (w->last_modified) = 0; |
| 1403 | windows_or_buffers_changed++; |
| 1404 | XFASTINT (w->height) = height; |
| 1405 | if (!NILP (w->hchild)) |
| 1406 | { |
| 1407 | for (child = w->hchild; !NILP (child); child = XWINDOW (child)->next) |
| 1408 | { |
| 1409 | XWINDOW (child)->top = w->top; |
| 1410 | set_window_height (child, height, nodelete); |
| 1411 | } |
| 1412 | } |
| 1413 | else if (!NILP (w->vchild)) |
| 1414 | { |
| 1415 | lastbot = top = XFASTINT (w->top); |
| 1416 | lastobot = 0; |
| 1417 | for (child = w->vchild; !NILP (child); child = c->next) |
| 1418 | { |
| 1419 | c = XWINDOW (child); |
| 1420 | |
| 1421 | opos = lastobot + XFASTINT (c->height); |
| 1422 | |
| 1423 | XFASTINT (c->top) = lastbot; |
| 1424 | |
| 1425 | pos = (((opos * height) << 1) + oheight) / (oheight << 1); |
| 1426 | |
| 1427 | /* Avoid confusion: inhibit deletion of child if becomes too small */ |
| 1428 | set_window_height (child, pos + top - lastbot, 1); |
| 1429 | |
| 1430 | /* Now advance child to next window, |
| 1431 | and set lastbot if child was not just deleted. */ |
| 1432 | lastbot = pos + top; |
| 1433 | lastobot = opos; |
| 1434 | } |
| 1435 | /* Now delete any children that became too small. */ |
| 1436 | if (!nodelete) |
| 1437 | for (child = w->vchild; !NILP (child); child = XWINDOW (child)->next) |
| 1438 | { |
| 1439 | set_window_height (child, XINT (XWINDOW (child)->height), 0); |
| 1440 | } |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | /* Recursively set width of WINDOW and its inferiors. */ |
| 1445 | |
| 1446 | set_window_width (window, width, nodelete) |
| 1447 | Lisp_Object window; |
| 1448 | int width; |
| 1449 | int nodelete; |
| 1450 | { |
| 1451 | register struct window *w = XWINDOW (window); |
| 1452 | register struct window *c; |
| 1453 | int owidth = XFASTINT (w->width); |
| 1454 | int left, pos, lastright, opos, lastoright; |
| 1455 | Lisp_Object child; |
| 1456 | |
| 1457 | if (!nodelete && width < window_min_width) |
| 1458 | { |
| 1459 | Fdelete_window (window); |
| 1460 | return; |
| 1461 | } |
| 1462 | |
| 1463 | XFASTINT (w->last_modified) = 0; |
| 1464 | windows_or_buffers_changed++; |
| 1465 | XFASTINT (w->width) = width; |
| 1466 | if (!NILP (w->vchild)) |
| 1467 | { |
| 1468 | for (child = w->vchild; !NILP (child); child = XWINDOW (child)->next) |
| 1469 | { |
| 1470 | XWINDOW (child)->left = w->left; |
| 1471 | set_window_width (child, width, nodelete); |
| 1472 | } |
| 1473 | } |
| 1474 | else if (!NILP (w->hchild)) |
| 1475 | { |
| 1476 | lastright = left = XFASTINT (w->left); |
| 1477 | lastoright = 0; |
| 1478 | for (child = w->hchild; !NILP (child); child = c->next) |
| 1479 | { |
| 1480 | c = XWINDOW (child); |
| 1481 | |
| 1482 | opos = lastoright + XFASTINT (c->width); |
| 1483 | |
| 1484 | XFASTINT (c->left) = lastright; |
| 1485 | |
| 1486 | pos = (((opos * width) << 1) + owidth) / (owidth << 1); |
| 1487 | |
| 1488 | /* Inhibit deletion for becoming too small */ |
| 1489 | set_window_width (child, pos + left - lastright, 1); |
| 1490 | |
| 1491 | /* Now advance child to next window, |
| 1492 | and set lastright if child was not just deleted. */ |
| 1493 | lastright = pos + left, lastoright = opos; |
| 1494 | } |
| 1495 | /* Delete children that became too small */ |
| 1496 | if (!nodelete) |
| 1497 | for (child = w->hchild; !NILP (child); child = XWINDOW (child)->next) |
| 1498 | { |
| 1499 | set_window_width (child, XINT (XWINDOW (child)->width), 0); |
| 1500 | } |
| 1501 | } |
| 1502 | } |
| 1503 | \f |
| 1504 | int window_select_count; |
| 1505 | |
| 1506 | DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 2, 0, |
| 1507 | "Make WINDOW display BUFFER as its contents.\n\ |
| 1508 | BUFFER can be a buffer or buffer name.") |
| 1509 | (window, buffer) |
| 1510 | register Lisp_Object window, buffer; |
| 1511 | { |
| 1512 | register Lisp_Object tem; |
| 1513 | register struct window *w = decode_window (window); |
| 1514 | |
| 1515 | buffer = Fget_buffer (buffer); |
| 1516 | CHECK_BUFFER (buffer, 1); |
| 1517 | |
| 1518 | if (NILP (XBUFFER (buffer)->name)) |
| 1519 | error ("Attempt to display deleted buffer"); |
| 1520 | |
| 1521 | tem = w->buffer; |
| 1522 | if (NILP (tem)) |
| 1523 | error ("Window is deleted"); |
| 1524 | else if (! EQ (tem, Qt)) /* w->buffer is t when the window |
| 1525 | is first being set up. */ |
| 1526 | { |
| 1527 | if (!NILP (w->dedicated) && !EQ (tem, buffer)) |
| 1528 | error ("Window is dedicated to %s\n", tem); |
| 1529 | |
| 1530 | unshow_buffer (w); |
| 1531 | } |
| 1532 | |
| 1533 | w->buffer = buffer; |
| 1534 | w->hscroll = 0; |
| 1535 | Fset_marker (w->pointm, |
| 1536 | make_number (BUF_PT (XBUFFER (buffer))), |
| 1537 | buffer); |
| 1538 | set_marker_restricted (w->start, |
| 1539 | make_number (XBUFFER (buffer)->last_window_start), |
| 1540 | buffer); |
| 1541 | w->start_at_line_beg = Qnil; |
| 1542 | w->force_start = Qnil; |
| 1543 | XFASTINT (w->last_modified) = 0; |
| 1544 | windows_or_buffers_changed++; |
| 1545 | if (EQ (window, selected_window)) |
| 1546 | Fset_buffer (buffer); |
| 1547 | |
| 1548 | return Qnil; |
| 1549 | } |
| 1550 | |
| 1551 | DEFUN ("select-window", Fselect_window, Sselect_window, 1, 1, 0, |
| 1552 | "Select WINDOW. Most editing will apply to WINDOW's buffer.\n\ |
| 1553 | The main editor command loop selects the buffer of the selected window\n\ |
| 1554 | before each command.") |
| 1555 | (window) |
| 1556 | register Lisp_Object window; |
| 1557 | { |
| 1558 | register struct window *w; |
| 1559 | register struct window *ow = XWINDOW (selected_window); |
| 1560 | |
| 1561 | CHECK_LIVE_WINDOW (window, 0); |
| 1562 | |
| 1563 | w = XWINDOW (window); |
| 1564 | |
| 1565 | if (NILP (w->buffer)) |
| 1566 | error ("Trying to select deleted window or non-leaf window"); |
| 1567 | |
| 1568 | XFASTINT (w->use_time) = ++window_select_count; |
| 1569 | if (EQ (window, selected_window)) |
| 1570 | return window; |
| 1571 | |
| 1572 | Fset_marker (ow->pointm, make_number (BUF_PT (XBUFFER (ow->buffer))), |
| 1573 | ow->buffer); |
| 1574 | |
| 1575 | selected_window = window; |
| 1576 | #ifdef MULTI_FRAME |
| 1577 | if (XFRAME (WINDOW_FRAME (w)) != selected_frame) |
| 1578 | { |
| 1579 | XFRAME (WINDOW_FRAME (w))->selected_window = window; |
| 1580 | Fhandle_switch_frame (WINDOW_FRAME (w), Qnil); |
| 1581 | } |
| 1582 | else |
| 1583 | selected_frame->selected_window = window; |
| 1584 | #endif |
| 1585 | |
| 1586 | record_buffer (w->buffer); |
| 1587 | Fset_buffer (w->buffer); |
| 1588 | |
| 1589 | /* Go to the point recorded in the window. |
| 1590 | This is important when the buffer is in more |
| 1591 | than one window. It also matters when |
| 1592 | redisplay_window has altered point after scrolling, |
| 1593 | because it makes the change only in the window. */ |
| 1594 | { |
| 1595 | register int new_point = marker_position (w->pointm); |
| 1596 | if (new_point < BEGV) |
| 1597 | SET_PT (BEGV); |
| 1598 | if (new_point > ZV) |
| 1599 | SET_PT (ZV); |
| 1600 | else |
| 1601 | SET_PT (new_point); |
| 1602 | } |
| 1603 | |
| 1604 | windows_or_buffers_changed++; |
| 1605 | return window; |
| 1606 | } |
| 1607 | |
| 1608 | DEFUN ("display-buffer", Fdisplay_buffer, Sdisplay_buffer, 1, 2, |
| 1609 | "BDisplay buffer: \nP", |
| 1610 | "Make BUFFER appear in some window but don't select it.\n\ |
| 1611 | BUFFER can be a buffer or a buffer name.\n\ |
| 1612 | If BUFFER is shown already in some window, just use that one,\n\ |
| 1613 | unless the window is the selected window and the optional second\n\ |
| 1614 | argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).\n\ |
| 1615 | Returns the window displaying BUFFER.") |
| 1616 | (buffer, not_this_window) |
| 1617 | register Lisp_Object buffer, not_this_window; |
| 1618 | { |
| 1619 | register Lisp_Object window; |
| 1620 | |
| 1621 | buffer = Fget_buffer (buffer); |
| 1622 | CHECK_BUFFER (buffer, 0); |
| 1623 | |
| 1624 | if (!NILP (Vdisplay_buffer_function)) |
| 1625 | return call2 (Vdisplay_buffer_function, buffer, not_this_window); |
| 1626 | |
| 1627 | if (NILP (not_this_window) |
| 1628 | && XBUFFER (XWINDOW (selected_window)->buffer) == XBUFFER (buffer)) |
| 1629 | return selected_window; |
| 1630 | |
| 1631 | window = Fget_buffer_window (buffer, Qnil); |
| 1632 | if (!NILP (window) |
| 1633 | && (NILP (not_this_window) || !EQ (window, selected_window))) |
| 1634 | return window; |
| 1635 | |
| 1636 | #ifdef MULTI_FRAME |
| 1637 | /* If there are no frames open that have more than a minibuffer, |
| 1638 | we need to create a new frame. */ |
| 1639 | if (pop_up_frames || last_nonminibuf_frame == 0) |
| 1640 | { |
| 1641 | window |
| 1642 | = Fframe_selected_window (call0 (Vpop_up_frame_function)); |
| 1643 | Fset_window_buffer (window, buffer); |
| 1644 | #if 0 |
| 1645 | Fhandle_switch_frame (XWINDOW (window)->frame, Qnil); |
| 1646 | #endif |
| 1647 | return window; |
| 1648 | } |
| 1649 | #endif /* MULTI_FRAME */ |
| 1650 | |
| 1651 | if (pop_up_windows |
| 1652 | #ifdef MULTI_FRAME |
| 1653 | || FRAME_MINIBUF_ONLY_P (selected_frame) |
| 1654 | #endif |
| 1655 | ) |
| 1656 | { |
| 1657 | Lisp_Object frames = Qnil; |
| 1658 | |
| 1659 | #ifdef MULTI_FRAME |
| 1660 | if (FRAME_MINIBUF_ONLY_P (selected_frame)) |
| 1661 | XSET (frames, Lisp_Frame, last_nonminibuf_frame); |
| 1662 | #endif |
| 1663 | /* Don't try to create a window if would get an error */ |
| 1664 | if (split_height_threshold < window_min_height << 1) |
| 1665 | split_height_threshold = window_min_height << 1; |
| 1666 | |
| 1667 | window = Fget_largest_window (frames); |
| 1668 | |
| 1669 | if (!NILP (window) |
| 1670 | && window_height (window) >= split_height_threshold |
| 1671 | && (XFASTINT (XWINDOW (window)->width) |
| 1672 | == FRAME_WIDTH (XFRAME (WINDOW_FRAME (XWINDOW (window)))))) |
| 1673 | window = Fsplit_window (window, Qnil, Qnil); |
| 1674 | else |
| 1675 | { |
| 1676 | window = Fget_lru_window (frames); |
| 1677 | if ((EQ (window, selected_window) |
| 1678 | || EQ (XWINDOW (window)->parent, Qnil)) |
| 1679 | && window_height (window) >= window_min_height << 1) |
| 1680 | window = Fsplit_window (window, Qnil, Qnil); |
| 1681 | } |
| 1682 | } |
| 1683 | else |
| 1684 | window = Fget_lru_window (Qnil); |
| 1685 | |
| 1686 | Fset_window_buffer (window, buffer); |
| 1687 | return window; |
| 1688 | } |
| 1689 | |
| 1690 | void |
| 1691 | temp_output_buffer_show (buf) |
| 1692 | register Lisp_Object buf; |
| 1693 | { |
| 1694 | register struct buffer *old = current_buffer; |
| 1695 | register Lisp_Object window; |
| 1696 | register struct window *w; |
| 1697 | |
| 1698 | Fset_buffer (buf); |
| 1699 | XBUFFER (buf)->save_modified = MODIFF; |
| 1700 | BEGV = BEG; |
| 1701 | ZV = Z; |
| 1702 | SET_PT (BEG); |
| 1703 | clip_changed = 1; |
| 1704 | set_buffer_internal (old); |
| 1705 | |
| 1706 | if (!EQ (Vtemp_buffer_show_function, Qnil)) |
| 1707 | call1 (Vtemp_buffer_show_function, buf); |
| 1708 | else |
| 1709 | { |
| 1710 | window = Fdisplay_buffer (buf, Qnil); |
| 1711 | |
| 1712 | #ifdef MULTI_FRAME |
| 1713 | if (XFRAME (XWINDOW (window)->frame) != selected_frame) |
| 1714 | Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window))); |
| 1715 | #endif /* MULTI_FRAME */ |
| 1716 | Vminibuf_scroll_window = window; |
| 1717 | w = XWINDOW (window); |
| 1718 | XFASTINT (w->hscroll) = 0; |
| 1719 | set_marker_restricted (w->start, make_number (1), buf); |
| 1720 | set_marker_restricted (w->pointm, make_number (1), buf); |
| 1721 | } |
| 1722 | } |
| 1723 | \f |
| 1724 | static |
| 1725 | make_dummy_parent (window) |
| 1726 | Lisp_Object window; |
| 1727 | { |
| 1728 | register Lisp_Object old, new; |
| 1729 | register struct window *o, *p; |
| 1730 | |
| 1731 | old = window; |
| 1732 | XSETTYPE (old, Lisp_Vector); |
| 1733 | new = Fcopy_sequence (old); |
| 1734 | XSETTYPE (new, Lisp_Window); |
| 1735 | |
| 1736 | o = XWINDOW (old); |
| 1737 | p = XWINDOW (new); |
| 1738 | XFASTINT (p->sequence_number) = ++sequence_number; |
| 1739 | |
| 1740 | /* Put new into window structure in place of window */ |
| 1741 | replace_window (window, new); |
| 1742 | |
| 1743 | o->next = Qnil; |
| 1744 | o->prev = Qnil; |
| 1745 | o->vchild = Qnil; |
| 1746 | o->hchild = Qnil; |
| 1747 | o->parent = new; |
| 1748 | |
| 1749 | p->start = Qnil; |
| 1750 | p->pointm = Qnil; |
| 1751 | p->buffer = Qnil; |
| 1752 | } |
| 1753 | |
| 1754 | DEFUN ("split-window", Fsplit_window, Ssplit_window, 0, 3, "", |
| 1755 | "Split WINDOW, putting SIZE lines in the first of the pair.\n\ |
| 1756 | WINDOW defaults to selected one and SIZE to half its size.\n\ |
| 1757 | If optional third arg HOR-FLAG is non-nil, split side by side\n\ |
| 1758 | and put SIZE columns in the first of the pair.") |
| 1759 | (window, chsize, horflag) |
| 1760 | Lisp_Object window, chsize, horflag; |
| 1761 | { |
| 1762 | register Lisp_Object new; |
| 1763 | register struct window *o, *p; |
| 1764 | register int size; |
| 1765 | |
| 1766 | if (NILP (window)) |
| 1767 | window = selected_window; |
| 1768 | else |
| 1769 | CHECK_LIVE_WINDOW (window, 0); |
| 1770 | |
| 1771 | o = XWINDOW (window); |
| 1772 | |
| 1773 | if (NILP (chsize)) |
| 1774 | { |
| 1775 | if (!NILP (horflag)) |
| 1776 | /* Round odd size up, since this is for the left-hand window, |
| 1777 | and it will lose a column for the separators. */ |
| 1778 | size = ((XFASTINT (o->width) + 1) & -2) >> 1; |
| 1779 | else |
| 1780 | size = XFASTINT (o->height) >> 1; |
| 1781 | } |
| 1782 | else |
| 1783 | { |
| 1784 | CHECK_NUMBER (chsize, 1); |
| 1785 | size = XINT (chsize); |
| 1786 | } |
| 1787 | |
| 1788 | if (MINI_WINDOW_P (o)) |
| 1789 | error ("Attempt to split minibuffer window"); |
| 1790 | else if (FRAME_NO_SPLIT_P (XFRAME (WINDOW_FRAME (o)))) |
| 1791 | error ("Attempt to split unsplittable frame"); |
| 1792 | |
| 1793 | check_min_window_sizes (); |
| 1794 | |
| 1795 | if (NILP (horflag)) |
| 1796 | { |
| 1797 | if (size < window_min_height |
| 1798 | || size + window_min_height > XFASTINT (o->height)) |
| 1799 | args_out_of_range_3 (window, chsize, horflag); |
| 1800 | if (NILP (o->parent) |
| 1801 | || NILP (XWINDOW (o->parent)->vchild)) |
| 1802 | { |
| 1803 | make_dummy_parent (window); |
| 1804 | new = o->parent; |
| 1805 | XWINDOW (new)->vchild = window; |
| 1806 | } |
| 1807 | } |
| 1808 | else |
| 1809 | { |
| 1810 | if (size < window_min_width |
| 1811 | || size + window_min_width > XFASTINT (o->width)) |
| 1812 | args_out_of_range_3 (window, chsize, horflag); |
| 1813 | if (NILP (o->parent) |
| 1814 | || NILP (XWINDOW (o->parent)->hchild)) |
| 1815 | { |
| 1816 | make_dummy_parent (window); |
| 1817 | new = o->parent; |
| 1818 | XWINDOW (new)->hchild = window; |
| 1819 | } |
| 1820 | } |
| 1821 | |
| 1822 | /* Now we know that window's parent is a vertical combination |
| 1823 | if we are dividing vertically, or a horizontal combination |
| 1824 | if we are making side-by-side windows */ |
| 1825 | |
| 1826 | windows_or_buffers_changed++; |
| 1827 | new = make_window (); |
| 1828 | p = XWINDOW (new); |
| 1829 | |
| 1830 | p->frame = o->frame; |
| 1831 | p->next = o->next; |
| 1832 | if (!NILP (p->next)) |
| 1833 | XWINDOW (p->next)->prev = new; |
| 1834 | p->prev = window; |
| 1835 | o->next = new; |
| 1836 | p->parent = o->parent; |
| 1837 | p->buffer = Qt; |
| 1838 | |
| 1839 | Fset_window_buffer (new, o->buffer); |
| 1840 | |
| 1841 | /* Apportion the available frame space among the two new windows */ |
| 1842 | |
| 1843 | if (!NILP (horflag)) |
| 1844 | { |
| 1845 | p->height = o->height; |
| 1846 | p->top = o->top; |
| 1847 | XFASTINT (p->width) = XFASTINT (o->width) - size; |
| 1848 | XFASTINT (o->width) = size; |
| 1849 | XFASTINT (p->left) = XFASTINT (o->left) + size; |
| 1850 | } |
| 1851 | else |
| 1852 | { |
| 1853 | p->left = o->left; |
| 1854 | p->width = o->width; |
| 1855 | XFASTINT (p->height) = XFASTINT (o->height) - size; |
| 1856 | XFASTINT (o->height) = size; |
| 1857 | XFASTINT (p->top) = XFASTINT (o->top) + size; |
| 1858 | } |
| 1859 | |
| 1860 | return new; |
| 1861 | } |
| 1862 | \f |
| 1863 | DEFUN ("enlarge-window", Fenlarge_window, Senlarge_window, 1, 2, "p", |
| 1864 | "Make current window ARG lines bigger.\n\ |
| 1865 | From program, optional second arg non-nil means grow sideways ARG columns.") |
| 1866 | (n, side) |
| 1867 | register Lisp_Object n, side; |
| 1868 | { |
| 1869 | CHECK_NUMBER (n, 0); |
| 1870 | change_window_height (XINT (n), !NILP (side)); |
| 1871 | return Qnil; |
| 1872 | } |
| 1873 | |
| 1874 | DEFUN ("shrink-window", Fshrink_window, Sshrink_window, 1, 2, "p", |
| 1875 | "Make current window ARG lines smaller.\n\ |
| 1876 | From program, optional second arg non-nil means shrink sideways ARG columns.") |
| 1877 | (n, side) |
| 1878 | register Lisp_Object n, side; |
| 1879 | { |
| 1880 | CHECK_NUMBER (n, 0); |
| 1881 | change_window_height (-XINT (n), !NILP (side)); |
| 1882 | return Qnil; |
| 1883 | } |
| 1884 | |
| 1885 | int |
| 1886 | window_height (window) |
| 1887 | Lisp_Object window; |
| 1888 | { |
| 1889 | register struct window *p = XWINDOW (window); |
| 1890 | return XFASTINT (p->height); |
| 1891 | } |
| 1892 | |
| 1893 | int |
| 1894 | window_width (window) |
| 1895 | Lisp_Object window; |
| 1896 | { |
| 1897 | register struct window *p = XWINDOW (window); |
| 1898 | return XFASTINT (p->width); |
| 1899 | } |
| 1900 | |
| 1901 | #define MINSIZE(w) \ |
| 1902 | (widthflag \ |
| 1903 | ? window_min_width \ |
| 1904 | : (MINI_WINDOW_P (XWINDOW (w)) ? 1 : window_min_height)) |
| 1905 | |
| 1906 | #define CURBEG(w) \ |
| 1907 | *(widthflag ? (int *) &(XWINDOW (w)->left) : (int *) &(XWINDOW (w)->top)) |
| 1908 | |
| 1909 | #define CURSIZE(w) \ |
| 1910 | *(widthflag ? (int *) &(XWINDOW (w)->width) : (int *) &(XWINDOW (w)->height)) |
| 1911 | |
| 1912 | /* Unlike set_window_height, this function |
| 1913 | also changes the heights of the siblings so as to |
| 1914 | keep everything consistent. */ |
| 1915 | |
| 1916 | change_window_height (delta, widthflag) |
| 1917 | register int delta; |
| 1918 | int widthflag; |
| 1919 | { |
| 1920 | register Lisp_Object parent; |
| 1921 | Lisp_Object window; |
| 1922 | register struct window *p; |
| 1923 | int *sizep; |
| 1924 | int (*sizefun) () = widthflag ? window_width : window_height; |
| 1925 | register int (*setsizefun) () = (widthflag |
| 1926 | ? set_window_width |
| 1927 | : set_window_height); |
| 1928 | |
| 1929 | check_min_window_sizes (); |
| 1930 | |
| 1931 | window = selected_window; |
| 1932 | while (1) |
| 1933 | { |
| 1934 | p = XWINDOW (window); |
| 1935 | parent = p->parent; |
| 1936 | if (NILP (parent)) |
| 1937 | { |
| 1938 | if (widthflag) |
| 1939 | error ("No other window to side of this one"); |
| 1940 | break; |
| 1941 | } |
| 1942 | if (widthflag ? !NILP (XWINDOW (parent)->hchild) |
| 1943 | : !NILP (XWINDOW (parent)->vchild)) |
| 1944 | break; |
| 1945 | window = parent; |
| 1946 | } |
| 1947 | |
| 1948 | sizep = &CURSIZE (window); |
| 1949 | |
| 1950 | if (*sizep + delta < MINSIZE (window)) |
| 1951 | { |
| 1952 | Fdelete_window (window); |
| 1953 | return; |
| 1954 | } |
| 1955 | |
| 1956 | { |
| 1957 | register int maxdelta; |
| 1958 | |
| 1959 | maxdelta = (!NILP (parent) ? (*sizefun) (parent) - *sizep |
| 1960 | : !NILP (p->next) ? (*sizefun) (p->next) - MINSIZE (p->next) |
| 1961 | : !NILP (p->prev) ? (*sizefun) (p->prev) - MINSIZE (p->prev) |
| 1962 | /* This is a frame with only one window, a minibuffer-only |
| 1963 | or a minibufferless frame. */ |
| 1964 | : (delta = 0)); |
| 1965 | |
| 1966 | if (delta > maxdelta) |
| 1967 | /* This case traps trying to make the minibuffer |
| 1968 | the full frame, or make the only window aside from the |
| 1969 | minibuffer the full frame. */ |
| 1970 | delta = maxdelta; |
| 1971 | |
| 1972 | if (delta == 0) |
| 1973 | return; |
| 1974 | } |
| 1975 | |
| 1976 | if (!NILP (p->next) && |
| 1977 | (*sizefun) (p->next) - delta >= MINSIZE (p->next)) |
| 1978 | { |
| 1979 | (*setsizefun) (p->next, (*sizefun) (p->next) - delta, 0); |
| 1980 | (*setsizefun) (window, *sizep + delta, 0); |
| 1981 | CURBEG (p->next) += delta; |
| 1982 | /* This does not change size of p->next, |
| 1983 | but it propagates the new top edge to its children */ |
| 1984 | (*setsizefun) (p->next, (*sizefun) (p->next), 0); |
| 1985 | } |
| 1986 | else if (!NILP (p->prev) && |
| 1987 | (*sizefun) (p->prev) - delta >= MINSIZE (p->prev)) |
| 1988 | { |
| 1989 | (*setsizefun) (p->prev, (*sizefun) (p->prev) - delta, 0); |
| 1990 | CURBEG (window) -= delta; |
| 1991 | (*setsizefun) (window, *sizep + delta, 0); |
| 1992 | } |
| 1993 | else |
| 1994 | { |
| 1995 | register int delta1; |
| 1996 | register int opht = (*sizefun) (parent); |
| 1997 | |
| 1998 | /* If trying to grow this window to or beyond size of the parent, |
| 1999 | make delta1 so big that, on shrinking back down, |
| 2000 | all the siblings end up with less than one line and are deleted. */ |
| 2001 | if (opht <= *sizep + delta) |
| 2002 | delta1 = opht * opht * 2; |
| 2003 | /* Otherwise, make delta1 just right so that if we add delta1 |
| 2004 | lines to this window and to the parent, and then shrink |
| 2005 | the parent back to its original size, the new proportional |
| 2006 | size of this window will increase by delta. */ |
| 2007 | else |
| 2008 | delta1 = (delta * opht * 100) / ((opht - *sizep - delta) * 100); |
| 2009 | |
| 2010 | /* Add delta1 lines or columns to this window, and to the parent, |
| 2011 | keeping things consistent while not affecting siblings. */ |
| 2012 | CURSIZE (parent) = opht + delta1; |
| 2013 | (*setsizefun) (window, *sizep + delta1, 0); |
| 2014 | |
| 2015 | /* Squeeze out delta1 lines or columns from our parent, |
| 2016 | shriking this window and siblings proportionately. |
| 2017 | This brings parent back to correct size. |
| 2018 | Delta1 was calculated so this makes this window the desired size, |
| 2019 | taking it all out of the siblings. */ |
| 2020 | (*setsizefun) (parent, opht, 0); |
| 2021 | } |
| 2022 | |
| 2023 | XFASTINT (p->last_modified) = 0; |
| 2024 | } |
| 2025 | #undef MINSIZE |
| 2026 | #undef CURBEG |
| 2027 | #undef CURSIZE |
| 2028 | |
| 2029 | \f |
| 2030 | /* Return number of lines of text (not counting mode line) in W. */ |
| 2031 | |
| 2032 | int |
| 2033 | window_internal_height (w) |
| 2034 | struct window *w; |
| 2035 | { |
| 2036 | int ht = XFASTINT (w->height); |
| 2037 | |
| 2038 | if (MINI_WINDOW_P (w)) |
| 2039 | return ht; |
| 2040 | |
| 2041 | if (!NILP (w->parent) || !NILP (w->vchild) || !NILP (w->hchild) |
| 2042 | || !NILP (w->next) || !NILP (w->prev) |
| 2043 | || FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME (w)))) |
| 2044 | return ht - 1; |
| 2045 | |
| 2046 | return ht; |
| 2047 | } |
| 2048 | |
| 2049 | |
| 2050 | /* Return the number of columns in W. |
| 2051 | Don't count columns occupied by scroll bars or the vertical bar |
| 2052 | separating W from the sibling to its right. */ |
| 2053 | int |
| 2054 | window_internal_width (w) |
| 2055 | struct window *w; |
| 2056 | { |
| 2057 | FRAME_PTR f = XFRAME (WINDOW_FRAME (w)); |
| 2058 | int left = XINT (w->left); |
| 2059 | int width = XINT (w->width); |
| 2060 | |
| 2061 | /* If this window is flush against the right edge of the frame, its |
| 2062 | internal width is its full width. */ |
| 2063 | if (left + width >= FRAME_WIDTH (f)) |
| 2064 | return width; |
| 2065 | |
| 2066 | /* If we are not flush right, then our rightmost columns are |
| 2067 | occupied by some sort of separator. */ |
| 2068 | |
| 2069 | /* Scroll bars occupy a few columns. */ |
| 2070 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) |
| 2071 | return width - VERTICAL_SCROLL_BAR_WIDTH; |
| 2072 | |
| 2073 | /* The column of `|' characters separating side-by-side windows |
| 2074 | occupies one column only. */ |
| 2075 | return width - 1; |
| 2076 | } |
| 2077 | |
| 2078 | |
| 2079 | /* Scroll contents of window WINDOW up N lines. */ |
| 2080 | |
| 2081 | void |
| 2082 | window_scroll (window, n, noerror) |
| 2083 | Lisp_Object window; |
| 2084 | int n; |
| 2085 | int noerror; |
| 2086 | { |
| 2087 | register struct window *w = XWINDOW (window); |
| 2088 | register int opoint = point; |
| 2089 | register int pos; |
| 2090 | register int ht = window_internal_height (w); |
| 2091 | register Lisp_Object tem; |
| 2092 | int lose; |
| 2093 | Lisp_Object bolp, nmoved; |
| 2094 | |
| 2095 | XFASTINT (tem) = point; |
| 2096 | tem = Fpos_visible_in_window_p (tem, window); |
| 2097 | |
| 2098 | if (NILP (tem)) |
| 2099 | { |
| 2100 | Fvertical_motion (make_number (- ht / 2)); |
| 2101 | XFASTINT (tem) = point; |
| 2102 | Fset_marker (w->start, tem, w->buffer); |
| 2103 | w->force_start = Qt; |
| 2104 | } |
| 2105 | |
| 2106 | SET_PT (marker_position (w->start)); |
| 2107 | lose = n < 0 && point == BEGV; |
| 2108 | Fvertical_motion (make_number (n)); |
| 2109 | pos = point; |
| 2110 | bolp = Fbolp (); |
| 2111 | SET_PT (opoint); |
| 2112 | |
| 2113 | if (lose) |
| 2114 | { |
| 2115 | if (noerror) |
| 2116 | return; |
| 2117 | else |
| 2118 | Fsignal (Qbeginning_of_buffer, Qnil); |
| 2119 | } |
| 2120 | |
| 2121 | if (pos < ZV) |
| 2122 | { |
| 2123 | set_marker_restricted (w->start, make_number (pos), w->buffer); |
| 2124 | w->start_at_line_beg = bolp; |
| 2125 | w->update_mode_line = Qt; |
| 2126 | XFASTINT (w->last_modified) = 0; |
| 2127 | if (pos > opoint) |
| 2128 | SET_PT (pos); |
| 2129 | if (n < 0) |
| 2130 | { |
| 2131 | SET_PT (pos); |
| 2132 | tem = Fvertical_motion (make_number (ht)); |
| 2133 | if (point > opoint || XFASTINT (tem) < ht) |
| 2134 | SET_PT (opoint); |
| 2135 | else |
| 2136 | Fvertical_motion (make_number (-1)); |
| 2137 | } |
| 2138 | } |
| 2139 | else |
| 2140 | { |
| 2141 | if (noerror) |
| 2142 | return; |
| 2143 | else |
| 2144 | Fsignal (Qend_of_buffer, Qnil); |
| 2145 | } |
| 2146 | } |
| 2147 | \f |
| 2148 | /* This is the guts of Fscroll_up and Fscroll_down. */ |
| 2149 | |
| 2150 | static void |
| 2151 | scroll_command (n, direction) |
| 2152 | register Lisp_Object n; |
| 2153 | int direction; |
| 2154 | { |
| 2155 | register int defalt; |
| 2156 | int count = specpdl_ptr - specpdl; |
| 2157 | |
| 2158 | /* If selected window's buffer isn't current, make it current for the moment. |
| 2159 | But don't screw up if window_scroll gets an error. */ |
| 2160 | if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) |
| 2161 | { |
| 2162 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); |
| 2163 | Fset_buffer (XWINDOW (selected_window)->buffer); |
| 2164 | } |
| 2165 | |
| 2166 | defalt = (window_internal_height (XWINDOW (selected_window)) |
| 2167 | - next_screen_context_lines); |
| 2168 | defalt = direction * (defalt < 1 ? 1 : defalt); |
| 2169 | |
| 2170 | if (NILP (n)) |
| 2171 | window_scroll (selected_window, defalt, 0); |
| 2172 | else if (EQ (n, Qminus)) |
| 2173 | window_scroll (selected_window, - defalt, 0); |
| 2174 | else |
| 2175 | { |
| 2176 | n = Fprefix_numeric_value (n); |
| 2177 | window_scroll (selected_window, XINT (n) * direction, 0); |
| 2178 | } |
| 2179 | |
| 2180 | unbind_to (count, Qnil); |
| 2181 | } |
| 2182 | |
| 2183 | DEFUN ("scroll-up", Fscroll_up, Sscroll_up, 0, 1, "P", |
| 2184 | "Scroll text of current window upward ARG lines; or near full screen if no ARG.\n\ |
| 2185 | A near full screen is `next-screen-context-lines' less than a full screen.\n\ |
| 2186 | When calling from a program, supply a number as argument or nil.") |
| 2187 | (n) |
| 2188 | Lisp_Object n; |
| 2189 | { |
| 2190 | scroll_command (n, 1); |
| 2191 | return Qnil; |
| 2192 | } |
| 2193 | |
| 2194 | DEFUN ("scroll-down", Fscroll_down, Sscroll_down, 0, 1, "P", |
| 2195 | "Scroll text of current window downward ARG lines; or near full screen if no ARG.\n\ |
| 2196 | A near full screen is `next-screen-context-lines' less than a full screen.\n\ |
| 2197 | When calling from a program, supply a number as argument or nil.") |
| 2198 | (n) |
| 2199 | Lisp_Object n; |
| 2200 | { |
| 2201 | scroll_command (n, -1); |
| 2202 | return Qnil; |
| 2203 | } |
| 2204 | |
| 2205 | DEFUN ("scroll-other-window", Fscroll_other_window, Sscroll_other_window, 0, 1, "P", |
| 2206 | "Scroll next window upward ARG lines; or near full screen if no ARG.\n\ |
| 2207 | The next window is the one below the current one; or the one at the top\n\ |
| 2208 | if the current one is at the bottom.\n\ |
| 2209 | When calling from a program, supply a number as argument or nil.\n\ |
| 2210 | \n\ |
| 2211 | If in the minibuffer, `minibuf-scroll-window' if non-nil\n\ |
| 2212 | specifies the window to scroll.\n\ |
| 2213 | If `other-window-scroll-buffer' is non-nil, scroll the window\n\ |
| 2214 | showing that buffer, popping the buffer up if necessary.") |
| 2215 | (n) |
| 2216 | register Lisp_Object n; |
| 2217 | { |
| 2218 | register Lisp_Object window; |
| 2219 | register int ht; |
| 2220 | register struct window *w; |
| 2221 | register int count = specpdl_ptr - specpdl; |
| 2222 | |
| 2223 | if (MINI_WINDOW_P (XWINDOW (selected_window)) |
| 2224 | && !NILP (Vminibuf_scroll_window)) |
| 2225 | window = Vminibuf_scroll_window; |
| 2226 | /* If buffer is specified, scroll that buffer. */ |
| 2227 | else if (!NILP (Vother_window_scroll_buffer)) |
| 2228 | { |
| 2229 | window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil); |
| 2230 | if (NILP (window)) |
| 2231 | window = Fdisplay_buffer (Vother_window_scroll_buffer, Qt); |
| 2232 | } |
| 2233 | else |
| 2234 | { |
| 2235 | /* Nothing specified; look for a neighboring window on the same |
| 2236 | frame. */ |
| 2237 | window = Fnext_window (selected_window, Qnil, Qnil); |
| 2238 | |
| 2239 | if (EQ (window, selected_window)) |
| 2240 | /* That didn't get us anywhere; look for a window on another |
| 2241 | visible frame. */ |
| 2242 | do |
| 2243 | window = Fnext_window (window, Qnil, Qt); |
| 2244 | while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window)))) |
| 2245 | && ! EQ (window, selected_window)); |
| 2246 | } |
| 2247 | |
| 2248 | CHECK_LIVE_WINDOW (window, 0); |
| 2249 | |
| 2250 | if (EQ (window, selected_window)) |
| 2251 | error ("There is no other window"); |
| 2252 | |
| 2253 | w = XWINDOW (window); |
| 2254 | ht = window_internal_height (w); |
| 2255 | |
| 2256 | /* Don't screw up if window_scroll gets an error. */ |
| 2257 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); |
| 2258 | |
| 2259 | Fset_buffer (w->buffer); |
| 2260 | SET_PT (marker_position (w->pointm)); |
| 2261 | |
| 2262 | if (NILP (n)) |
| 2263 | window_scroll (window, ht - next_screen_context_lines, 1); |
| 2264 | else if (EQ (n, Qminus)) |
| 2265 | window_scroll (window, next_screen_context_lines - ht, 1); |
| 2266 | else |
| 2267 | { |
| 2268 | if (XTYPE (n) == Lisp_Cons) |
| 2269 | n = Fcar (n); |
| 2270 | CHECK_NUMBER (n, 0); |
| 2271 | window_scroll (window, XINT (n), 1); |
| 2272 | } |
| 2273 | |
| 2274 | Fset_marker (w->pointm, make_number (point), Qnil); |
| 2275 | unbind_to (count, Qnil); |
| 2276 | |
| 2277 | return Qnil; |
| 2278 | } |
| 2279 | \f |
| 2280 | DEFUN ("scroll-left", Fscroll_left, Sscroll_left, 0, 1, "P", |
| 2281 | "Scroll selected window display ARG columns left.\n\ |
| 2282 | Default for ARG is window width minus 2.") |
| 2283 | (arg) |
| 2284 | register Lisp_Object arg; |
| 2285 | { |
| 2286 | |
| 2287 | if (NILP (arg)) |
| 2288 | XFASTINT (arg) = window_internal_width (XWINDOW (selected_window)) - 2; |
| 2289 | else |
| 2290 | arg = Fprefix_numeric_value (arg); |
| 2291 | |
| 2292 | return |
| 2293 | Fset_window_hscroll (selected_window, |
| 2294 | make_number (XINT (XWINDOW (selected_window)->hscroll) |
| 2295 | + XINT (arg))); |
| 2296 | } |
| 2297 | |
| 2298 | DEFUN ("scroll-right", Fscroll_right, Sscroll_right, 0, 1, "P", |
| 2299 | "Scroll selected window display ARG columns right.\n\ |
| 2300 | Default for ARG is window width minus 2.") |
| 2301 | (arg) |
| 2302 | register Lisp_Object arg; |
| 2303 | { |
| 2304 | if (NILP (arg)) |
| 2305 | XFASTINT (arg) = window_internal_width (XWINDOW (selected_window)) - 2; |
| 2306 | else |
| 2307 | arg = Fprefix_numeric_value (arg); |
| 2308 | |
| 2309 | return |
| 2310 | Fset_window_hscroll (selected_window, |
| 2311 | make_number (XINT (XWINDOW (selected_window)->hscroll) |
| 2312 | - XINT (arg))); |
| 2313 | } |
| 2314 | |
| 2315 | DEFUN ("recenter", Frecenter, Srecenter, 0, 1, "P", |
| 2316 | "Center point in window and redisplay frame. With ARG, put point on line ARG.\n\ |
| 2317 | The desired position of point is always relative to the current window.\n\ |
| 2318 | Just C-u as prefix means put point in the center of the window.\n\ |
| 2319 | No arg (i.e., it is nil) erases the entire frame and then\n\ |
| 2320 | redraws with point in the center of the current window.") |
| 2321 | (n) |
| 2322 | register Lisp_Object n; |
| 2323 | { |
| 2324 | register struct window *w = XWINDOW (selected_window); |
| 2325 | register int ht = window_internal_height (w); |
| 2326 | register int opoint = point; |
| 2327 | |
| 2328 | if (NILP (n)) |
| 2329 | { |
| 2330 | extern int frame_garbaged; |
| 2331 | |
| 2332 | SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w))); |
| 2333 | XFASTINT (n) = ht / 2; |
| 2334 | } |
| 2335 | else if (XTYPE (n) == Lisp_Cons) /* Just C-u. */ |
| 2336 | { |
| 2337 | XFASTINT (n) = ht / 2; |
| 2338 | } |
| 2339 | else |
| 2340 | { |
| 2341 | n = Fprefix_numeric_value (n); |
| 2342 | CHECK_NUMBER (n, 0); |
| 2343 | } |
| 2344 | |
| 2345 | if (XINT (n) < 0) |
| 2346 | XSETINT (n, XINT (n) + ht); |
| 2347 | |
| 2348 | XSETINT (n, - XINT (n)); |
| 2349 | |
| 2350 | Fvertical_motion (n); |
| 2351 | Fset_marker (w->start, make_number (point), w->buffer); |
| 2352 | w->start_at_line_beg = Fbolp (); |
| 2353 | |
| 2354 | SET_PT (opoint); |
| 2355 | w->force_start = Qt; |
| 2356 | |
| 2357 | return Qnil; |
| 2358 | } |
| 2359 | \f |
| 2360 | DEFUN ("move-to-window-line", Fmove_to_window_line, Smove_to_window_line, |
| 2361 | 1, 1, "P", |
| 2362 | "Position point relative to window.\n\ |
| 2363 | With no argument, position text at center of window.\n\ |
| 2364 | An argument specifies frame line; zero means top of window,\n\ |
| 2365 | negative means relative to bottom of window.") |
| 2366 | (arg) |
| 2367 | register Lisp_Object arg; |
| 2368 | { |
| 2369 | register struct window *w = XWINDOW (selected_window); |
| 2370 | register int height = window_internal_height (w); |
| 2371 | register int start; |
| 2372 | |
| 2373 | if (NILP (arg)) |
| 2374 | XFASTINT (arg) = height / 2; |
| 2375 | else |
| 2376 | { |
| 2377 | arg = Fprefix_numeric_value (arg); |
| 2378 | if (XINT (arg) < 0) |
| 2379 | XSETINT (arg, XINT (arg) + height); |
| 2380 | } |
| 2381 | |
| 2382 | start = marker_position (w->start); |
| 2383 | if (start < BEGV || start > ZV) |
| 2384 | { |
| 2385 | Fvertical_motion (make_number (- height / 2)); |
| 2386 | Fset_marker (w->start, make_number (point), w->buffer); |
| 2387 | w->start_at_line_beg = Fbolp (); |
| 2388 | w->force_start = Qt; |
| 2389 | } |
| 2390 | else |
| 2391 | SET_PT (start); |
| 2392 | |
| 2393 | return Fvertical_motion (arg); |
| 2394 | } |
| 2395 | \f |
| 2396 | struct save_window_data |
| 2397 | { |
| 2398 | int size_from_Lisp_Vector_struct; |
| 2399 | struct Lisp_Vector *next_from_Lisp_Vector_struct; |
| 2400 | Lisp_Object frame_width, frame_height; |
| 2401 | Lisp_Object selected_frame; |
| 2402 | Lisp_Object current_window; |
| 2403 | Lisp_Object current_buffer; |
| 2404 | Lisp_Object minibuf_scroll_window; |
| 2405 | Lisp_Object root_window; |
| 2406 | Lisp_Object focus_frame; |
| 2407 | /* A vector, interpreted as a struct saved_window */ |
| 2408 | Lisp_Object saved_windows; |
| 2409 | }; |
| 2410 | |
| 2411 | /* Arg to Fmake_vector */ |
| 2412 | #define SAVE_WINDOW_DATA_SIZE \ |
| 2413 | ((sizeof (struct save_window_data) \ |
| 2414 | - (sizeof (struct Lisp_Vector) \ |
| 2415 | /* Don't count the contents member of the struct Lisp_Vector */ \ |
| 2416 | - sizeof (Lisp_Object))) \ |
| 2417 | / sizeof (Lisp_Object)) |
| 2418 | |
| 2419 | /* This is saved as a Lisp_Vector */ |
| 2420 | struct saved_window |
| 2421 | { |
| 2422 | /* these first two must agree with struct Lisp_Vector in lisp.h */ |
| 2423 | int size_from_Lisp_Vector_struct; |
| 2424 | struct Lisp_Vector *next_from_Lisp_Vector_struct; |
| 2425 | |
| 2426 | Lisp_Object window; |
| 2427 | Lisp_Object buffer, start, pointm, mark; |
| 2428 | Lisp_Object left, top, width, height, hscroll; |
| 2429 | Lisp_Object parent, prev; |
| 2430 | Lisp_Object start_at_line_beg; |
| 2431 | Lisp_Object display_table; |
| 2432 | }; |
| 2433 | #define SAVED_WINDOW_VECTOR_SIZE 14 /* Arg to Fmake_vector */ |
| 2434 | |
| 2435 | #define SAVED_WINDOW_N(swv,n) \ |
| 2436 | ((struct saved_window *) (XVECTOR ((swv)->contents[(n)]))) |
| 2437 | |
| 2438 | DEFUN ("window-configuration-p", Fwindow_configuration_p, Swindow_configuration_p, 1, 1, 0, |
| 2439 | "T if OBJECT is a window-configration object.") |
| 2440 | (obj) |
| 2441 | Lisp_Object obj; |
| 2442 | { |
| 2443 | if (XTYPE (obj) == Lisp_Window_Configuration) |
| 2444 | return Qt; |
| 2445 | return Qnil; |
| 2446 | } |
| 2447 | |
| 2448 | |
| 2449 | DEFUN ("set-window-configuration", Fset_window_configuration, |
| 2450 | Sset_window_configuration, 1, 1, 0, |
| 2451 | "Set the configuration of windows and buffers as specified by CONFIGURATION.\n\ |
| 2452 | CONFIGURATION must be a value previously returned\n\ |
| 2453 | by `current-window-configuration' (which see).") |
| 2454 | (configuration) |
| 2455 | Lisp_Object configuration; |
| 2456 | { |
| 2457 | register struct save_window_data *data; |
| 2458 | struct Lisp_Vector *saved_windows; |
| 2459 | Lisp_Object new_current_buffer; |
| 2460 | Lisp_Object frame; |
| 2461 | FRAME_PTR f; |
| 2462 | |
| 2463 | while (XTYPE (configuration) != Lisp_Window_Configuration) |
| 2464 | { |
| 2465 | configuration = wrong_type_argument (intern ("window-configuration-p"), |
| 2466 | configuration); |
| 2467 | } |
| 2468 | |
| 2469 | data = (struct save_window_data *) XVECTOR (configuration); |
| 2470 | saved_windows = XVECTOR (data->saved_windows); |
| 2471 | |
| 2472 | new_current_buffer = data->current_buffer; |
| 2473 | if (NILP (XBUFFER (new_current_buffer)->name)) |
| 2474 | new_current_buffer = Qnil; |
| 2475 | |
| 2476 | frame = XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame; |
| 2477 | f = XFRAME (frame); |
| 2478 | |
| 2479 | /* If f is a dead frame, don't bother rebuilding its window tree. |
| 2480 | However, there is other stuff we should still try to do below. */ |
| 2481 | if (FRAME_LIVE_P (f)) |
| 2482 | { |
| 2483 | register struct window *w; |
| 2484 | register struct saved_window *p; |
| 2485 | int k; |
| 2486 | |
| 2487 | /* If the frame has been resized since this window configuration was |
| 2488 | made, we change the frame to the size specified in the |
| 2489 | configuration, restore the configuration, and then resize it |
| 2490 | back. We keep track of the prevailing height in these variables. */ |
| 2491 | int previous_frame_height = FRAME_HEIGHT (f); |
| 2492 | int previous_frame_width = FRAME_WIDTH (f); |
| 2493 | |
| 2494 | if (XFASTINT (data->frame_height) != previous_frame_height |
| 2495 | || XFASTINT (data->frame_width) != previous_frame_width) |
| 2496 | change_frame_size (f, data->frame_height, data->frame_width, 0, 0); |
| 2497 | |
| 2498 | windows_or_buffers_changed++; |
| 2499 | |
| 2500 | /* Kludge Alert! |
| 2501 | Mark all windows now on frame as "deleted". |
| 2502 | Restoring the new configuration "undeletes" any that are in it. |
| 2503 | |
| 2504 | Save their current buffers in their height fields, since we may |
| 2505 | need it later, if a buffer saved in the configuration is now |
| 2506 | dead. */ |
| 2507 | delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f))); |
| 2508 | |
| 2509 | for (k = 0; k < saved_windows->size; k++) |
| 2510 | { |
| 2511 | p = SAVED_WINDOW_N (saved_windows, k); |
| 2512 | w = XWINDOW (p->window); |
| 2513 | w->next = Qnil; |
| 2514 | |
| 2515 | if (!NILP (p->parent)) |
| 2516 | w->parent = SAVED_WINDOW_N (saved_windows, |
| 2517 | XFASTINT (p->parent))->window; |
| 2518 | else |
| 2519 | w->parent = Qnil; |
| 2520 | |
| 2521 | if (!NILP (p->prev)) |
| 2522 | { |
| 2523 | w->prev = SAVED_WINDOW_N (saved_windows, |
| 2524 | XFASTINT (p->prev))->window; |
| 2525 | XWINDOW (w->prev)->next = p->window; |
| 2526 | } |
| 2527 | else |
| 2528 | { |
| 2529 | w->prev = Qnil; |
| 2530 | if (!NILP (w->parent)) |
| 2531 | { |
| 2532 | if (EQ (p->width, XWINDOW (w->parent)->width)) |
| 2533 | { |
| 2534 | XWINDOW (w->parent)->vchild = p->window; |
| 2535 | XWINDOW (w->parent)->hchild = Qnil; |
| 2536 | } |
| 2537 | else |
| 2538 | { |
| 2539 | XWINDOW (w->parent)->hchild = p->window; |
| 2540 | XWINDOW (w->parent)->vchild = Qnil; |
| 2541 | } |
| 2542 | } |
| 2543 | } |
| 2544 | |
| 2545 | /* If we squirreled away the buffer in the window's height, |
| 2546 | restore it now. */ |
| 2547 | if (XTYPE (w->height) == Lisp_Buffer) |
| 2548 | w->buffer = w->height; |
| 2549 | w->left = p->left; |
| 2550 | w->top = p->top; |
| 2551 | w->width = p->width; |
| 2552 | w->height = p->height; |
| 2553 | w->hscroll = p->hscroll; |
| 2554 | w->display_table = p->display_table; |
| 2555 | XFASTINT (w->last_modified) = 0; |
| 2556 | |
| 2557 | /* Reinstall the saved buffer and pointers into it. */ |
| 2558 | if (NILP (p->buffer)) |
| 2559 | w->buffer = p->buffer; |
| 2560 | else |
| 2561 | { |
| 2562 | if (!NILP (XBUFFER (p->buffer)->name)) |
| 2563 | /* If saved buffer is alive, install it. */ |
| 2564 | { |
| 2565 | w->buffer = p->buffer; |
| 2566 | w->start_at_line_beg = p->start_at_line_beg; |
| 2567 | set_marker_restricted (w->start, |
| 2568 | Fmarker_position (p->start), |
| 2569 | w->buffer); |
| 2570 | set_marker_restricted (w->pointm, |
| 2571 | Fmarker_position (p->pointm), |
| 2572 | w->buffer); |
| 2573 | Fset_marker (XBUFFER (w->buffer)->mark, |
| 2574 | Fmarker_position (p->mark), w->buffer); |
| 2575 | |
| 2576 | /* As documented in Fcurrent_window_configuration, don't |
| 2577 | save the location of point in the buffer which was current |
| 2578 | when the window configuration was recorded. */ |
| 2579 | if (!EQ (p->buffer, new_current_buffer) && |
| 2580 | XBUFFER (p->buffer) == current_buffer) |
| 2581 | Fgoto_char (w->pointm); |
| 2582 | } |
| 2583 | else if (NILP (w->buffer) || NILP (XBUFFER (w->buffer)->name)) |
| 2584 | /* Else unless window has a live buffer, get one. */ |
| 2585 | { |
| 2586 | w->buffer = Fcdr (Fcar (Vbuffer_alist)); |
| 2587 | /* This will set the markers to beginning of visible |
| 2588 | range. */ |
| 2589 | set_marker_restricted (w->start, make_number (0), w->buffer); |
| 2590 | set_marker_restricted (w->pointm, make_number (0),w->buffer); |
| 2591 | w->start_at_line_beg = Qt; |
| 2592 | } |
| 2593 | else |
| 2594 | /* Keeping window's old buffer; make sure the markers |
| 2595 | are real. */ |
| 2596 | { |
| 2597 | /* Set window markers at start of visible range. */ |
| 2598 | if (XMARKER (w->start)->buffer == 0) |
| 2599 | set_marker_restricted (w->start, make_number (0), |
| 2600 | w->buffer); |
| 2601 | if (XMARKER (w->pointm)->buffer == 0) |
| 2602 | set_marker_restricted (w->pointm, |
| 2603 | (make_number |
| 2604 | (BUF_PT (XBUFFER (w->buffer)))), |
| 2605 | w->buffer); |
| 2606 | w->start_at_line_beg = Qt; |
| 2607 | } |
| 2608 | } |
| 2609 | } |
| 2610 | |
| 2611 | FRAME_ROOT_WINDOW (f) = data->root_window; |
| 2612 | Fselect_window (data->current_window); |
| 2613 | |
| 2614 | #ifdef MULTI_FRAME |
| 2615 | if (NILP (data->focus_frame) |
| 2616 | || (XTYPE (data->focus_frame) == Lisp_Frame |
| 2617 | && FRAME_LIVE_P (XFRAME (data->focus_frame)))) |
| 2618 | Fredirect_frame_focus (frame, data->focus_frame); |
| 2619 | #endif |
| 2620 | |
| 2621 | #if 0 /* I don't understand why this is needed, and it causes problems |
| 2622 | when the frame's old selected window has been deleted. */ |
| 2623 | #ifdef MULTI_FRAME |
| 2624 | if (f != selected_frame && ! FRAME_TERMCAP_P (f)) |
| 2625 | Fhandle_switch_frame (WINDOW_FRAME (XWINDOW (data->root_window)), Qnil); |
| 2626 | #endif |
| 2627 | #endif |
| 2628 | |
| 2629 | /* Set the screen height to the value it had before this function. */ |
| 2630 | if (previous_frame_height != FRAME_HEIGHT (f) |
| 2631 | || previous_frame_width != FRAME_WIDTH (f)) |
| 2632 | change_frame_size (f, previous_frame_height, previous_frame_width, |
| 2633 | 0, 0); |
| 2634 | } |
| 2635 | |
| 2636 | #ifdef MULTI_FRAME |
| 2637 | /* Fselect_window will have made f the selected frame, so we |
| 2638 | reselect the proper frame here. Fhandle_switch_frame will change the |
| 2639 | selected window too, but that doesn't make the call to |
| 2640 | Fselect_window above totally superfluous; it still sets f's |
| 2641 | selected window. */ |
| 2642 | if (FRAME_LIVE_P (XFRAME (data->selected_frame))) |
| 2643 | Fhandle_switch_frame (data->selected_frame, Qnil); |
| 2644 | #endif |
| 2645 | |
| 2646 | if (!NILP (new_current_buffer)) |
| 2647 | Fset_buffer (new_current_buffer); |
| 2648 | |
| 2649 | Vminibuf_scroll_window = data->minibuf_scroll_window; |
| 2650 | return (Qnil); |
| 2651 | } |
| 2652 | |
| 2653 | /* Mark all windows now on frame as deleted |
| 2654 | by setting their buffers to nil. */ |
| 2655 | |
| 2656 | void |
| 2657 | delete_all_subwindows (w) |
| 2658 | register struct window *w; |
| 2659 | { |
| 2660 | if (!NILP (w->next)) |
| 2661 | delete_all_subwindows (XWINDOW (w->next)); |
| 2662 | if (!NILP (w->vchild)) |
| 2663 | delete_all_subwindows (XWINDOW (w->vchild)); |
| 2664 | if (!NILP (w->hchild)) |
| 2665 | delete_all_subwindows (XWINDOW (w->hchild)); |
| 2666 | |
| 2667 | w->height = w->buffer; /* See Fset_window_configuration for excuse. */ |
| 2668 | |
| 2669 | /* We set all three of these fields to nil, to make sure that we can |
| 2670 | distinguish this dead window from any live window. Live leaf |
| 2671 | windows will have buffer set, and combination windows will have |
| 2672 | vchild or hchild set. */ |
| 2673 | w->buffer = Qnil; |
| 2674 | w->vchild = Qnil; |
| 2675 | w->hchild = Qnil; |
| 2676 | } |
| 2677 | \f |
| 2678 | static int |
| 2679 | count_windows (window) |
| 2680 | register struct window *window; |
| 2681 | { |
| 2682 | register int count = 1; |
| 2683 | if (!NILP (window->next)) |
| 2684 | count += count_windows (XWINDOW (window->next)); |
| 2685 | if (!NILP (window->vchild)) |
| 2686 | count += count_windows (XWINDOW (window->vchild)); |
| 2687 | if (!NILP (window->hchild)) |
| 2688 | count += count_windows (XWINDOW (window->hchild)); |
| 2689 | return count; |
| 2690 | } |
| 2691 | |
| 2692 | static int |
| 2693 | save_window_save (window, vector, i) |
| 2694 | Lisp_Object window; |
| 2695 | struct Lisp_Vector *vector; |
| 2696 | int i; |
| 2697 | { |
| 2698 | register struct saved_window *p; |
| 2699 | register struct window *w; |
| 2700 | register Lisp_Object tem; |
| 2701 | |
| 2702 | for (;!NILP (window); window = w->next) |
| 2703 | { |
| 2704 | p = SAVED_WINDOW_N (vector, i); |
| 2705 | w = XWINDOW (window); |
| 2706 | |
| 2707 | XFASTINT (w->temslot) = i++; |
| 2708 | p->window = window; |
| 2709 | p->buffer = w->buffer; |
| 2710 | p->left = w->left; |
| 2711 | p->top = w->top; |
| 2712 | p->width = w->width; |
| 2713 | p->height = w->height; |
| 2714 | p->hscroll = w->hscroll; |
| 2715 | p->display_table = w->display_table; |
| 2716 | if (!NILP (w->buffer)) |
| 2717 | { |
| 2718 | /* Save w's value of point in the window configuration. |
| 2719 | If w is the selected window, then get the value of point |
| 2720 | from the buffer; pointm is garbage in the selected window. */ |
| 2721 | if (EQ (window, selected_window)) |
| 2722 | { |
| 2723 | p->pointm = Fmake_marker (); |
| 2724 | Fset_marker (p->pointm, BUF_PT (XBUFFER (w->buffer)), |
| 2725 | w->buffer); |
| 2726 | } |
| 2727 | else |
| 2728 | p->pointm = Fcopy_marker (w->pointm); |
| 2729 | |
| 2730 | p->start = Fcopy_marker (w->start); |
| 2731 | p->start_at_line_beg = w->start_at_line_beg; |
| 2732 | |
| 2733 | tem = XBUFFER (w->buffer)->mark; |
| 2734 | p->mark = Fcopy_marker (tem); |
| 2735 | } |
| 2736 | else |
| 2737 | { |
| 2738 | p->pointm = Qnil; |
| 2739 | p->start = Qnil; |
| 2740 | p->mark = Qnil; |
| 2741 | p->start_at_line_beg = Qnil; |
| 2742 | } |
| 2743 | |
| 2744 | if (NILP (w->parent)) |
| 2745 | p->parent = Qnil; |
| 2746 | else |
| 2747 | p->parent = XWINDOW (w->parent)->temslot; |
| 2748 | |
| 2749 | if (NILP (w->prev)) |
| 2750 | p->prev = Qnil; |
| 2751 | else |
| 2752 | p->prev = XWINDOW (w->prev)->temslot; |
| 2753 | |
| 2754 | if (!NILP (w->vchild)) |
| 2755 | i = save_window_save (w->vchild, vector, i); |
| 2756 | if (!NILP (w->hchild)) |
| 2757 | i = save_window_save (w->hchild, vector, i); |
| 2758 | } |
| 2759 | |
| 2760 | return i; |
| 2761 | } |
| 2762 | |
| 2763 | DEFUN ("current-window-configuration", |
| 2764 | Fcurrent_window_configuration, Scurrent_window_configuration, 0, 1, 0, |
| 2765 | "Return an object representing the current window configuration of FRAME.\n\ |
| 2766 | If FRAME is nil or omitted, use the selected frame.\n\ |
| 2767 | This describes the number of windows, their sizes and current buffers,\n\ |
| 2768 | and for each displayed buffer, where display starts, and the positions of\n\ |
| 2769 | point and mark. An exception is made for point in the current buffer:\n\ |
| 2770 | its value is -not- saved.\n\ |
| 2771 | This also records the currently selected frame, and FRAME's focus\n\ |
| 2772 | redirection (see `redirect-frame-focus').") |
| 2773 | (frame) |
| 2774 | Lisp_Object frame; |
| 2775 | { |
| 2776 | register Lisp_Object tem; |
| 2777 | register int n_windows; |
| 2778 | register struct save_window_data *data; |
| 2779 | register int i; |
| 2780 | FRAME_PTR f; |
| 2781 | |
| 2782 | if (NILP (frame)) |
| 2783 | f = selected_frame; |
| 2784 | else |
| 2785 | { |
| 2786 | CHECK_LIVE_FRAME (frame, 0); |
| 2787 | f = XFRAME (frame); |
| 2788 | } |
| 2789 | |
| 2790 | n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f))); |
| 2791 | data = (struct save_window_data *) |
| 2792 | XVECTOR (Fmake_vector (make_number (SAVE_WINDOW_DATA_SIZE), |
| 2793 | Qnil)); |
| 2794 | XFASTINT (data->frame_width) = FRAME_WIDTH (f); |
| 2795 | XFASTINT (data->frame_height) = FRAME_HEIGHT (f); |
| 2796 | #ifdef MULTI_FRAME |
| 2797 | XSET (data->selected_frame, Lisp_Frame, selected_frame); |
| 2798 | #endif |
| 2799 | data->current_window = FRAME_SELECTED_WINDOW (f); |
| 2800 | XSET (data->current_buffer, Lisp_Buffer, current_buffer); |
| 2801 | data->minibuf_scroll_window = Vminibuf_scroll_window; |
| 2802 | data->root_window = FRAME_ROOT_WINDOW (f); |
| 2803 | data->focus_frame = FRAME_FOCUS_FRAME (f); |
| 2804 | tem = Fmake_vector (make_number (n_windows), Qnil); |
| 2805 | data->saved_windows = tem; |
| 2806 | for (i = 0; i < n_windows; i++) |
| 2807 | XVECTOR (tem)->contents[i] |
| 2808 | = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE), Qnil); |
| 2809 | save_window_save (FRAME_ROOT_WINDOW (f), |
| 2810 | XVECTOR (tem), 0); |
| 2811 | XSET (tem, Lisp_Window_Configuration, data); |
| 2812 | return (tem); |
| 2813 | } |
| 2814 | |
| 2815 | DEFUN ("save-window-excursion", Fsave_window_excursion, Ssave_window_excursion, |
| 2816 | 0, UNEVALLED, 0, |
| 2817 | "Execute body, preserving window sizes and contents.\n\ |
| 2818 | Restores which buffer appears in which window, where display starts,\n\ |
| 2819 | as well as the current buffer.\n\ |
| 2820 | Does not restore the value of point in current buffer.") |
| 2821 | (args) |
| 2822 | Lisp_Object args; |
| 2823 | { |
| 2824 | register Lisp_Object val; |
| 2825 | register int count = specpdl_ptr - specpdl; |
| 2826 | |
| 2827 | record_unwind_protect (Fset_window_configuration, |
| 2828 | Fcurrent_window_configuration (Qnil)); |
| 2829 | val = Fprogn (args); |
| 2830 | return unbind_to (count, val); |
| 2831 | } |
| 2832 | \f |
| 2833 | init_window_once () |
| 2834 | { |
| 2835 | #ifdef MULTI_FRAME |
| 2836 | selected_frame = make_terminal_frame (); |
| 2837 | minibuf_window = selected_frame->minibuffer_window; |
| 2838 | selected_window = selected_frame->selected_window; |
| 2839 | last_nonminibuf_frame = selected_frame; |
| 2840 | #else /* not MULTI_FRAME */ |
| 2841 | extern Lisp_Object get_minibuffer (); |
| 2842 | |
| 2843 | minibuf_window = make_window (); |
| 2844 | FRAME_ROOT_WINDOW (selected_frame) = make_window (); |
| 2845 | |
| 2846 | XWINDOW (FRAME_ROOT_WINDOW (selected_frame))->next = minibuf_window; |
| 2847 | XWINDOW (minibuf_window)->prev = FRAME_ROOT_WINDOW (selected_frame); |
| 2848 | XWINDOW (minibuf_window)->mini_p = Qt; |
| 2849 | |
| 2850 | /* These values 9 and 10 are arbitrary, |
| 2851 | just so that there is "something there." |
| 2852 | Correct values are put in in init_xdisp */ |
| 2853 | |
| 2854 | XFASTINT (XWINDOW (FRAME_ROOT_WINDOW (selected_frame))->width) = 10; |
| 2855 | XFASTINT (XWINDOW (minibuf_window)->width) = 10; |
| 2856 | |
| 2857 | XFASTINT (XWINDOW (FRAME_ROOT_WINDOW (selected_frame))->height) = 9; |
| 2858 | XFASTINT (XWINDOW (minibuf_window)->top) = 9; |
| 2859 | XFASTINT (XWINDOW (minibuf_window)->height) = 1; |
| 2860 | |
| 2861 | /* Prevent error in Fset_window_buffer. */ |
| 2862 | XWINDOW (FRAME_ROOT_WINDOW (selected_frame))->buffer = Qt; |
| 2863 | XWINDOW (minibuf_window)->buffer = Qt; |
| 2864 | |
| 2865 | /* Now set them up for real. */ |
| 2866 | Fset_window_buffer (FRAME_ROOT_WINDOW (selected_frame), |
| 2867 | Fcurrent_buffer ()); |
| 2868 | Fset_window_buffer (minibuf_window, get_minibuffer (0)); |
| 2869 | |
| 2870 | selected_window = FRAME_ROOT_WINDOW (selected_frame); |
| 2871 | /* Make sure this window seems more recently used than |
| 2872 | a newly-created, never-selected window. Increment |
| 2873 | window_select_count so the first selection ever will get |
| 2874 | something newer than this. */ |
| 2875 | XFASTINT (XWINDOW (selected_window)->use_time) = ++window_select_count; |
| 2876 | #endif /* not MULTI_FRAME */ |
| 2877 | } |
| 2878 | |
| 2879 | syms_of_window () |
| 2880 | { |
| 2881 | Qwindowp = intern ("windowp"); |
| 2882 | staticpro (&Qwindowp); |
| 2883 | |
| 2884 | Qwindow_live_p = intern ("window-live-p"); |
| 2885 | staticpro (&Qwindow_live_p); |
| 2886 | |
| 2887 | #ifndef MULTI_FRAME |
| 2888 | /* Make sure all windows get marked */ |
| 2889 | staticpro (&minibuf_window); |
| 2890 | #endif |
| 2891 | |
| 2892 | DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function, |
| 2893 | "Non-nil means call as function to display a help buffer.\n\ |
| 2894 | Used by `with-output-to-temp-buffer'."); |
| 2895 | Vtemp_buffer_show_function = Qnil; |
| 2896 | |
| 2897 | DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function, |
| 2898 | "If non-nil, function to call to handle `display-buffer'.\n\ |
| 2899 | It will receive two args, the buffer and a flag which if non-nil means\n\ |
| 2900 | that the currently selected window is not acceptable.\n\ |
| 2901 | Commands such as `switch-to-buffer-other-window' and `find-file-other-window'\n\ |
| 2902 | work using this function."); |
| 2903 | Vdisplay_buffer_function = Qnil; |
| 2904 | |
| 2905 | DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window, |
| 2906 | "Non-nil means it is the window that C-M-v in minibuffer should scroll."); |
| 2907 | Vminibuf_scroll_window = Qnil; |
| 2908 | |
| 2909 | DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer, |
| 2910 | "If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window."); |
| 2911 | Vother_window_scroll_buffer = Qnil; |
| 2912 | |
| 2913 | DEFVAR_BOOL ("pop-up-frames", &pop_up_frames, |
| 2914 | "*Non-nil means `display-buffer' should make a separate frame."); |
| 2915 | pop_up_frames = 0; |
| 2916 | |
| 2917 | DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function, |
| 2918 | "*If non-nil, function to call to handle automatic new frame creation.\n\ |
| 2919 | It is called with no arguments and should return a newly created frame.\n\ |
| 2920 | \n\ |
| 2921 | A typical value might be `(lambda () (new-frame pop-up-frame-alist))'\n\ |
| 2922 | where `pop-up-frame-alist' would hold the default frame parameters."); |
| 2923 | Vpop_up_frame_function = Qnil; |
| 2924 | |
| 2925 | DEFVAR_BOOL ("pop-up-windows", &pop_up_windows, |
| 2926 | "*Non-nil means display-buffer should make new windows."); |
| 2927 | pop_up_windows = 1; |
| 2928 | |
| 2929 | DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines, |
| 2930 | "*Number of lines of continuity when scrolling by screenfuls."); |
| 2931 | next_screen_context_lines = 2; |
| 2932 | |
| 2933 | DEFVAR_INT ("split-height-threshold", &split_height_threshold, |
| 2934 | "*display-buffer would prefer to split the largest window if this large.\n\ |
| 2935 | If there is only one window, it is split regardless of this value."); |
| 2936 | split_height_threshold = 500; |
| 2937 | |
| 2938 | DEFVAR_INT ("window-min-height", &window_min_height, |
| 2939 | "*Delete any window less than this tall (including its mode line)."); |
| 2940 | window_min_height = 4; |
| 2941 | |
| 2942 | DEFVAR_INT ("window-min-width", &window_min_width, |
| 2943 | "*Delete any window less than this wide."); |
| 2944 | window_min_width = 10; |
| 2945 | |
| 2946 | defsubr (&Sselected_window); |
| 2947 | defsubr (&Sminibuffer_window); |
| 2948 | defsubr (&Swindow_minibuffer_p); |
| 2949 | defsubr (&Swindowp); |
| 2950 | defsubr (&Swindow_live_p); |
| 2951 | defsubr (&Spos_visible_in_window_p); |
| 2952 | defsubr (&Swindow_buffer); |
| 2953 | defsubr (&Swindow_height); |
| 2954 | defsubr (&Swindow_width); |
| 2955 | defsubr (&Swindow_hscroll); |
| 2956 | defsubr (&Sset_window_hscroll); |
| 2957 | defsubr (&Swindow_edges); |
| 2958 | defsubr (&Scoordinates_in_window_p); |
| 2959 | defsubr (&Swindow_at); |
| 2960 | defsubr (&Swindow_point); |
| 2961 | defsubr (&Swindow_start); |
| 2962 | defsubr (&Swindow_end); |
| 2963 | defsubr (&Sset_window_point); |
| 2964 | defsubr (&Sset_window_start); |
| 2965 | defsubr (&Swindow_dedicated_p); |
| 2966 | defsubr (&Sset_window_dedicated_p); |
| 2967 | defsubr (&Swindow_display_table); |
| 2968 | defsubr (&Sset_window_display_table); |
| 2969 | defsubr (&Snext_window); |
| 2970 | defsubr (&Sprevious_window); |
| 2971 | defsubr (&Sother_window); |
| 2972 | defsubr (&Sget_lru_window); |
| 2973 | defsubr (&Sget_largest_window); |
| 2974 | defsubr (&Sget_buffer_window); |
| 2975 | defsubr (&Sdelete_other_windows); |
| 2976 | defsubr (&Sdelete_windows_on); |
| 2977 | defsubr (&Sreplace_buffer_in_windows); |
| 2978 | defsubr (&Sdelete_window); |
| 2979 | defsubr (&Sset_window_buffer); |
| 2980 | defsubr (&Sselect_window); |
| 2981 | defsubr (&Sdisplay_buffer); |
| 2982 | defsubr (&Ssplit_window); |
| 2983 | defsubr (&Senlarge_window); |
| 2984 | defsubr (&Sshrink_window); |
| 2985 | defsubr (&Sscroll_up); |
| 2986 | defsubr (&Sscroll_down); |
| 2987 | defsubr (&Sscroll_left); |
| 2988 | defsubr (&Sscroll_right); |
| 2989 | defsubr (&Sscroll_other_window); |
| 2990 | defsubr (&Srecenter); |
| 2991 | defsubr (&Smove_to_window_line); |
| 2992 | defsubr (&Swindow_configuration_p); |
| 2993 | defsubr (&Sset_window_configuration); |
| 2994 | defsubr (&Scurrent_window_configuration); |
| 2995 | defsubr (&Ssave_window_excursion); |
| 2996 | } |
| 2997 | |
| 2998 | keys_of_window () |
| 2999 | { |
| 3000 | initial_define_key (control_x_map, '1', "delete-other-windows"); |
| 3001 | initial_define_key (control_x_map, '2', "split-window"); |
| 3002 | initial_define_key (control_x_map, '0', "delete-window"); |
| 3003 | initial_define_key (control_x_map, 'o', "other-window"); |
| 3004 | initial_define_key (control_x_map, '^', "enlarge-window"); |
| 3005 | initial_define_key (control_x_map, '<', "scroll-left"); |
| 3006 | initial_define_key (control_x_map, '>', "scroll-right"); |
| 3007 | |
| 3008 | initial_define_key (global_map, Ctl ('V'), "scroll-up"); |
| 3009 | initial_define_key (meta_map, Ctl ('V'), "scroll-other-window"); |
| 3010 | initial_define_key (meta_map, 'v', "scroll-down"); |
| 3011 | |
| 3012 | initial_define_key (global_map, Ctl('L'), "recenter"); |
| 3013 | initial_define_key (meta_map, 'r', "move-to-window-line"); |
| 3014 | } |