0
|
1 /* Window creation, deletion and examination for XEmacs.
|
|
2 Copyright (C) 1985-1987, 1992-1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
|
|
4 Copyright (C) 1995, 1996 Ben Wing.
|
|
5 Copyright (C) 1996 Chuck Thompson.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: FSF 19.30. */
|
|
25 /* Beginning to diverge significantly. */
|
|
26
|
|
27 /* This file has been Mule-ized. */
|
|
28
|
|
29 #include <config.h>
|
|
30 #include "lisp.h"
|
|
31
|
|
32 #include "buffer.h"
|
|
33 #include "faces.h"
|
|
34 #include "frame.h"
|
|
35 #include "objects.h"
|
|
36 #include "glyphs.h"
|
|
37 #include "redisplay.h"
|
|
38 #include "window.h"
|
|
39 #include "commands.h"
|
|
40
|
|
41 Lisp_Object Qwindowp, Qwindow_live_p;
|
|
42 Lisp_Object Qwindow_configurationp;
|
|
43 Lisp_Object Qscroll_up;
|
|
44 Lisp_Object Qscroll_down;
|
|
45 Lisp_Object Qdisplay_buffer;
|
|
46
|
|
47 #ifdef MEMORY_USAGE_STATS
|
|
48 Lisp_Object Qface_cache;
|
|
49 Lisp_Object Qglyph_cache;
|
|
50 Lisp_Object Qline_start_cache;
|
|
51 #ifdef HAVE_SCROLLBARS
|
|
52 Lisp_Object Qscrollbar_instances;
|
|
53 #endif
|
|
54 Lisp_Object Qother_redisplay;
|
|
55 #endif
|
|
56
|
|
57 static int window_pixel_width_to_char_width (struct window *w,
|
|
58 int pixel_width,
|
|
59 int include_margins_p);
|
|
60 static int window_char_width_to_pixel_width (struct window *w,
|
|
61 int char_width,
|
|
62 int include_margins_p);
|
|
63 static int window_pixel_height_to_char_height (struct window *w,
|
|
64 int pixel_height,
|
|
65 int include_gutters_p);
|
|
66 static int window_char_height_to_pixel_height (struct window *w,
|
|
67 int char_height,
|
|
68 int include_gutters_p);
|
|
69 static void change_window_height (struct window *w, int delta, int widthflag);
|
|
70
|
|
71
|
|
72 /* Thickness of shadow border around 3d modelines. */
|
|
73 Lisp_Object Vmodeline_shadow_thickness;
|
|
74
|
|
75 /* Whether a modeline should be displayed. */
|
|
76 Lisp_Object Vhas_modeline_p;
|
|
77
|
|
78 /* Scroll if point lands on the bottom line and that line is partially
|
|
79 clipped. */
|
|
80 int scroll_on_clipped_lines;
|
|
81
|
|
82 /* The minibuffer window of the selected frame.
|
|
83 Note that you cannot test for minibufferness of an arbitrary window
|
|
84 by comparing against this; but you can test for minibufferness of
|
|
85 the selected window. */
|
|
86 Lisp_Object minibuf_window;
|
|
87
|
|
88 /* Non-nil means it is the window for C-M-v to scroll
|
|
89 when the minibuffer is selected. */
|
|
90 Lisp_Object Vminibuf_scroll_window;
|
|
91
|
|
92 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
|
|
93 Lisp_Object Vother_window_scroll_buffer;
|
|
94
|
102
|
95 /* Non-nil means it's the function to call to display temp buffers. */
|
0
|
96 Lisp_Object Vtemp_buffer_show_function;
|
|
97
|
|
98 Lisp_Object Vtemp_buffer_show_hook;
|
|
99
|
|
100 /* If a window gets smaller than either of these, it is removed. */
|
|
101 int window_min_height;
|
|
102 int window_min_width;
|
|
103
|
|
104 /* Hook run at end of temp_output_buffer_show. */
|
|
105 Lisp_Object Qtemp_buffer_show_hook;
|
|
106
|
|
107 /* Number of lines of continuity in scrolling by screenfuls. */
|
|
108 int next_screen_context_lines;
|
|
109
|
|
110 /* List of freed window configurations with 1 - 10 windows. */
|
|
111 Lisp_Object Vwindow_configuration_free_list[10];
|
|
112
|
|
113 #define SET_LAST_MODIFIED(w, cache_too) \
|
|
114 do { \
|
|
115 (w)->last_modified[CURRENT_DISP] = Qzero; \
|
|
116 (w)->last_modified[DESIRED_DISP] = Qzero; \
|
|
117 (w)->last_modified[CMOTION_DISP] = Qzero; \
|
|
118 if (cache_too) \
|
|
119 (w)->line_cache_last_updated = Qzero; \
|
|
120 } while (0)
|
|
121
|
|
122 #define SET_LAST_FACECHANGE(w) \
|
|
123 do { \
|
|
124 (w)->last_facechange[CURRENT_DISP] = Qzero; \
|
|
125 (w)->last_facechange[DESIRED_DISP] = Qzero; \
|
|
126 (w)->last_facechange[CMOTION_DISP] = Qzero; \
|
|
127 } while (0)
|
|
128
|
|
129
|
|
130 static Lisp_Object mark_window (Lisp_Object, void (*) (Lisp_Object));
|
|
131 static void print_window (Lisp_Object, Lisp_Object, int);
|
|
132 static void finalize_window (void *header, int for_disksave);
|
|
133 DEFINE_LRECORD_IMPLEMENTATION ("window", window,
|
|
134 mark_window, print_window, finalize_window,
|
|
135 0, 0, struct window);
|
|
136
|
102
|
137 #define MARK_DISP_VARIABLE(field) \
|
|
138 ((markobj) (window->field[CURRENT_DISP])); \
|
|
139 ((markobj) (window->field[DESIRED_DISP])); \
|
0
|
140 ((markobj) (window->field[CMOTION_DISP]));
|
|
141
|
|
142 static Lisp_Object
|
|
143 mark_window (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
144 {
|
|
145 struct window *window = XWINDOW (obj);
|
|
146 ((markobj) (window->frame));
|
|
147 ((markobj) (window->mini_p));
|
|
148 ((markobj) (window->next));
|
|
149 ((markobj) (window->prev));
|
|
150 ((markobj) (window->hchild));
|
|
151 ((markobj) (window->vchild));
|
|
152 ((markobj) (window->parent));
|
|
153 ((markobj) (window->buffer));
|
|
154 MARK_DISP_VARIABLE (start);
|
|
155 MARK_DISP_VARIABLE (pointm);
|
|
156 ((markobj) (window->sb_point)); /* #### move to scrollbar.c? */
|
|
157 ((markobj) (window->use_time));
|
|
158 MARK_DISP_VARIABLE (last_modified);
|
|
159 MARK_DISP_VARIABLE (last_point);
|
|
160 MARK_DISP_VARIABLE (last_start);
|
|
161 MARK_DISP_VARIABLE (last_facechange);
|
|
162 ((markobj) (window->line_cache_last_updated));
|
|
163 ((markobj) (window->redisplay_end_trigger));
|
|
164 /* Cached specifiers: */
|
|
165 ((markobj) (window->display_table));
|
|
166 ((markobj) (window->has_modeline_p));
|
|
167 ((markobj) (window->modeline_shadow_thickness));
|
|
168 #ifdef HAVE_SCROLLBARS
|
|
169 ((markobj) (window->scrollbar_width));
|
|
170 ((markobj) (window->scrollbar_height));
|
|
171 ((markobj) (window->scrollbar_pointer));
|
102
|
172 #endif /* HAVE_SCROLLBARS */
|
0
|
173 ((markobj) (window->left_margin_width));
|
|
174 ((markobj) (window->right_margin_width));
|
|
175 #ifdef HAVE_TOOLBARS
|
|
176 ((markobj) (window->toolbar[0]));
|
|
177 ((markobj) (window->toolbar[1]));
|
|
178 ((markobj) (window->toolbar[2]));
|
|
179 ((markobj) (window->toolbar[3]));
|
|
180 ((markobj) (window->toolbar_size[0]));
|
|
181 ((markobj) (window->toolbar_size[1]));
|
|
182 ((markobj) (window->toolbar_size[2]));
|
|
183 ((markobj) (window->toolbar_size[3]));
|
|
184 ((markobj) (window->toolbar_visible_p[0]));
|
|
185 ((markobj) (window->toolbar_visible_p[1]));
|
|
186 ((markobj) (window->toolbar_visible_p[2]));
|
|
187 ((markobj) (window->toolbar_visible_p[3]));
|
|
188 ((markobj) (window->toolbar_buttons_captioned_p));
|
|
189 ((markobj) (window->default_toolbar));
|
|
190 ((markobj) (window->default_toolbar_height));
|
|
191 ((markobj) (window->default_toolbar_width));
|
|
192 ((markobj) (window->default_toolbar_visible_p));
|
102
|
193 #endif /* HAVE_TOOLBARS */
|
0
|
194 ((markobj) (window->minimum_line_ascent));
|
|
195 ((markobj) (window->minimum_line_descent));
|
|
196 ((markobj) (window->use_left_overflow));
|
|
197 ((markobj) (window->use_right_overflow));
|
|
198 #ifdef HAVE_MENUBARS
|
|
199 ((markobj) (window->menubar_visible_p));
|
102
|
200 #endif /* HAVE_MENUBARS */
|
0
|
201 ((markobj) (window->text_cursor_visible_p));
|
|
202 /* End cached specifiers. */
|
|
203 ((markobj) (window->dedicated));
|
|
204 mark_face_cachels (window->face_cachels, markobj);
|
|
205 mark_glyph_cachels (window->glyph_cachels, markobj);
|
173
|
206 return Qnil;
|
0
|
207 }
|
|
208
|
|
209 static void
|
|
210 print_window (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
211 {
|
|
212 char buf[200];
|
|
213
|
|
214 if (print_readably)
|
|
215 error ("printing unreadable object #<window 0x%x>",
|
|
216 XWINDOW (obj)->header.uid);
|
185
|
217
|
0
|
218 write_c_string ("#<window", printcharfun);
|
|
219 if (!NILP (XWINDOW (obj)->buffer))
|
|
220 {
|
|
221 Lisp_Object name = XBUFFER (XWINDOW (obj)->buffer)->name;
|
|
222 write_c_string (" on ", printcharfun);
|
|
223 print_internal (name, printcharfun, 1);
|
|
224 }
|
|
225 sprintf (buf, " 0x%x>", XWINDOW (obj)->header.uid);
|
|
226 write_c_string (buf, printcharfun);
|
|
227 }
|
|
228
|
|
229 static void
|
|
230 finalize_window (void *header, int for_disksave)
|
|
231 {
|
|
232 struct window *w = (struct window *) header;
|
|
233
|
|
234 if (w->line_start_cache)
|
|
235 {
|
|
236 Dynarr_free (w->line_start_cache);
|
|
237 w->line_start_cache = 0;
|
|
238 }
|
|
239
|
|
240 if (w->face_cachels)
|
|
241 {
|
|
242 int i;
|
|
243
|
|
244 for (i = 0; i < Dynarr_length (w->face_cachels); i++)
|
|
245 {
|
|
246 struct face_cachel *cachel = Dynarr_atp (w->face_cachels, i);
|
|
247 if (cachel->merged_faces)
|
|
248 {
|
|
249 Dynarr_free (cachel->merged_faces);
|
|
250 cachel->merged_faces = 0;
|
|
251 }
|
|
252 }
|
|
253 Dynarr_free (w->face_cachels);
|
|
254 w->face_cachels = 0;
|
|
255 }
|
|
256
|
|
257 if (w->glyph_cachels)
|
|
258 {
|
|
259 Dynarr_free (w->glyph_cachels);
|
|
260 w->glyph_cachels = 0;
|
|
261 }
|
|
262 }
|
|
263
|
|
264 #define INIT_DISP_VARIABLE(field, initialization) \
|
|
265 p->field[CURRENT_DISP] = initialization; \
|
|
266 p->field[DESIRED_DISP] = initialization; \
|
|
267 p->field[CMOTION_DISP] = initialization;
|
|
268
|
|
269 /* We have an implicit assertion that the first two elements (default
|
|
270 and modeline faces) are always present in the face_element_cache.
|
|
271 Normally redisplay ensures this. However, it is possible for a
|
|
272 window to get created and functions which reference these values
|
|
273 called before redisplay works with the window for the first time.
|
|
274 All callers of allocate_window should therefore call
|
|
275 reset_face_cachels on the created window. We can't do it
|
|
276 here because the window must have its frame pointer set or
|
|
277 reset_face_cachels will fail. */
|
|
278 Lisp_Object
|
|
279 allocate_window (void)
|
|
280 {
|
|
281 Lisp_Object val = Qnil;
|
185
|
282 struct window *p = alloc_lcrecord_type (struct window, lrecord_window);
|
0
|
283
|
|
284 zero_lcrecord (p);
|
|
285 XSETWINDOW (val, p);
|
|
286
|
|
287 p->dead = 0;
|
|
288 p->frame = Qnil;
|
|
289 p->mini_p = Qnil;
|
|
290 p->next = Qnil;
|
|
291 p->prev = Qnil;
|
185
|
292 p->hchild = Qnil;
|
|
293 p->vchild = Qnil;
|
0
|
294 p->parent = Qnil;
|
|
295 p->buffer = Qnil;
|
|
296 INIT_DISP_VARIABLE (start, Fmake_marker ());
|
|
297 INIT_DISP_VARIABLE (pointm, Fmake_marker ());
|
|
298 p->sb_point = Fmake_marker ();
|
|
299 p->use_time = Qzero;
|
|
300 INIT_DISP_VARIABLE (last_modified, Qzero);
|
|
301 INIT_DISP_VARIABLE (last_point, Fmake_marker ());
|
|
302 INIT_DISP_VARIABLE (last_start, Fmake_marker ());
|
|
303 INIT_DISP_VARIABLE (last_facechange, Qzero);
|
185
|
304 p->face_cachels = Dynarr_new (face_cachel);
|
|
305 p->glyph_cachels = Dynarr_new (glyph_cachel);
|
|
306 p->line_start_cache = Dynarr_new (line_start_cache);
|
0
|
307 p->line_cache_last_updated = Qzero;
|
|
308 INIT_DISP_VARIABLE (last_point_x, 0);
|
|
309 INIT_DISP_VARIABLE (last_point_y, 0);
|
|
310 INIT_DISP_VARIABLE (window_end_pos, 0);
|
|
311 p->redisplay_end_trigger = Qnil;
|
|
312 /* cached specifier values: will get set properly later */
|
|
313 p->display_table = Qnil;
|
|
314 p->has_modeline_p = Qnil;
|
|
315 p->modeline_shadow_thickness = Qnil;
|
|
316 #ifdef HAVE_SCROLLBARS
|
|
317 p->scrollbar_width = Qnil;
|
|
318 p->scrollbar_height = Qnil;
|
|
319 #endif
|
|
320 p->left_margin_width = Qnil;
|
|
321 p->right_margin_width = Qnil;
|
|
322 #ifdef HAVE_TOOLBARS
|
|
323 p->toolbar_size[0] = Qnil;
|
|
324 p->toolbar_size[1] = Qnil;
|
|
325 p->toolbar_size[2] = Qnil;
|
|
326 p->toolbar_size[3] = Qnil;
|
|
327 #endif
|
|
328 p->minimum_line_ascent = Qnil;
|
|
329 p->minimum_line_descent = Qnil;
|
|
330 p->use_left_overflow = Qnil;
|
|
331 p->use_right_overflow = Qnil;
|
|
332 #ifdef HAVE_MENUBARS
|
|
333 p->menubar_visible_p = Qnil;
|
|
334 #endif
|
|
335 #ifdef HAVE_TOOLBARS
|
|
336 p->toolbar_buttons_captioned_p = Qnil;
|
|
337 #endif
|
|
338 p->text_cursor_visible_p = Qnil;
|
|
339 /* end cached specifier values. */
|
|
340
|
|
341 p->dedicated = Qnil;
|
|
342 p->windows_changed = 1;
|
|
343 p->shadow_thickness_changed = 1;
|
|
344
|
173
|
345 return val;
|
0
|
346 }
|
|
347 #undef INIT_DISP_VARIABLE
|
|
348
|
|
349 /*
|
|
350 * The redisplay structures used to be stored with each window. While
|
|
351 * they are logically something associated with frames they can't be
|
|
352 * stored there with a redisplay which handles variable height lines.
|
|
353 * Lines in horizontally split windows might not line up. So they get
|
|
354 * stored with the windows.
|
|
355 *
|
|
356 * The problem with this is window configurations. When restoring a
|
|
357 * window configuration it now becomes problematic to do an
|
|
358 * incremental redisplay. The solution is to store the redisplay
|
|
359 * structures with the frame as they should be but laid out in the
|
|
360 * same manner as the window structure. Thus is born the window
|
|
361 * mirror.
|
|
362 *
|
|
363 * It also becomes a convenient place to stick scrollbar instances
|
|
364 * since they extrapolate out to having the same problem described for
|
|
365 * the display structures.
|
|
366 */
|
|
367
|
102
|
368 /* Create a new window mirror structure and associated redisplay
|
0
|
369 structs. */
|
|
370 static struct window_mirror *
|
|
371 new_window_mirror (struct frame *f)
|
|
372 {
|
185
|
373 struct window_mirror *t = xnew_and_zero (struct window_mirror);
|
0
|
374
|
|
375 t->frame = f;
|
|
376
|
185
|
377 t->current_display_lines = Dynarr_new (display_line);
|
|
378 t->desired_display_lines = Dynarr_new (display_line);
|
0
|
379 t->buffer = NULL;
|
|
380
|
|
381 #ifdef HAVE_SCROLLBARS
|
|
382 t->scrollbar_vertical_instance = NULL;
|
|
383 t->scrollbar_horizontal_instance = NULL;
|
|
384 #endif
|
|
385
|
|
386 return t;
|
|
387 }
|
|
388
|
|
389 /* Synchronize the mirror structure with a given window structure.
|
|
390 This is normally called from update_frame_window_mirror with a
|
|
391 starting window of f->root_window. */
|
|
392 static struct window_mirror *
|
|
393 update_mirror_internal (Lisp_Object win, struct window_mirror *mir)
|
|
394 {
|
|
395 if (NILP (win))
|
|
396 {
|
|
397 if (mir)
|
|
398 {
|
|
399 free_window_mirror (mir);
|
|
400 mir = 0;
|
|
401 }
|
|
402 return mir;
|
|
403 }
|
|
404 else
|
|
405 if (!mir)
|
|
406 mir = new_window_mirror (XFRAME (XWINDOW (win)->frame));
|
|
407
|
102
|
408 mir->next = update_mirror_internal (XWINDOW (win)->next, mir->next);
|
0
|
409 mir->hchild = update_mirror_internal (XWINDOW (win)->hchild, mir->hchild);
|
|
410 mir->vchild = update_mirror_internal (XWINDOW (win)->vchild, mir->vchild);
|
|
411
|
|
412 /*
|
|
413 * If the redisplay structs are not empty and the mirror has
|
|
414 * children, then this mirror structure was formerly being used for
|
|
415 * display but is no longer. Reset its current display structs so
|
|
416 * that redisplay doesn't accidentally think they are accurate if it
|
|
417 * is later used for display purposes once again. Also, mark the
|
|
418 * scrollbar instance as not active.
|
|
419 */
|
|
420 if (mir->vchild || mir->hchild)
|
|
421 {
|
|
422 /* The redisplay structures are big. Leaving them around in
|
|
423 non-leaf windows can add up to a lot of wasted space. So
|
|
424 don't do it. */
|
|
425 free_display_structs (mir);
|
185
|
426 mir->current_display_lines = Dynarr_new (display_line);
|
|
427 mir->desired_display_lines = Dynarr_new (display_line);
|
0
|
428
|
|
429 #ifdef HAVE_SCROLLBARS
|
|
430 update_window_scrollbars (XWINDOW (win), mir, 0, 0);
|
|
431 #endif
|
|
432 mir->buffer = NULL;
|
|
433 }
|
|
434
|
|
435 return mir;
|
|
436 }
|
|
437
|
|
438 /* Given a window mirror, determine which real window it contains the
|
|
439 redisplay structures for. */
|
|
440 static Lisp_Object
|
|
441 real_window_internal (Lisp_Object win, struct window_mirror *rmir,
|
|
442 struct window_mirror *mir)
|
|
443 {
|
|
444 Lisp_Object retval;
|
|
445
|
|
446 for (; !NILP (win) && rmir ; win = XWINDOW (win)->next, rmir = rmir->next)
|
|
447 {
|
|
448 if (mir == rmir)
|
|
449 return win;
|
|
450 if (!NILP (XWINDOW (win)->vchild))
|
|
451 {
|
|
452 retval = real_window_internal (XWINDOW (win)->vchild, rmir->vchild,
|
|
453 mir);
|
|
454 if (!NILP (retval))
|
|
455 return retval;
|
|
456 }
|
|
457 if (!NILP (XWINDOW (win)->hchild))
|
|
458 {
|
|
459 retval = real_window_internal (XWINDOW (win)->hchild, rmir->hchild,
|
|
460 mir);
|
|
461 if (!NILP (retval))
|
|
462 return retval;
|
|
463 }
|
|
464 }
|
|
465
|
|
466 return Qnil;
|
|
467 }
|
|
468
|
|
469 /* Given a real window, find the mirror structure which contains its
|
|
470 redisplay structures. */
|
|
471 static struct window_mirror *
|
|
472 find_window_mirror_internal (Lisp_Object win, struct window_mirror *rmir,
|
|
473 struct window *w)
|
|
474 {
|
|
475 struct window_mirror *retval;
|
|
476
|
|
477 for (; !NILP (win); win = XWINDOW (win)->next, rmir = rmir->next)
|
|
478 {
|
|
479 if (w == XWINDOW (win))
|
|
480 return rmir;
|
|
481 if (!NILP (XWINDOW (win)->vchild) &&
|
|
482 (retval = find_window_mirror_internal (XWINDOW (win)->vchild,
|
|
483 rmir->vchild, w)))
|
|
484 return retval;
|
|
485 if (!NILP (XWINDOW (win)->hchild) &&
|
|
486 (retval = find_window_mirror_internal (XWINDOW (win)->hchild,
|
|
487 rmir->hchild, w)))
|
|
488 return retval;
|
|
489 }
|
|
490
|
|
491 return 0;
|
|
492 }
|
|
493
|
|
494 /* Update the mirror structure for the given frame. */
|
|
495 void
|
|
496 update_frame_window_mirror (struct frame *f)
|
|
497 {
|
|
498 f->root_mirror = update_mirror_internal (f->root_window, f->root_mirror);
|
|
499 f->mirror_dirty = 0;
|
|
500 }
|
|
501
|
|
502 /* Free a given mirror structure along with all of its children as
|
|
503 well as their associated display structures. */
|
|
504 void
|
|
505 free_window_mirror (struct window_mirror *mir)
|
|
506 {
|
|
507 struct window_mirror *p;
|
|
508
|
|
509 p = mir;
|
|
510 while (mir)
|
|
511 {
|
|
512 if (mir->hchild) free_window_mirror (mir->hchild);
|
|
513 if (mir->vchild) free_window_mirror (mir->vchild);
|
|
514 #ifdef HAVE_SCROLLBARS
|
|
515 release_window_mirror_scrollbars (mir);
|
|
516 #endif
|
|
517 free_display_structs (mir);
|
|
518 mir = mir->next;
|
|
519 xfree (p);
|
|
520 p = mir;
|
|
521 }
|
|
522 }
|
|
523
|
|
524 /* Given a mirror structure, return the window it mirrors. Calls
|
|
525 real_window_internal to do most of the work. */
|
|
526 Lisp_Object
|
|
527 real_window (struct window_mirror *mir, int no_abort)
|
|
528 {
|
|
529 Lisp_Object retval;
|
|
530
|
|
531 retval = real_window_internal (mir->frame->root_window,
|
|
532 mir->frame->root_mirror, mir);
|
|
533
|
|
534 if (NILP (retval) && !no_abort)
|
|
535 abort ();
|
|
536
|
|
537 return retval;
|
|
538 }
|
|
539
|
|
540 /* Given a real window, return its mirror structure. Calls
|
|
541 find_window_mirror_internal to do all of the work. */
|
|
542 struct window_mirror *
|
|
543 find_window_mirror (struct window *w)
|
|
544 {
|
|
545 struct frame *f = XFRAME (w->frame);
|
|
546 if (f->mirror_dirty)
|
|
547 update_frame_window_mirror (f);
|
|
548 return find_window_mirror_internal (f->root_window, f->root_mirror, w);
|
|
549 }
|
|
550
|
|
551 /*****************************************************************************
|
|
552 find_window_by_pixel_pos
|
|
553
|
|
554 Given a pixel position relative to a frame, find the window at that
|
|
555 position.
|
|
556 ****************************************************************************/
|
|
557 struct window *
|
|
558 find_window_by_pixel_pos (unsigned int pix_x, unsigned int pix_y,
|
|
559 Lisp_Object win)
|
|
560 {
|
|
561 struct window *w;
|
|
562
|
|
563 if (NILP (win))
|
|
564 return 0;
|
|
565
|
|
566 for (; !NILP (win); win = XWINDOW (win)->next)
|
|
567 {
|
|
568 if (!NILP (XWINDOW (win)->vchild) &&
|
|
569 (w = find_window_by_pixel_pos (pix_x, pix_y, XWINDOW (win)->vchild)))
|
|
570 return w;
|
|
571 if (!NILP (XWINDOW (win)->hchild) &&
|
|
572 (w = find_window_by_pixel_pos (pix_x, pix_y, XWINDOW (win)->hchild)))
|
|
573 return w;
|
|
574 w = XWINDOW (win);
|
|
575 if (pix_x >= WINDOW_LEFT (w)
|
|
576 && pix_x <= WINDOW_RIGHT (w)
|
|
577 && pix_y >= WINDOW_TOP (w)
|
|
578 && pix_y <= WINDOW_BOTTOM (w))
|
|
579 return w;
|
|
580 }
|
|
581 return 0;
|
|
582 }
|
|
583
|
|
584 /* Return a pointer to the display structures for the given window. */
|
|
585 display_line_dynarr *
|
|
586 window_display_lines (struct window *w, int which)
|
|
587 {
|
|
588 struct window_mirror *t;
|
|
589
|
|
590 if (XFRAME (w->frame)->mirror_dirty)
|
|
591 update_frame_window_mirror (XFRAME (w->frame));
|
|
592 t = find_window_mirror (w);
|
|
593 if (!t)
|
|
594 abort ();
|
|
595
|
|
596 if (which == CURRENT_DISP)
|
|
597 return t->current_display_lines;
|
|
598 else if (which == DESIRED_DISP)
|
|
599 return t->desired_display_lines;
|
|
600 else if (which == CMOTION_DISP)
|
|
601 /* The CMOTION_DISP display lines are global. */
|
|
602 return cmotion_display_lines;
|
|
603 else
|
|
604 abort ();
|
|
605
|
|
606 return 0; /* shut up compiler */
|
|
607 }
|
|
608
|
|
609 struct buffer *
|
|
610 window_display_buffer (struct window *w)
|
|
611 {
|
|
612 struct window_mirror *t;
|
|
613
|
|
614 if (XFRAME (w->frame)->mirror_dirty)
|
|
615 update_frame_window_mirror (XFRAME (w->frame));
|
|
616 t = find_window_mirror (w);
|
|
617 if (!t)
|
|
618 abort ();
|
|
619
|
|
620 return t->buffer;
|
|
621 }
|
|
622
|
|
623 void
|
|
624 set_window_display_buffer (struct window *w, struct buffer *b)
|
|
625 {
|
|
626 struct window_mirror *t;
|
|
627
|
|
628 if (XFRAME (w->frame)->mirror_dirty)
|
|
629 update_frame_window_mirror (XFRAME (w->frame));
|
|
630 t = find_window_mirror (w);
|
|
631 if (!t)
|
|
632 abort ();
|
|
633
|
|
634 t->buffer = b;
|
|
635 }
|
|
636
|
|
637
|
102
|
638 /* Determining a window's position based solely on its pixel
|
0
|
639 positioning doesn't work. Instead, we do it the intelligent way,
|
|
640 by checking its positioning in the window hierarchy. */
|
|
641 int
|
|
642 window_is_leftmost (struct window *w)
|
|
643 {
|
|
644 Lisp_Object parent, current_ancestor, window;
|
|
645
|
|
646 XSETWINDOW (window, w);
|
|
647
|
|
648 parent = XWINDOW (window)->parent;
|
|
649 current_ancestor = window;
|
|
650
|
|
651 while (!NILP (parent))
|
|
652 {
|
|
653 if (!NILP (XWINDOW (parent)->hchild) &&
|
|
654 !EQ (XWINDOW (parent)->hchild, current_ancestor))
|
|
655 return 0;
|
|
656
|
|
657 current_ancestor = parent;
|
|
658 parent = XWINDOW (parent)->parent;
|
|
659 }
|
|
660
|
|
661 return 1;
|
|
662 }
|
|
663
|
|
664 int
|
|
665 window_is_rightmost (struct window *w)
|
|
666 {
|
|
667 Lisp_Object parent, current_ancestor, window;
|
|
668
|
|
669 XSETWINDOW (window, w);
|
|
670
|
|
671 parent = XWINDOW (window)->parent;
|
|
672 current_ancestor = window;
|
|
673
|
|
674 while (!NILP (parent))
|
|
675 {
|
|
676 if (!NILP (XWINDOW (parent)->hchild)
|
|
677 && !NILP (XWINDOW (current_ancestor)->next))
|
|
678 return 0;
|
|
679
|
|
680 current_ancestor = parent;
|
|
681 parent = XWINDOW (parent)->parent;
|
|
682 }
|
|
683
|
|
684 return 1;
|
|
685 }
|
|
686
|
|
687 static int
|
|
688 window_full_width_p (struct window *w)
|
|
689 {
|
|
690 return window_is_leftmost (w) && window_is_rightmost (w);
|
|
691 }
|
|
692
|
|
693 static int
|
|
694 window_is_highest (struct window *w)
|
|
695 {
|
|
696 Lisp_Object parent, current_ancestor, window;
|
|
697
|
|
698 XSETWINDOW (window, w);
|
|
699
|
|
700 parent = XWINDOW (window)->parent;
|
|
701 current_ancestor = window;
|
|
702
|
|
703 while (!NILP (parent))
|
|
704 {
|
|
705 if (!NILP (XWINDOW (parent)->vchild) &&
|
|
706 !EQ (XWINDOW (parent)->vchild, current_ancestor))
|
|
707 return 0;
|
|
708
|
|
709 current_ancestor = parent;
|
|
710 parent = XWINDOW (parent)->parent;
|
|
711 }
|
|
712
|
|
713 /* This is really to catch the minibuffer but we make it generic in
|
|
714 case we ever change things around to let the minibuffer be on top. */
|
|
715 if (NILP (XWINDOW (current_ancestor)->prev))
|
|
716 return 1;
|
|
717 else
|
|
718 return 0;
|
|
719 }
|
|
720
|
|
721 static int
|
|
722 window_is_lowest (struct window *w)
|
|
723 {
|
|
724 Lisp_Object parent, current_ancestor, window;
|
|
725
|
|
726 XSETWINDOW (window, w);
|
|
727
|
|
728 parent = XWINDOW (window)->parent;
|
|
729 current_ancestor = window;
|
|
730
|
|
731 while (!NILP (parent))
|
|
732 {
|
|
733 if (!NILP (XWINDOW (parent)->vchild)
|
|
734 && !NILP (XWINDOW (current_ancestor)->next))
|
|
735 return 0;
|
|
736
|
|
737 current_ancestor = parent;
|
|
738 parent = XWINDOW (parent)->parent;
|
|
739 }
|
|
740
|
|
741 return 1;
|
|
742 }
|
|
743
|
|
744 #if 0 /* not currently used */
|
|
745
|
|
746 static int
|
|
747 window_full_height_p (struct window *w)
|
|
748 {
|
|
749 return window_is_highest (w) && window_is_lowest (w);
|
|
750 }
|
|
751
|
|
752 #endif
|
|
753
|
|
754 int
|
|
755 window_truncation_on (struct window *w)
|
|
756 {
|
|
757 /* Horizontally scrolled windows are truncated. */
|
|
758 if (w->hscroll)
|
|
759 return 1;
|
|
760
|
|
761 /* If truncate_partial_width_windows is true and the window is not
|
|
762 the full width of the frame it is truncated. */
|
|
763 if (truncate_partial_width_windows
|
|
764 && !(window_is_leftmost (w) && window_is_rightmost (w)))
|
|
765 return 1;
|
|
766
|
|
767 /* If the window's buffer's value of truncate_lines is non-nil, then
|
|
768 the window is truncated. */
|
|
769 if (!NILP (XBUFFER (w->buffer)->truncate_lines))
|
|
770 return 1;
|
|
771
|
|
772 return 0;
|
|
773 }
|
|
774
|
|
775 int
|
|
776 window_needs_vertical_divider (struct window *w)
|
|
777 {
|
|
778 #ifdef HAVE_SCROLLBARS
|
149
|
779 return (!window_scrollbar_width (w) &&
|
|
780 ((XFRAME (w->frame)->scrollbar_on_left) ?
|
|
781 !window_is_leftmost (w) :
|
|
782 !window_is_rightmost (w)));
|
0
|
783 #else
|
149
|
784 return !window_is_leftmost (w);
|
102
|
785 #endif /* HAVE_SCROLLBARS */
|
0
|
786 }
|
|
787
|
|
788 int
|
|
789 window_scrollbar_width (struct window *w)
|
|
790 {
|
|
791 #ifdef HAVE_SCROLLBARS
|
|
792 if (!WINDOW_WIN_P (w)
|
|
793 || MINI_WINDOW_P (w)
|
|
794 || NILP (w->buffer))
|
|
795 /* #### when does NILP (w->buffer) happen? */
|
|
796 return 0;
|
|
797
|
|
798 return XINT (w->scrollbar_width);
|
|
799 #else
|
|
800 return 0;
|
102
|
801 #endif /* HAVE_SCROLLBARS */
|
0
|
802 }
|
|
803
|
|
804 /* Horizontal scrollbars are only active on windows with truncation
|
|
805 turned on. */
|
|
806 int
|
|
807 window_scrollbar_height (struct window *w)
|
|
808 {
|
|
809 #ifdef HAVE_SCROLLBARS
|
|
810 if (!WINDOW_WIN_P (w)
|
|
811 || MINI_WINDOW_P (w)
|
|
812 || NILP (w->buffer)
|
|
813 || !window_truncation_on (w))
|
|
814 return 0;
|
|
815
|
|
816 return XINT (w->scrollbar_height);
|
|
817 #else
|
|
818 return 0;
|
102
|
819 #endif /* HAVE_SCROLLBARS */
|
0
|
820 }
|
|
821
|
|
822 int
|
|
823 window_modeline_height (struct window *w)
|
|
824 {
|
|
825 struct frame *f = XFRAME (w->frame);
|
|
826 int modeline_height;
|
|
827
|
|
828 if (MINI_WINDOW_P (w) || NILP (w->buffer))
|
|
829 {
|
|
830 modeline_height = 0;
|
|
831 }
|
|
832 else if (!WINDOW_HAS_MODELINE_P (w))
|
|
833 {
|
|
834 if (window_scrollbar_height (w))
|
|
835 modeline_height = 0;
|
|
836 else
|
|
837 {
|
|
838 modeline_height = FRAMEMETH (f, divider_height, ());
|
|
839
|
|
840 if (!EQ (Qzero, w->modeline_shadow_thickness) && FRAME_WIN_P (f))
|
|
841 modeline_height += (2 * MODELINE_SHADOW_THICKNESS (w));
|
|
842 }
|
|
843 }
|
|
844 else
|
|
845 {
|
|
846 if (noninteractive)
|
|
847 modeline_height = 0;
|
|
848 else
|
|
849 {
|
|
850 display_line_dynarr *dla;
|
|
851
|
|
852 /* We don't force a regeneration of the modeline here.
|
|
853 Instead it is now a precondition that any function calling
|
|
854 this should make sure that one of these structures is
|
|
855 up-to-date. In practice this only affects two internal
|
|
856 redisplay functions, regenerate_window and
|
|
857 regenerate_window_point_center. */
|
|
858 /* We check DESIRED_DISP because if it is valid it is more
|
|
859 up-to-date than CURRENT_DISP. For calls to this outside
|
|
860 of redisplay it doesn't matter which structure we check
|
|
861 since there is a redisplay condition that these
|
|
862 structures be identical outside of redisplay. */
|
|
863 dla = window_display_lines (w, DESIRED_DISP);
|
|
864 if (dla && Dynarr_length (dla) && Dynarr_atp (dla, 0)->modeline)
|
|
865 modeline_height = (Dynarr_atp (dla, 0)->ascent +
|
|
866 Dynarr_atp (dla, 0)->descent);
|
|
867 else
|
|
868 {
|
|
869 dla = window_display_lines (w, CURRENT_DISP);
|
|
870 if (dla && Dynarr_length (dla) && Dynarr_atp (dla, 0)->modeline)
|
|
871 modeline_height = (Dynarr_atp (dla, 0)->ascent +
|
|
872 Dynarr_atp (dla, 0)->descent);
|
|
873 else
|
|
874 /* This should be an abort except I'm not yet 100%
|
|
875 confident that it won't ever get hit (though I
|
|
876 haven't been able to trigger it). It is extremely
|
|
877 unlikely to cause any noticable problem and even if
|
|
878 it does it will be a minor display glitch. */
|
|
879 /* #### Bullshit alert. It does get hit and it causes
|
|
880 noticeable glitches. real_current_modeline_height
|
|
881 is a kludge to fix this for 19.14. */
|
|
882 modeline_height = real_current_modeline_height (w);
|
|
883 }
|
|
884
|
|
885 if (!EQ (Qzero, w->modeline_shadow_thickness) && FRAME_WIN_P (f))
|
|
886 modeline_height += (2 * MODELINE_SHADOW_THICKNESS (w));
|
|
887 }
|
|
888 }
|
|
889
|
|
890 return modeline_height;
|
|
891 }
|
|
892
|
|
893 /*****************************************************************************
|
|
894 margin_width_internal
|
|
895
|
|
896 For a given window, return the width in pixels of the specified margin.
|
|
897 ****************************************************************************/
|
|
898 static int
|
|
899 margin_width_internal (struct window *w, int left_margin)
|
|
900 {
|
|
901 struct buffer *b;
|
|
902 int window_cwidth = window_char_width (w, 1);
|
|
903 int margin_cwidth;
|
|
904 int font_width;
|
|
905 Lisp_Object window = Qnil;
|
|
906
|
|
907 /* We might be getting called on a non-leaf. */
|
|
908 if (NILP (w->buffer))
|
|
909 return 0;
|
|
910
|
|
911 /* The minibuffer never has margins. */
|
|
912 if (MINI_WINDOW_P (w))
|
|
913 return 0;
|
|
914
|
|
915 XSETWINDOW (window, w);
|
|
916 b = XBUFFER (w->buffer);
|
|
917 margin_cwidth = (left_margin ? XINT (w->left_margin_width) :
|
|
918 XINT (w->right_margin_width));
|
|
919
|
|
920 default_face_height_and_width (window, 0, &font_width);
|
|
921
|
|
922 /* The left margin takes precedence over the right margin so we
|
|
923 subtract its width from the space available for the right
|
|
924 margin. */
|
|
925 if (!left_margin)
|
|
926 window_cwidth -= XINT (w->left_margin_width);
|
|
927
|
|
928 /* The margin cannot be wider than the window is. We allow the
|
|
929 value to be bigger since it is possible for the user to enlarge
|
|
930 the window such that the left margin value would no longer be too
|
|
931 big, but we won't return a value that is larger. */
|
|
932 if (margin_cwidth > window_cwidth)
|
|
933 margin_cwidth = window_cwidth;
|
|
934
|
|
935 /* At the user level the margin is always specified in characters.
|
|
936 Internally however it is manipulated in terms of pixels. */
|
173
|
937 return margin_cwidth * font_width;
|
0
|
938 }
|
|
939
|
|
940 int
|
|
941 window_left_margin_width (struct window *w)
|
|
942 {
|
|
943 return margin_width_internal (w, 1);
|
|
944 }
|
|
945
|
|
946 int
|
|
947 window_right_margin_width (struct window *w)
|
|
948 {
|
|
949 return margin_width_internal (w, 0);
|
|
950 }
|
|
951
|
|
952 static int
|
|
953 window_top_toolbar_height (struct window *w)
|
|
954 {
|
|
955 /* #### implement this shit. */
|
|
956 return 0;
|
|
957 }
|
|
958
|
|
959 /* #### Currently used in scrollbar.c. Does it actually need to be? */
|
|
960 int
|
|
961 window_bottom_toolbar_height (struct window *w)
|
|
962 {
|
|
963 return 0;
|
|
964 }
|
|
965
|
|
966 static int
|
|
967 window_left_toolbar_width (struct window *w)
|
|
968 {
|
|
969 return 0;
|
|
970 }
|
|
971
|
|
972 static int
|
|
973 window_right_toolbar_width (struct window *w)
|
|
974 {
|
|
975 return 0;
|
|
976 }
|
|
977
|
|
978 /*****************************************************************************
|
|
979 Window Gutters
|
|
980
|
|
981 The gutters of a window are those areas in the boundary defined by
|
|
982 w->pixel_top, w->pixel_left, w->pixel_height and w->pixel_width which
|
|
983 do not contain text. Items which may be in the gutters include
|
|
984 scrollbars, toolbars and modelines. The margin areas are not
|
|
985 included. This is an exception made because redisplay special cases
|
|
986 the handling of those areas in many places in such a way that
|
|
987 including them in the gutter area would make life difficult.
|
|
988
|
|
989 The size functions refer to height for the bottom and top gutters and
|
|
990 width for the left and right gutters. The starting position
|
|
991 functions refer to the Y coord for bottom and top gutters and the X
|
|
992 coord for left and right gutters. All starting positions are
|
|
993 relative to the frame, not the window.
|
|
994 ****************************************************************************/
|
|
995
|
|
996 int
|
|
997 window_top_gutter_height (struct window *w)
|
|
998 {
|
|
999 int toolbar_height = window_top_toolbar_height (w);
|
|
1000
|
|
1001 if (!NILP (w->hchild) || !NILP (w->vchild))
|
|
1002 return 0;
|
|
1003
|
|
1004 #ifdef HAVE_SCROLLBARS
|
|
1005 if (XFRAME (w->frame)->scrollbar_on_top)
|
|
1006 return window_scrollbar_height (w) + toolbar_height;
|
|
1007 else
|
|
1008 #endif
|
|
1009 return toolbar_height;
|
|
1010 }
|
|
1011
|
|
1012 int
|
|
1013 window_bottom_gutter_height (struct window *w)
|
|
1014 {
|
185
|
1015 int other_height;
|
0
|
1016
|
|
1017 if (!NILP (w->hchild) || !NILP (w->vchild))
|
|
1018 return 0;
|
|
1019 else
|
|
1020 other_height =
|
|
1021 window_modeline_height (w) + window_bottom_toolbar_height (w);
|
|
1022
|
|
1023 #ifdef HAVE_SCROLLBARS
|
|
1024 if (!XFRAME (w->frame)->scrollbar_on_top)
|
|
1025 return window_scrollbar_height (w) + other_height;
|
|
1026 else
|
|
1027 #endif
|
|
1028 return other_height;
|
|
1029 }
|
|
1030
|
|
1031 static int
|
|
1032 window_left_right_gutter_width_internal (struct window *w, int modeline)
|
|
1033 {
|
|
1034 struct frame *f = XFRAME (w->frame);
|
|
1035 int scrollbar_width = window_scrollbar_width (w);
|
|
1036
|
|
1037 if (!NILP (w->hchild) || !NILP (w->vchild))
|
|
1038 return 0;
|
|
1039
|
|
1040 if (!modeline)
|
|
1041 {
|
|
1042 if (scrollbar_width)
|
|
1043 return scrollbar_width;
|
|
1044 else if (window_needs_vertical_divider (w))
|
|
1045 return FRAMEMETH (f, divider_width, ());
|
|
1046 else
|
|
1047 return 0;
|
|
1048 }
|
|
1049 else
|
|
1050 {
|
|
1051 /* The shadows on the 3D modelines provide a visual break
|
|
1052 between the modelines of horizontally split windows. 2D
|
|
1053 modelines need some help, though. */
|
|
1054 if (!EQ (Qzero, w->modeline_shadow_thickness))
|
|
1055 return 0;
|
|
1056 else if (window_needs_vertical_divider (w))
|
|
1057 return FRAMEMETH (f, divider_width, ());
|
|
1058 else
|
|
1059 return 0;
|
|
1060 }
|
|
1061 }
|
|
1062
|
|
1063 int
|
|
1064 window_left_gutter_width (struct window *w, int modeline)
|
|
1065 {
|
|
1066 if (!NILP (w->hchild) || !NILP (w->vchild))
|
|
1067 return 0;
|
|
1068
|
|
1069 #ifdef HAVE_SCROLLBARS
|
|
1070 if (XFRAME (w->frame)->scrollbar_on_left)
|
|
1071 {
|
|
1072 #endif
|
|
1073 return (window_left_right_gutter_width_internal (w, modeline) +
|
|
1074 window_left_toolbar_width (w));
|
|
1075 #ifdef HAVE_SCROLLBARS
|
|
1076 }
|
|
1077 else
|
|
1078 return window_left_toolbar_width (w);
|
|
1079 #endif
|
|
1080 }
|
|
1081
|
|
1082 int
|
|
1083 window_right_gutter_width (struct window *w, int modeline)
|
|
1084 {
|
|
1085 if (!NILP (w->hchild) || !NILP (w->vchild))
|
|
1086 return 0;
|
|
1087
|
|
1088 #ifdef HAVE_SCROLLBARS
|
|
1089 if (!XFRAME (w->frame)->scrollbar_on_left)
|
|
1090 {
|
|
1091 return (window_left_right_gutter_width_internal (w, modeline) +
|
|
1092 window_right_toolbar_width (w));
|
|
1093 }
|
|
1094 else
|
|
1095 #endif
|
|
1096 return window_right_toolbar_width (w);
|
|
1097 }
|
|
1098
|
|
1099
|
20
|
1100 DEFUN ("windowp", Fwindowp, 1, 1, 0, /*
|
0
|
1101 Return t if OBJ is a window.
|
20
|
1102 */
|
|
1103 (obj))
|
0
|
1104 {
|
173
|
1105 return WINDOWP (obj) ? Qt : Qnil;
|
0
|
1106 }
|
|
1107
|
20
|
1108 DEFUN ("window-live-p", Fwindow_live_p, 1, 1, 0, /*
|
0
|
1109 Return t if OBJ is a window which is currently visible.
|
20
|
1110 */
|
|
1111 (obj))
|
0
|
1112 {
|
173
|
1113 return WINDOWP (obj) && WINDOW_LIVE_P (XWINDOW (obj)) ? Qt : Qnil;
|
0
|
1114 }
|
|
1115
|
20
|
1116 DEFUN ("selected-window", Fselected_window, 0, 1, 0, /*
|
0
|
1117 Return the window that the cursor now appears in and commands apply to.
|
|
1118 If the optional argument CON-DEV-OR-FRAME is specified and is a frame, return
|
|
1119 the selected window used by that frame. If CON-DEV-OR-FRAME is a device,
|
|
1120 then the selected frame on that device will be used. If CON-DEV-OR-FRAME
|
|
1121 is a console, the selected frame on that console's selected device will
|
|
1122 be used. Otherwise, the selected frame is used.
|
20
|
1123 */
|
|
1124 (con_dev_or_frame))
|
0
|
1125 {
|
|
1126 struct frame *f;
|
|
1127
|
|
1128 if (NILP (con_dev_or_frame) && NILP (Fselected_device (Qnil)))
|
|
1129 return Qnil; /* happens at startup */
|
|
1130
|
|
1131 f = decode_frame_or_selected (con_dev_or_frame);
|
|
1132 return FRAME_SELECTED_WINDOW (f);
|
|
1133 }
|
|
1134
|
20
|
1135 DEFUN ("minibuffer-window", Fminibuffer_window, 0, 1, 0, /*
|
0
|
1136 Return the window used now for minibuffers.
|
|
1137 If the optional argument CON-DEV-OR-FRAME is specified and is a frame, return
|
|
1138 the minibuffer window used by that frame. If CON-DEV-OR-FRAME is a device,
|
|
1139 then the selected frame on that device will be used. If CON-DEV-OR-FRAME
|
|
1140 is a console, the selected frame on that console's selected device will
|
|
1141 be used. Otherwise, the selected frame is used.
|
20
|
1142 */
|
|
1143 (con_dev_or_frame))
|
0
|
1144 {
|
|
1145 struct frame *f = decode_frame_or_selected (con_dev_or_frame);
|
|
1146
|
|
1147 return FRAME_MINIBUF_WINDOW (f);
|
|
1148 }
|
|
1149
|
20
|
1150 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p, 1, 1, 0, /*
|
0
|
1151 Return non-nil if WINDOW is a minibuffer window.
|
20
|
1152 */
|
|
1153 (window))
|
0
|
1154 {
|
173
|
1155 return MINI_WINDOW_P (decode_window (window)) ? Qt : Qnil;
|
0
|
1156 }
|
|
1157
|
20
|
1158 DEFUN ("window-first-hchild", Fwindow_first_hchild, 1, 1, 0, /*
|
0
|
1159 Return the first horizontal child of WINDOW, or nil.
|
20
|
1160 */
|
|
1161 (window))
|
0
|
1162 {
|
102
|
1163 return decode_window (window)->hchild;
|
0
|
1164 }
|
|
1165
|
20
|
1166 DEFUN ("window-first-vchild", Fwindow_first_vchild, 1, 1, 0, /*
|
0
|
1167 Return the first vertical child of WINDOW, or nil.
|
20
|
1168 */
|
|
1169 (window))
|
0
|
1170 {
|
102
|
1171 return decode_window (window)->vchild;
|
0
|
1172 }
|
|
1173
|
20
|
1174 DEFUN ("window-next-child", Fwindow_next_child, 1, 1, 0, /*
|
0
|
1175 Return the next window on the same level as WINDOW, or nil.
|
20
|
1176 */
|
|
1177 (window))
|
0
|
1178 {
|
102
|
1179 return decode_window (window)->next;
|
0
|
1180 }
|
|
1181
|
20
|
1182 DEFUN ("window-previous-child", Fwindow_previous_child, 1, 1, 0, /*
|
0
|
1183 Return the previous window on the same level as WINDOW, or nil.
|
20
|
1184 */
|
|
1185 (window))
|
0
|
1186 {
|
102
|
1187 return decode_window (window)->prev;
|
0
|
1188 }
|
|
1189
|
20
|
1190 DEFUN ("window-parent", Fwindow_parent, 1, 1, 0, /*
|
0
|
1191 Return the parent of WINDOW, or nil.
|
20
|
1192 */
|
|
1193 (window))
|
0
|
1194 {
|
102
|
1195 return decode_window (window)->parent;
|
0
|
1196 }
|
|
1197
|
20
|
1198 DEFUN ("window-lowest-p", Fwindow_lowest_p, 1, 1, 0, /*
|
0
|
1199 Return non-nil if WINDOW is along the bottom of its frame.
|
20
|
1200 */
|
|
1201 (window))
|
0
|
1202 {
|
102
|
1203 return window_is_lowest (decode_window (window)) ? Qt : Qnil;
|
0
|
1204 }
|
|
1205
|
20
|
1206 DEFUN ("window-highest-p", Fwindow_highest_p, 1, 1, 0, /*
|
0
|
1207 Return non-nil if WINDOW is along the top of its frame.
|
20
|
1208 */
|
|
1209 (window))
|
0
|
1210 {
|
102
|
1211 return window_is_highest (decode_window (window)) ? Qt : Qnil;
|
0
|
1212 }
|
|
1213
|
20
|
1214 DEFUN ("window-leftmost-p", Fwindow_leftmost_p, 1, 1, 0, /*
|
0
|
1215 Return non-nil if WINDOW is along the left edge of its frame.
|
20
|
1216 */
|
|
1217 (window))
|
0
|
1218 {
|
102
|
1219 return window_is_leftmost (decode_window (window)) ? Qt : Qnil;
|
0
|
1220 }
|
|
1221
|
20
|
1222 DEFUN ("window-rightmost-p", Fwindow_rightmost_p, 1, 1, 0, /*
|
0
|
1223 Return non-nil if WINDOW is along the right edge of its frame.
|
20
|
1224 */
|
|
1225 (window))
|
0
|
1226 {
|
102
|
1227 return window_is_rightmost (decode_window (window)) ? Qt : Qnil;
|
0
|
1228 }
|
|
1229
|
20
|
1230 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p, 0, 2, 0, /*
|
0
|
1231 Return t if position POS is currently on the frame in WINDOW.
|
|
1232 Returns nil if that position is scrolled vertically out of view.
|
|
1233 POS defaults to point in WINDOW's buffer; WINDOW, to the selected window.
|
20
|
1234 */
|
|
1235 (pos, window))
|
0
|
1236 {
|
102
|
1237 struct window *w = decode_window (window);
|
0
|
1238 Bufpos top;
|
|
1239 Bufpos posint;
|
|
1240 struct buffer *buf;
|
|
1241
|
|
1242 top = marker_position (w->start[CURRENT_DISP]);
|
|
1243
|
|
1244 buf = XBUFFER (w->buffer);
|
|
1245
|
|
1246 if (NILP (pos))
|
|
1247 posint = BUF_PT (buf);
|
|
1248 else
|
|
1249 {
|
|
1250 CHECK_INT_COERCE_MARKER (pos);
|
|
1251 posint = XINT (pos);
|
|
1252 }
|
|
1253
|
|
1254 if (posint < top || posint > BUF_ZV (buf))
|
|
1255 return Qnil;
|
|
1256
|
|
1257 /* w->start can be out of range. If it is, do something reasonable. */
|
|
1258 if (top < BUF_BEGV (buf) || top > BUF_ZV (buf))
|
|
1259 return Qnil;
|
|
1260
|
|
1261 if (point_would_be_visible (w, top, posint))
|
|
1262 return Qt;
|
|
1263 else
|
|
1264 return Qnil;
|
|
1265 }
|
|
1266
|
|
1267
|
|
1268 struct window *
|
|
1269 decode_window (Lisp_Object window)
|
|
1270 {
|
|
1271 if (NILP (window))
|
|
1272 return XWINDOW (Fselected_window (Qnil));
|
|
1273
|
|
1274 CHECK_LIVE_WINDOW (window);
|
|
1275 return XWINDOW (window);
|
|
1276 }
|
|
1277
|
20
|
1278 DEFUN ("window-buffer", Fwindow_buffer, 0, 1, 0, /*
|
0
|
1279 Return the buffer that WINDOW is displaying.
|
20
|
1280 */
|
|
1281 (window))
|
0
|
1282 {
|
|
1283 return decode_window (window)->buffer;
|
|
1284 }
|
|
1285
|
20
|
1286 DEFUN ("window-frame", Fwindow_frame, 0, 1, 0, /*
|
0
|
1287 Return the frame that window WINDOW is on.
|
20
|
1288 */
|
|
1289 (window))
|
0
|
1290 {
|
|
1291 return decode_window (window)->frame;
|
|
1292 }
|
|
1293
|
20
|
1294 DEFUN ("window-height", Fwindow_height, 0, 1, 0, /*
|
0
|
1295 Return the number of default lines in WINDOW.
|
|
1296 This actually works by dividing the window's pixel height (including
|
|
1297 the modeline and horizontal scrollbar, if any) by the height of the
|
|
1298 default font; therefore, the number of displayed lines will probably
|
|
1299 be different.
|
|
1300 Use `window-height' to get consistent results in geometry calculations.
|
|
1301 Use `window-displayed-height' to get the actual number of lines
|
|
1302 currently displayed in a window.
|
20
|
1303 */
|
|
1304 (window))
|
0
|
1305 {
|
|
1306 return make_int (window_char_height (decode_window (window), 1));
|
|
1307 }
|
|
1308
|
20
|
1309 DEFUN ("window-displayed-height", Fwindow_displayed_height, 0, 1, 0, /*
|
0
|
1310 Return the number of lines currently displayed in WINDOW.
|
|
1311 This counts the actual number of lines displayed in WINDOW
|
|
1312 (as opposed to `window-height'). The modeline and horizontal
|
|
1313 scrollbar do not count as lines. If there is some blank space
|
|
1314 between the end of the buffer and the end of the window, this
|
|
1315 function pretends that there are lines of text in the default
|
|
1316 font there.
|
20
|
1317 */
|
70
|
1318 (window))
|
0
|
1319 {
|
|
1320 return make_int (window_displayed_height (decode_window (window)));
|
|
1321 }
|
|
1322
|
20
|
1323 DEFUN ("window-pixel-height", Fwindow_pixel_height, 0, 1, 0, /*
|
0
|
1324 Return the height of WINDOW in pixels. Defaults to current window.
|
|
1325 This includes the window's modeline and horizontal scrollbar (if any).
|
20
|
1326 */
|
|
1327 (window))
|
0
|
1328 {
|
173
|
1329 return make_int (decode_window (window)->pixel_height);
|
0
|
1330 }
|
|
1331
|
20
|
1332 DEFUN ("window-width", Fwindow_width, 0, 1, 0, /*
|
0
|
1333 Return the number of display columns in WINDOW.
|
|
1334 This is the width that is usable columns available for text in WINDOW.
|
20
|
1335 */
|
|
1336 (window))
|
0
|
1337 {
|
173
|
1338 return make_int (window_char_width (decode_window (window), 0));
|
0
|
1339 }
|
|
1340
|
20
|
1341 DEFUN ("window-pixel-width", Fwindow_pixel_width, 0, 1, 0, /*
|
0
|
1342 Return the width of WINDOW in pixels. Defaults to current window.
|
20
|
1343 */
|
|
1344 (window))
|
0
|
1345 {
|
173
|
1346 return make_int (decode_window (window)->pixel_width);
|
0
|
1347 }
|
|
1348
|
20
|
1349 DEFUN ("window-hscroll", Fwindow_hscroll, 0, 1, 0, /*
|
0
|
1350 Return the number of columns by which WINDOW is scrolled from left margin.
|
20
|
1351 */
|
|
1352 (window))
|
0
|
1353 {
|
173
|
1354 return make_int (decode_window (window)->hscroll);
|
0
|
1355 }
|
|
1356
|
20
|
1357 DEFUN ("set-window-hscroll", Fset_window_hscroll, 2, 2, 0, /*
|
0
|
1358 Set number of columns WINDOW is scrolled from left margin to NCOL.
|
|
1359 NCOL should be zero or positive.
|
20
|
1360 */
|
|
1361 (window, ncol))
|
0
|
1362 {
|
|
1363 struct window *w;
|
|
1364 int ncols;
|
|
1365
|
|
1366 CHECK_INT (ncol);
|
|
1367 ncols = XINT (ncol);
|
|
1368 if (ncols < 0) ncols = 0;
|
|
1369 w = decode_window (window);
|
|
1370 if (w->hscroll != ncols)
|
|
1371 MARK_CLIP_CHANGED; /* FSF marks differently but we aren't FSF. */
|
|
1372 w->hscroll = ncols;
|
|
1373 return ncol;
|
|
1374 }
|
|
1375
|
251
|
1376 #if 0 /* bogus crock */
|
0
|
1377
|
149
|
1378 xxDEFUN ("window-redisplay-end-trigger",
|
|
1379 Fwindow_redisplay_end_trigger, 0, 1, 0, /*
|
0
|
1380 Return WINDOW's redisplay end trigger value.
|
|
1381 See `set-window-redisplay-end-trigger' for more information.
|
102
|
1382 */
|
|
1383 (window))
|
0
|
1384 {
|
|
1385 return decode_window (window)->redisplay_end_trigger;
|
|
1386 }
|
|
1387
|
149
|
1388 xxDEFUN ("set-window-redisplay-end-trigger",
|
|
1389 Fset_window_redisplay_end_trigger, 2, 2, 0, /*
|
0
|
1390 Set WINDOW's redisplay end trigger value to VALUE.
|
|
1391 VALUE should be a buffer position (typically a marker) or nil.
|
|
1392 If it is a buffer position, then if redisplay in WINDOW reaches a position
|
|
1393 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
|
|
1394 with two arguments: WINDOW, and the end trigger value.
|
|
1395 Afterwards the end-trigger value is reset to nil.
|
185
|
1396 */
|
102
|
1397 (window, value))
|
0
|
1398 {
|
102
|
1399 return (decode_window (window)->redisplay_end_trigger = value);
|
0
|
1400 }
|
|
1401
|
|
1402 #endif /* 0 */
|
|
1403
|
20
|
1404 DEFUN ("window-pixel-edges", Fwindow_pixel_edges, 0, 1, 0, /*
|
0
|
1405 Return a list of the pixel edge coordinates of WINDOW.
|
|
1406 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
|
|
1407 The frame toolbars and menubars are considered to be outside of this area.
|
20
|
1408 */
|
|
1409 (window))
|
0
|
1410 {
|
|
1411 struct window *w = decode_window (window);
|
|
1412 struct frame *f = XFRAME (w->frame);
|
149
|
1413
|
|
1414 int left = w->pixel_left - FRAME_LEFT_BORDER_END (f);
|
|
1415 int top = w->pixel_top - FRAME_TOP_BORDER_END (f);
|
0
|
1416
|
|
1417 return list4 (make_int (left),
|
|
1418 make_int (top),
|
|
1419 make_int (left + w->pixel_width),
|
|
1420 make_int (top + w->pixel_height));
|
|
1421 }
|
|
1422
|
20
|
1423 DEFUN ("window-point", Fwindow_point, 0, 1, 0, /*
|
0
|
1424 Return current value of point in WINDOW.
|
|
1425 For a nonselected window, this is the value point would have
|
|
1426 if that window were selected.
|
|
1427
|
|
1428 Note that, when WINDOW is the selected window and its buffer
|
|
1429 is also currently selected, the value returned is the same as (point).
|
|
1430 It would be more strictly correct to return the `top-level' value
|
|
1431 of point, outside of any save-excursion forms.
|
|
1432 But that is hard to define.
|
20
|
1433 */
|
|
1434 (window))
|
0
|
1435 {
|
|
1436 struct window *w = decode_window (window);
|
|
1437
|
|
1438 /* The special check for current buffer is necessary for this
|
|
1439 function to work as defined when called within an excursion. */
|
|
1440 if (w == XWINDOW (Fselected_window (XFRAME (w->frame)->device))
|
|
1441 && current_buffer == XBUFFER (w->buffer))
|
|
1442 return Fpoint (Qnil);
|
|
1443 return Fmarker_position (w->pointm[CURRENT_DISP]);
|
|
1444 }
|
|
1445
|
20
|
1446 DEFUN ("window-start", Fwindow_start, 0, 1, 0, /*
|
0
|
1447 Return position at which display currently starts in WINDOW.
|
|
1448 This is updated by redisplay or by calling `set-window-start'.
|
20
|
1449 */
|
|
1450 (window))
|
0
|
1451 {
|
|
1452 return Fmarker_position (decode_window (window)->start[CURRENT_DISP]);
|
|
1453 }
|
|
1454
|
20
|
1455 DEFUN ("window-end", Fwindow_end, 0, 2, 0, /*
|
0
|
1456 Return position at which display currently ends in WINDOW.
|
|
1457 This is updated by redisplay, when it runs to completion.
|
|
1458 Simply changing the buffer text or setting `window-start'
|
|
1459 does not update this value.
|
|
1460 If GUARANTEE is non-nil, then the return value is guaranteed to be
|
|
1461 the value of window-end at the end of the next full redisplay assuming
|
|
1462 nothing else changes in the meantime. This function is potentially much
|
|
1463 slower with this flag set.
|
20
|
1464 */
|
|
1465 (window, guarantee))
|
0
|
1466 {
|
|
1467 Lisp_Object value;
|
|
1468 struct window *w = decode_window (window);
|
|
1469 Lisp_Object buf;
|
|
1470
|
|
1471 if (NILP (guarantee))
|
|
1472 {
|
|
1473 buf = w->buffer;
|
|
1474 CHECK_BUFFER (buf);
|
|
1475
|
|
1476 XSETINT (value, BUF_Z (XBUFFER (buf)) - w->window_end_pos[CURRENT_DISP]);
|
|
1477
|
|
1478 return value;
|
|
1479 }
|
|
1480 else
|
|
1481 {
|
|
1482 Bufpos startp = marker_position (w->start[CURRENT_DISP]);
|
173
|
1483 return make_int (end_of_last_line (w, startp));
|
0
|
1484 }
|
|
1485 }
|
|
1486
|
20
|
1487 DEFUN ("set-window-point", Fset_window_point, 2, 2, 0, /*
|
0
|
1488 Make point value in WINDOW be at position POS in WINDOW's buffer.
|
20
|
1489 */
|
|
1490 (window, pos))
|
0
|
1491 {
|
|
1492 struct window *w = decode_window (window);
|
|
1493
|
|
1494 CHECK_INT_COERCE_MARKER (pos);
|
|
1495 if (w == XWINDOW (Fselected_window (Qnil)))
|
223
|
1496 Fgoto_char (pos, Qnil);
|
0
|
1497 else
|
|
1498 set_marker_restricted (w->pointm[CURRENT_DISP], pos, w->buffer);
|
|
1499
|
|
1500 MARK_POINT_CHANGED;
|
|
1501 return pos;
|
|
1502 }
|
|
1503
|
20
|
1504 DEFUN ("set-window-start", Fset_window_start, 2, 3, 0, /*
|
0
|
1505 Make display in WINDOW start at position POS in WINDOW's buffer.
|
|
1506 Optional third arg NOFORCE non-nil inhibits next redisplay
|
|
1507 from overriding motion of point in order to display at this exact start.
|
20
|
1508 */
|
|
1509 (window, pos, noforce))
|
0
|
1510 {
|
|
1511 struct window *w = decode_window (window);
|
|
1512
|
|
1513 CHECK_INT_COERCE_MARKER (pos);
|
|
1514 set_marker_restricted (w->start[CURRENT_DISP], pos, w->buffer);
|
|
1515 /* this is not right, but much easier than doing what is right. */
|
|
1516 w->start_at_line_beg = 0;
|
|
1517 if (NILP (noforce))
|
|
1518 w->force_start = 1;
|
|
1519 w->redo_modeline = 1;
|
|
1520 SET_LAST_MODIFIED (w, 0);
|
|
1521 SET_LAST_FACECHANGE (w);
|
|
1522
|
|
1523 MARK_WINDOWS_CHANGED (w);
|
|
1524
|
|
1525 return pos;
|
|
1526 }
|
|
1527
|
20
|
1528 DEFUN ("window-dedicated-p", Fwindow_dedicated_p, 1, 1, 0, /*
|
0
|
1529 Return WINDOW's dedicated object, usually t or nil.
|
|
1530 See also `set-window-dedicated-p'.
|
20
|
1531 */
|
|
1532 (window))
|
0
|
1533 {
|
|
1534 return decode_window (window)->dedicated;
|
|
1535 }
|
|
1536
|
20
|
1537 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p, 2, 2, 0, /*
|
0
|
1538 Control whether WINDOW is dedicated to the buffer it displays.
|
|
1539 If it is dedicated, Emacs will not automatically change
|
|
1540 which buffer appears in it.
|
|
1541 The second argument is the new value for the dedication flag;
|
|
1542 non-nil means yes.
|
20
|
1543 */
|
|
1544 (window, arg))
|
0
|
1545 {
|
203
|
1546 REGISTER struct window *w = decode_window (window);
|
0
|
1547
|
149
|
1548 w->dedicated = NILP (arg) ? Qnil : Qt;
|
0
|
1549
|
|
1550 return w->dedicated;
|
|
1551 }
|
|
1552
|
|
1553 /* FSFmacs has window-display-table here. We have display table as a
|
|
1554 specifier. */
|
|
1555
|
|
1556
|
|
1557 /* Record info on buffer window w is displaying
|
|
1558 when it is about to cease to display that buffer. */
|
|
1559 static void
|
|
1560 unshow_buffer (struct window *w)
|
|
1561 {
|
|
1562 Lisp_Object buf = w->buffer;
|
|
1563
|
|
1564 if (XBUFFER (buf) != XMARKER (w->pointm[CURRENT_DISP])->buffer)
|
|
1565 abort ();
|
|
1566
|
|
1567 /* FSF disables this check, so I'll do it too. I hope it won't
|
|
1568 break things. --ben */
|
|
1569 #if 0
|
|
1570 if (w == XWINDOW (Fselected_window (Qnil))
|
|
1571 || ! EQ (buf, XWINDOW (Fselected_window (Qnil))->buffer))
|
|
1572 /* Do this except when the selected window's buffer
|
|
1573 is being removed from some other window. */
|
|
1574 #endif
|
|
1575 /* last_window_start records the start position that this buffer
|
|
1576 had in the last window to be disconnected from it.
|
|
1577 Now that this statement is unconditional,
|
|
1578 it is possible for the buffer to be displayed in the
|
|
1579 selected window, while last_window_start reflects another
|
|
1580 window which was recently showing the same buffer.
|
|
1581 Some people might say that might be a good thing. Let's see. */
|
|
1582 XBUFFER (buf)->last_window_start =
|
|
1583 marker_position (w->start[CURRENT_DISP]);
|
|
1584
|
|
1585 /* Point in the selected window's buffer
|
|
1586 is actually stored in that buffer, and the window's pointm isn't used.
|
|
1587 So don't clobber point in that buffer. */
|
|
1588 if (! EQ (buf, XWINDOW (Fselected_window (Qnil))->buffer))
|
|
1589 {
|
|
1590 struct buffer *b= XBUFFER (buf);
|
|
1591 BUF_SET_PT (b, bufpos_clip_to_bounds (BUF_BEGV (b),
|
|
1592 marker_position (w->pointm[CURRENT_DISP]),
|
|
1593 BUF_ZV (b)));
|
|
1594 }
|
|
1595 }
|
|
1596
|
|
1597 /* Put REPLACEMENT into the window structure in place of OLD. */
|
|
1598 static void
|
|
1599 replace_window (Lisp_Object old, Lisp_Object replacement)
|
|
1600 {
|
|
1601 Lisp_Object tem;
|
|
1602 struct window *o = XWINDOW (old), *p = XWINDOW (replacement);
|
|
1603
|
|
1604 /* If OLD is its frame's root_window, then replacement is the new
|
|
1605 root_window for that frame. */
|
|
1606
|
|
1607 if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame))))
|
|
1608 FRAME_ROOT_WINDOW (XFRAME (o->frame)) = replacement;
|
|
1609
|
|
1610 WINDOW_LEFT (p) = WINDOW_LEFT (o);
|
|
1611 WINDOW_TOP (p) = WINDOW_TOP (o);
|
|
1612 WINDOW_WIDTH (p) = WINDOW_WIDTH (o);
|
|
1613 WINDOW_HEIGHT (p) = WINDOW_HEIGHT (o);
|
|
1614
|
|
1615 p->next = tem = o->next;
|
|
1616 if (!NILP (tem))
|
|
1617 XWINDOW (tem)->prev = replacement;
|
|
1618
|
|
1619 p->prev = tem = o->prev;
|
|
1620 if (!NILP (tem))
|
|
1621 XWINDOW (tem)->next = replacement;
|
|
1622
|
|
1623 p->parent = tem = o->parent;
|
|
1624 if (!NILP (tem))
|
|
1625 {
|
|
1626 if (EQ (XWINDOW (tem)->vchild, old))
|
|
1627 XWINDOW (tem)->vchild = replacement;
|
|
1628 if (EQ (XWINDOW (tem)->hchild, old))
|
|
1629 XWINDOW (tem)->hchild = replacement;
|
|
1630 }
|
|
1631
|
|
1632 /* #### Here, if replacement is a vertical combination
|
|
1633 and so is its new parent, we should make replacement's
|
|
1634 children be children of that parent instead. */
|
|
1635 }
|
|
1636
|
|
1637 /* we're deleting W; set the structure of W to indicate this. */
|
|
1638
|
|
1639 static void
|
|
1640 mark_window_as_deleted (struct window *w)
|
|
1641 {
|
|
1642 /* In the loop
|
|
1643 (while t (split-window) (delete-window))
|
|
1644 we end up with a tree of deleted windows which are all connected
|
|
1645 through the `next' slot. This might not seem so bad, as they're
|
|
1646 deleted, and will presumably be GCed - but if even *one* of those
|
|
1647 windows is still being pointed to, by the user, or by a window
|
|
1648 configuration, then *all* of those windows stick around.
|
|
1649
|
|
1650 Since the window-configuration code doesn't need any of the
|
|
1651 pointers to other windows (they are all recreated from the
|
|
1652 window-config data), we set them all to nil so that we
|
|
1653 are able to collect more actual garbage.
|
|
1654 */
|
|
1655 w->next = Qnil;
|
|
1656 w->prev = Qnil;
|
|
1657 w->hchild = Qnil;
|
|
1658 w->vchild = Qnil;
|
|
1659 w->parent = Qnil;
|
|
1660
|
|
1661 w->dead = 1;
|
|
1662
|
|
1663 /* Free the extra data structures attached to windows immediately so
|
|
1664 they don't sit around consuming excess space. They will be
|
|
1665 reinitialized by the window-configuration code as necessary. */
|
|
1666 finalize_window ((void *) w, 0);
|
|
1667 }
|
|
1668
|
20
|
1669 DEFUN ("delete-window", Fdelete_window, 0, 2, "", /*
|
0
|
1670 Remove WINDOW from the display. Default is selected window.
|
|
1671 If window is the only one on the frame, the frame is destroyed.
|
|
1672 Normally, you cannot delete the last non-minibuffer-only frame (you must
|
|
1673 use `save-buffers-kill-emacs' or `kill-emacs'). However, if optional
|
|
1674 second argument FORCE is non-nil, you can delete the last frame. (This
|
|
1675 will automatically call `save-buffers-kill-emacs'.)
|
20
|
1676 */
|
|
1677 (window, force))
|
0
|
1678 {
|
|
1679 /* This function can GC if this is the only window in the frame */
|
|
1680 struct window *w;
|
|
1681 Lisp_Object parent;
|
|
1682 struct window *par;
|
|
1683 Lisp_Object frame;
|
|
1684 struct frame *f;
|
|
1685 struct device *d;
|
|
1686
|
|
1687 /* Note: this function is called by other C code on non-leaf
|
|
1688 windows. */
|
|
1689
|
|
1690 /* Do the equivalent of decode_window() but don't error out on
|
|
1691 deleted window; it's OK to delete an already-deleted window. */
|
|
1692 if (NILP (window))
|
|
1693 window = Fselected_window (Qnil);
|
|
1694 else
|
|
1695 CHECK_WINDOW (window);
|
|
1696 w = XWINDOW (window);
|
|
1697
|
|
1698 /* It's okay to delete an already-deleted window. */
|
|
1699 if (! WINDOW_LIVE_P (w))
|
|
1700 return Qnil;
|
|
1701
|
|
1702 frame = WINDOW_FRAME (w);
|
|
1703 f = XFRAME (frame);
|
|
1704 d = XDEVICE (FRAME_DEVICE (f));
|
|
1705
|
|
1706 if (TOP_LEVEL_WINDOW_P (w))
|
|
1707 {
|
|
1708 if (NILP (memq_no_quit (frame, DEVICE_FRAME_LIST (d))))
|
|
1709 /* this frame isn't fully initialized yet; don't blow up. */
|
|
1710 return Qnil;
|
|
1711
|
|
1712 if (MINI_WINDOW_P (XWINDOW (window)))
|
|
1713 error ("Attempt to delete the minibuffer window");
|
|
1714
|
|
1715 /* It has been suggested that it's a good thing for C-x 0 to have this
|
|
1716 behavior, but not such a good idea for #'delete-window to have it.
|
|
1717 Maybe C-x 0 should be bound to something else, or maybe frame
|
|
1718 deletion should only happen when this is called interactively.
|
|
1719 */
|
|
1720 delete_frame_internal (f, !NILP (force), 0, 0);
|
|
1721 return Qnil;
|
|
1722 }
|
|
1723
|
|
1724 /* At this point, we know the window has a parent. */
|
|
1725 parent = w->parent;
|
|
1726 par = XWINDOW (parent);
|
|
1727
|
|
1728 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
1729
|
|
1730 /* Are we trying to delete any frame's selected window?
|
|
1731 Note that we could be dealing with a non-leaf window
|
|
1732 where the selected window is one of our children.
|
|
1733 So, we check by scanning all the ancestors of the
|
|
1734 frame's selected window and comparing each one with
|
|
1735 WINDOW. */
|
|
1736 {
|
|
1737 Lisp_Object pwindow;
|
185
|
1738
|
0
|
1739 pwindow = FRAME_SELECTED_WINDOW (f);
|
185
|
1740
|
0
|
1741 while (!NILP (pwindow))
|
|
1742 {
|
|
1743 if (EQ (window, pwindow))
|
|
1744 break;
|
|
1745 pwindow = XWINDOW (pwindow)->parent;
|
|
1746 }
|
|
1747
|
|
1748 if (EQ (window, pwindow))
|
|
1749 {
|
|
1750 /* OK, we found it. */
|
|
1751 Lisp_Object alternative;
|
|
1752 alternative = Fnext_window (window, Qlambda, Qnil, Qnil);
|
185
|
1753
|
0
|
1754 /* If we're about to delete the selected window on the
|
|
1755 selected frame, then we should use Fselect_window to select
|
|
1756 the new window. On the other hand, if we're about to
|
|
1757 delete the selected window on any other frame, we shouldn't do
|
|
1758 anything but set the frame's selected_window slot. */
|
|
1759 if (EQ (frame, Fselected_frame (Qnil)))
|
|
1760 Fselect_window (alternative);
|
|
1761 else
|
|
1762 set_frame_selected_window (f, alternative);
|
|
1763 }
|
|
1764 }
|
|
1765
|
|
1766 /* w->buffer is nil in a non-leaf window; in this case,
|
|
1767 get rid of the markers we maintain that point into that buffer. */
|
|
1768 if (!NILP (w->buffer))
|
|
1769 {
|
|
1770 unshow_buffer (w);
|
|
1771 unchain_marker (w->pointm[CURRENT_DISP]);
|
|
1772 unchain_marker (w->pointm[DESIRED_DISP]);
|
|
1773 unchain_marker (w->pointm[CMOTION_DISP]);
|
|
1774 unchain_marker (w->start[CURRENT_DISP]);
|
|
1775 unchain_marker (w->start[DESIRED_DISP]);
|
|
1776 unchain_marker (w->start[CMOTION_DISP]);
|
|
1777 unchain_marker (w->sb_point);
|
|
1778 /* This breaks set-window-configuration if windows in the saved
|
|
1779 configuration get deleted and multiple frames are in use. */
|
|
1780 /* w->buffer = Qnil; */
|
|
1781 }
|
185
|
1782
|
0
|
1783 /* close up the hole in the sibling list */
|
|
1784 if (!NILP (w->next))
|
|
1785 XWINDOW (w->next)->prev = w->prev;
|
|
1786 if (!NILP (w->prev))
|
|
1787 XWINDOW (w->prev)->next = w->next;
|
|
1788 if (EQ (window, par->hchild))
|
|
1789 par->hchild = w->next;
|
|
1790 if (EQ (window, par->vchild))
|
|
1791 par->vchild = w->next;
|
|
1792
|
|
1793 /* Find one of our siblings to give our space to. */
|
|
1794 {
|
|
1795 Lisp_Object sib = w->prev;
|
|
1796 if (NILP (sib))
|
|
1797 {
|
|
1798 /* If w gives its space to its next sibling, that sibling needs
|
|
1799 to have its top/left side pulled back to where w's is.
|
|
1800 set_window_{height,width} will re-position the sibling's
|
|
1801 children. */
|
|
1802 sib = w->next;
|
|
1803 WINDOW_TOP (XWINDOW (sib)) = WINDOW_TOP (w);
|
|
1804 WINDOW_LEFT (XWINDOW (sib)) = WINDOW_LEFT (w);
|
|
1805 }
|
185
|
1806
|
0
|
1807 /* Stretch that sibling. */
|
|
1808 if (!NILP (par->vchild))
|
|
1809 set_window_pixheight
|
|
1810 (sib, (WINDOW_HEIGHT (XWINDOW (sib)) + WINDOW_HEIGHT (w)), 1);
|
|
1811 if (!NILP (par->hchild))
|
|
1812 set_window_pixwidth
|
|
1813 (sib, (WINDOW_WIDTH (XWINDOW (sib)) + WINDOW_WIDTH (w)), 1);
|
|
1814 }
|
|
1815
|
|
1816 /* If parent now has only one child,
|
|
1817 put the child into the parent's place. */
|
|
1818 {
|
|
1819 Lisp_Object parchild = par->hchild;
|
|
1820 if (NILP (parchild))
|
|
1821 parchild = par->vchild;
|
|
1822 if (NILP (XWINDOW (parchild)->next))
|
|
1823 {
|
|
1824 replace_window (parent, parchild);
|
|
1825 mark_window_as_deleted (XWINDOW (parent));
|
|
1826 }
|
|
1827 }
|
|
1828
|
|
1829 /* Since we may be deleting combination windows, we must make sure that
|
|
1830 not only W but all its children have been marked as deleted. */
|
|
1831 if (!NILP (w->hchild))
|
|
1832 delete_all_subwindows (XWINDOW (w->hchild));
|
|
1833 else if (!NILP (w->vchild))
|
|
1834 delete_all_subwindows (XWINDOW (w->vchild));
|
|
1835
|
|
1836 mark_window_as_deleted (w);
|
|
1837
|
|
1838 f->mirror_dirty = 1;
|
|
1839 return Qnil;
|
|
1840 }
|
|
1841
|
|
1842
|
20
|
1843 DEFUN ("next-window", Fnext_window, 0, 4, 0, /*
|
0
|
1844 Return next window after WINDOW in canonical ordering of windows.
|
|
1845 If omitted, WINDOW defaults to the selected window.
|
|
1846
|
|
1847 Optional second arg MINIBUF t means count the minibuffer window even
|
|
1848 if not active. MINIBUF nil or omitted means count the minibuffer iff
|
|
1849 it is active. MINIBUF neither t nor nil means not to count the
|
|
1850 minibuffer even if it is active.
|
|
1851
|
|
1852 Several frames may share a single minibuffer; if the minibuffer
|
|
1853 counts, all windows on all frames that share that minibuffer count
|
|
1854 too. Therefore, `next-window' can be used to iterate through the
|
|
1855 set of windows even when the minibuffer is on another frame. If the
|
|
1856 minibuffer does not count, only windows from WINDOW's frame count.
|
|
1857
|
|
1858 Optional third arg ALL-FRAMES t means include windows on all frames.
|
|
1859 ALL-FRAMES nil or omitted means cycle within the frames as specified
|
|
1860 above. ALL-FRAMES = `visible' means include windows on all visible frames.
|
|
1861 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
|
|
1862 If ALL-FRAMES is a frame, restrict search to windows on that frame.
|
|
1863 Anything else means restrict to WINDOW's frame.
|
|
1864
|
|
1865 Optional fourth argument CONSOLE controls which consoles or devices the
|
|
1866 returned window may be on. If CONSOLE is a console, return windows only
|
|
1867 on that console. If CONSOLE is a device, return windows only on that
|
|
1868 device. If CONSOLE is a console type, return windows only on consoles
|
|
1869 of that type. If CONSOLE is 'window-system, return any windows on any
|
|
1870 window-system consoles. If CONSOLE is nil or omitted, return windows only
|
|
1871 on WINDOW's console. Otherwise, all windows are considered.
|
|
1872
|
|
1873 If you use consistent values for MINIBUF, ALL-FRAMES, and CONSOLE, you
|
|
1874 can use `next-window' to iterate through the entire cycle of acceptable
|
|
1875 windows, eventually ending up back at the window you started with.
|
|
1876 `previous-window' traverses the same cycle, in the reverse order.
|
20
|
1877 */
|
70
|
1878 (window, minibuf, all_frames, console))
|
0
|
1879 {
|
|
1880 Lisp_Object tem;
|
|
1881 Lisp_Object start_window;
|
|
1882
|
|
1883 if (NILP (window))
|
|
1884 window = Fselected_window (Qnil);
|
|
1885 else
|
|
1886 CHECK_LIVE_WINDOW (window);
|
|
1887
|
|
1888 start_window = window;
|
|
1889
|
|
1890 /* minibuf == nil may or may not include minibuffers.
|
|
1891 Decide if it does. */
|
|
1892 if (NILP (minibuf))
|
|
1893 minibuf = (minibuf_level ? minibuf_window : Qlambda);
|
|
1894 else if (! EQ (minibuf, Qt))
|
|
1895 minibuf = Qlambda;
|
|
1896 /* Now minibuf can be t => count all minibuffer windows,
|
|
1897 lambda => count none of them,
|
|
1898 or a specific minibuffer window (the active one) to count. */
|
|
1899
|
|
1900 /* all_frames == nil doesn't specify which frames to include. */
|
|
1901 if (NILP (all_frames))
|
|
1902 all_frames = (! EQ (minibuf, Qlambda)
|
|
1903 ? (FRAME_MINIBUF_WINDOW
|
|
1904 (XFRAME
|
|
1905 (WINDOW_FRAME
|
|
1906 (XWINDOW (window)))))
|
|
1907 : Qnil);
|
|
1908 else if (EQ (all_frames, Qvisible))
|
|
1909 ;
|
|
1910 else if (ZEROP (all_frames))
|
|
1911 ;
|
|
1912 else if (FRAMEP (all_frames) && ! EQ (all_frames, Fwindow_frame (window)))
|
|
1913 /* If all_frames is a frame and window arg isn't on that frame, just
|
|
1914 return the first window on the frame. */
|
|
1915 return frame_first_window (XFRAME (all_frames));
|
|
1916 else if (! EQ (all_frames, Qt))
|
|
1917 all_frames = Qnil;
|
|
1918 /* Now all_frames is t meaning search all frames,
|
|
1919 nil meaning search just current frame,
|
|
1920 visible meaning search just visible frames,
|
|
1921 0 meaning search visible and iconified frames,
|
|
1922 or a window, meaning search the frame that window belongs to. */
|
|
1923
|
|
1924 /* Do this loop at least once, to get the next window, and perhaps
|
|
1925 again, if we hit the minibuffer and that is not acceptable. */
|
|
1926 do
|
|
1927 {
|
|
1928 /* Find a window that actually has a next one. This loop
|
|
1929 climbs up the tree. */
|
|
1930 while (tem = XWINDOW (window)->next, NILP (tem))
|
|
1931 if (tem = XWINDOW (window)->parent, !NILP (tem))
|
|
1932 window = tem;
|
|
1933 else /* window must be minibuffer window now */
|
|
1934 {
|
|
1935 /* We've reached the end of this frame.
|
|
1936 Which other frames are acceptable? */
|
|
1937 tem = WINDOW_FRAME (XWINDOW (window));
|
|
1938
|
|
1939 if (! NILP (all_frames))
|
|
1940 {
|
|
1941 Lisp_Object tem1;
|
|
1942
|
|
1943 tem1 = tem;
|
|
1944 tem = next_frame (tem, all_frames, console);
|
|
1945 /* In the case where the minibuffer is active,
|
|
1946 and we include its frame as well as the selected one,
|
|
1947 next_frame may get stuck in that frame.
|
|
1948 If that happens, go back to the selected frame
|
|
1949 so we can complete the cycle. */
|
|
1950 if (EQ (tem, tem1))
|
|
1951 XSETFRAME (tem, selected_frame ());
|
|
1952 }
|
|
1953
|
|
1954 tem = FRAME_ROOT_WINDOW (XFRAME (tem));
|
|
1955 break;
|
|
1956 }
|
|
1957
|
|
1958 window = tem;
|
|
1959
|
|
1960 /* If we're in a combination window, find its first child and
|
|
1961 recurse on that. Otherwise, we've found the window we want. */
|
|
1962 while (1)
|
|
1963 {
|
|
1964 if (!NILP (XWINDOW (window)->hchild))
|
|
1965 window = XWINDOW (window)->hchild;
|
|
1966 else if (!NILP (XWINDOW (window)->vchild))
|
|
1967 window = XWINDOW (window)->vchild;
|
|
1968 else break;
|
|
1969 }
|
|
1970 }
|
|
1971 /* "acceptable" is the correct spelling. */
|
|
1972 /* Which windows are acceptable?
|
|
1973 Exit the loop and accept this window if
|
|
1974 this isn't a minibuffer window,
|
|
1975 or we're accepting all minibuffer windows,
|
|
1976 or this is the active minibuffer and we are accepting that one, or
|
|
1977 we've come all the way around and we're back at the original window. */
|
|
1978 while (MINI_WINDOW_P (XWINDOW (window))
|
|
1979 && ! EQ (minibuf, Qt)
|
|
1980 && ! EQ (minibuf, window)
|
|
1981 && ! EQ (window, start_window));
|
|
1982
|
|
1983 return window;
|
|
1984 }
|
|
1985
|
20
|
1986 DEFUN ("previous-window", Fprevious_window, 0, 4, 0, /*
|
110
|
1987 Return the window preceding WINDOW in canonical ordering of windows.
|
0
|
1988 If omitted, WINDOW defaults to the selected window.
|
|
1989
|
|
1990 Optional second arg MINIBUF t means count the minibuffer window even
|
|
1991 if not active. MINIBUF nil or omitted means count the minibuffer iff
|
|
1992 it is active. MINIBUF neither t nor nil means not to count the
|
|
1993 minibuffer even if it is active.
|
|
1994
|
|
1995 Several frames may share a single minibuffer; if the minibuffer
|
|
1996 counts, all windows on all frames that share that minibuffer count
|
|
1997 too. Therefore, `previous-window' can be used to iterate through
|
|
1998 the set of windows even when the minibuffer is on another frame. If
|
|
1999 the minibuffer does not count, only windows from WINDOW's frame count
|
|
2000
|
|
2001 If optional third arg ALL-FRAMES t means include windows on all frames.
|
|
2002 ALL-FRAMES nil or omitted means cycle within the frames as specified
|
|
2003 above. ALL-FRAMES = `visible' means include windows on all visible frames.
|
|
2004 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
|
|
2005 If ALL-FRAMES is a frame, restrict search to windows on that frame.
|
|
2006 Anything else means restrict to WINDOW's frame.
|
|
2007
|
|
2008 Optional fourth argument CONSOLE controls which consoles or devices the
|
|
2009 returned window may be on. If CONSOLE is a console, return windows only
|
|
2010 on that console. If CONSOLE is a device, return windows only on that
|
|
2011 device. If CONSOLE is a console type, return windows only on consoles
|
|
2012 of that type. If CONSOLE is 'window-system, return any windows on any
|
|
2013 window-system consoles. If CONSOLE is nil or omitted, return windows only
|
|
2014 on WINDOW's console. Otherwise, all windows are considered.
|
|
2015
|
|
2016 If you use consistent values for MINIBUF, ALL-FRAMES, and CONSOLE, you
|
|
2017 can use `previous-window' to iterate through the entire cycle of acceptable
|
|
2018 windows, eventually ending up back at the window you started with.
|
|
2019 `next-window' traverses the same cycle, in the reverse order.
|
20
|
2020 */
|
70
|
2021 (window, minibuf, all_frames, console))
|
0
|
2022 {
|
|
2023 Lisp_Object tem;
|
|
2024 Lisp_Object start_window;
|
|
2025
|
|
2026 if (NILP (window))
|
|
2027 window = Fselected_window (Qnil);
|
|
2028 else
|
|
2029 CHECK_LIVE_WINDOW (window);
|
|
2030
|
|
2031 start_window = window;
|
|
2032
|
|
2033 /* minibuf == nil may or may not include minibuffers.
|
|
2034 Decide if it does. */
|
|
2035 if (NILP (minibuf))
|
|
2036 minibuf = (minibuf_level ? minibuf_window : Qlambda);
|
|
2037 else if (! EQ (minibuf, Qt))
|
|
2038 minibuf = Qlambda;
|
|
2039 /* Now minibuf can be t => count all minibuffer windows,
|
|
2040 lambda => count none of them,
|
|
2041 or a specific minibuffer window (the active one) to count. */
|
|
2042
|
|
2043 /* all_frames == nil doesn't specify which frames to include.
|
|
2044 Decide which frames it includes. */
|
|
2045 if (NILP (all_frames))
|
|
2046 all_frames = (! EQ (minibuf, Qlambda)
|
|
2047 ? (FRAME_MINIBUF_WINDOW
|
|
2048 (XFRAME
|
|
2049 (WINDOW_FRAME
|
|
2050 (XWINDOW (window)))))
|
|
2051 : Qnil);
|
|
2052 else if (EQ (all_frames, Qvisible))
|
|
2053 ;
|
|
2054 else if (ZEROP (all_frames))
|
|
2055 ;
|
|
2056 else if (FRAMEP (all_frames) && ! EQ (all_frames, Fwindow_frame (window)))
|
|
2057 /* If all_frames is a frame and window arg isn't on that frame, just
|
|
2058 return the first window on the frame. */
|
|
2059 return frame_first_window (XFRAME (all_frames));
|
|
2060 else if (! EQ (all_frames, Qt))
|
|
2061 all_frames = Qnil;
|
|
2062 /* Now all_frames is t meaning search all frames,
|
|
2063 nil meaning search just current frame,
|
|
2064 visible meaning search just visible frames,
|
|
2065 0 meaning search visible and iconified frames,
|
|
2066 or a window, meaning search the frame that window belongs to. */
|
|
2067
|
|
2068 /* Do this loop at least once, to get the next window, and perhaps
|
|
2069 again, if we hit the minibuffer and that is not acceptable. */
|
|
2070 do
|
|
2071 {
|
|
2072 /* Find a window that actually has a next one. This loop
|
|
2073 climbs up the tree. */
|
|
2074 while (tem = XWINDOW (window)->prev, NILP (tem))
|
|
2075 if (tem = XWINDOW (window)->parent, !NILP (tem))
|
|
2076 window = tem;
|
|
2077 else /* window must be minibuffer window now */
|
|
2078 {
|
|
2079 /* We have found the top window on the frame.
|
|
2080 Which frames are acceptable? */
|
|
2081 tem = WINDOW_FRAME (XWINDOW (window));
|
|
2082
|
|
2083 if (! NILP (all_frames))
|
|
2084 /* It's actually important that we use prev_frame here,
|
|
2085 rather than next_frame. All the windows acceptable
|
|
2086 according to the given parameters should form a ring;
|
|
2087 Fnext_window and Fprevious_window should go back and
|
|
2088 forth around the ring. If we use next_frame here,
|
|
2089 then Fnext_window and Fprevious_window take different
|
|
2090 paths through the set of acceptable windows.
|
|
2091 window_loop assumes that these `ring' requirement are
|
|
2092 met. */
|
|
2093 {
|
|
2094 Lisp_Object tem1;
|
|
2095
|
|
2096 tem1 = tem;
|
|
2097 tem = prev_frame (tem, all_frames, console);
|
|
2098 /* In the case where the minibuffer is active,
|
|
2099 and we include its frame as well as the selected one,
|
|
2100 next_frame may get stuck in that frame.
|
|
2101 If that happens, go back to the selected frame
|
|
2102 so we can complete the cycle. */
|
|
2103 if (EQ (tem, tem1))
|
|
2104 XSETFRAME (tem, selected_frame ());
|
|
2105 }
|
|
2106
|
|
2107 /* If this frame has a minibuffer, find that window first,
|
|
2108 because it is conceptually the last window in that frame. */
|
|
2109 if (FRAME_HAS_MINIBUF_P (XFRAME (tem)))
|
|
2110 tem = FRAME_MINIBUF_WINDOW (XFRAME (tem));
|
|
2111 else
|
|
2112 tem = FRAME_ROOT_WINDOW (XFRAME (tem));
|
|
2113
|
|
2114 break;
|
|
2115 }
|
|
2116
|
|
2117 window = tem;
|
|
2118
|
|
2119 /* If we're in a combination window, find its first child and
|
|
2120 recurse on that. Otherwise, we've found the window we want. */
|
|
2121 while (1)
|
|
2122 {
|
|
2123 if (!NILP (XWINDOW (window)->hchild))
|
|
2124 window = XWINDOW (window)->hchild;
|
|
2125 else if (!NILP (XWINDOW (window)->vchild))
|
|
2126 window = XWINDOW (window)->vchild;
|
|
2127 else break;
|
|
2128 while (tem = XWINDOW (window)->next, !NILP (tem))
|
|
2129 window = tem;
|
|
2130 }
|
|
2131 }
|
|
2132 /* Which windows are acceptable?
|
|
2133 Exit the loop and accept this window if
|
|
2134 this isn't a minibuffer window,
|
|
2135 or we're accepting all minibuffer windows,
|
|
2136 or this is the active minibuffer and we are accepting that one, or
|
|
2137 we've come all the way around and we're back at the original window. */
|
|
2138 while (MINI_WINDOW_P (XWINDOW (window))
|
|
2139 && ! EQ (minibuf, Qt)
|
|
2140 && ! EQ (minibuf, window)
|
|
2141 && ! EQ (window, start_window));
|
|
2142
|
|
2143 return window;
|
|
2144 }
|
|
2145
|
20
|
2146 DEFUN ("next-vertical-window", Fnext_vertical_window, 0, 1, 0, /*
|
0
|
2147 Return the next window which is vertically after WINDOW.
|
20
|
2148 */
|
|
2149 (window))
|
0
|
2150 {
|
|
2151 Lisp_Object root;
|
|
2152 struct window *w = decode_window (window);
|
|
2153 XSETWINDOW (window, w);
|
|
2154
|
|
2155 if (MINI_WINDOW_P (XWINDOW (window)))
|
|
2156 return Qnil;
|
|
2157
|
|
2158 root = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (XWINDOW (window))));
|
|
2159
|
|
2160 if (EQ (window, root))
|
|
2161 {
|
|
2162 while (1)
|
|
2163 if (!NILP (XWINDOW (window)->hchild))
|
|
2164 window = XWINDOW (window)->hchild;
|
|
2165 else if (!NILP (XWINDOW (window)->vchild))
|
|
2166 window = XWINDOW (window)->vchild;
|
|
2167 else
|
|
2168 return window;
|
|
2169 }
|
|
2170
|
|
2171 do
|
|
2172 {
|
|
2173 if (!NILP (XWINDOW (window)->parent) &&
|
|
2174 !NILP (XWINDOW (XWINDOW (window)->parent)->vchild))
|
|
2175 {
|
|
2176 if (!NILP (XWINDOW (window)->next))
|
|
2177 return XWINDOW (window)->next;
|
|
2178 else
|
|
2179 window = XWINDOW (window)->parent;
|
|
2180 }
|
|
2181 else
|
|
2182 window = XWINDOW (window)->parent;
|
|
2183 }
|
|
2184 while (!EQ (window, root));
|
|
2185
|
|
2186 while (1)
|
|
2187 if (!NILP (XWINDOW (window)->hchild))
|
|
2188 window = XWINDOW (window)->hchild;
|
|
2189 else if (!NILP (XWINDOW (window)->vchild))
|
|
2190 window = XWINDOW (window)->vchild;
|
|
2191 else
|
|
2192 return window;
|
|
2193 }
|
|
2194
|
20
|
2195 DEFUN ("other-window", Fother_window, 1, 3, "p", /*
|
0
|
2196 Select the N'th different window on this frame.
|
|
2197 All windows on current frame are arranged in a cyclic order.
|
|
2198 This command selects the window N steps away in that order.
|
|
2199 A negative N moves in the opposite order.
|
|
2200
|
|
2201 If optional argument FRAME is `visible', search all visible frames.
|
|
2202 If FRAME is 0, search all visible and iconified frames.
|
|
2203 If FRAME is t, search all frames.
|
|
2204 If FRAME is nil, search only the selected frame.
|
|
2205 If FRAME is a frame, search only that frame.
|
|
2206
|
|
2207 Optional third argument CONSOLE controls which consoles or devices the
|
|
2208 returned window may be on. If CONSOLE is a console, return windows only
|
|
2209 on that console. If CONSOLE is a device, return windows only on that
|
|
2210 device. If CONSOLE is a console type, return windows only on consoles
|
|
2211 of that type. If CONSOLE is 'window-system, return any windows on any
|
|
2212 window-system consoles. If CONSOLE is nil or omitted, return windows only
|
|
2213 on FRAME'S console, or on the selected console if FRAME is not a frame.
|
|
2214 Otherwise, all windows are considered.
|
20
|
2215 */
|
|
2216 (n, frame, console))
|
0
|
2217 {
|
|
2218 int i;
|
|
2219 Lisp_Object w;
|
|
2220
|
|
2221 CHECK_INT (n);
|
|
2222 w = Fselected_window (Qnil);
|
|
2223 i = XINT (n);
|
|
2224
|
|
2225 while (i > 0)
|
|
2226 {
|
|
2227 w = Fnext_window (w, Qnil, frame, console);
|
|
2228 i--;
|
|
2229 }
|
|
2230 while (i < 0)
|
|
2231 {
|
|
2232 w = Fprevious_window (w, Qnil, frame, console);
|
|
2233 i++;
|
|
2234 }
|
|
2235 Fselect_window (w);
|
|
2236 return Qnil;
|
|
2237 }
|
|
2238
|
|
2239
|
|
2240 /* Look at all windows, performing an operation specified by TYPE
|
|
2241 with argument OBJ.
|
|
2242
|
|
2243 If FRAMES is Qt, look at all frames, if Qnil, look at just the selected
|
|
2244 frame. If FRAMES is a frame, just look at windows on that frame.
|
|
2245 If MINI is non-zero, perform the operation on minibuffer windows too.
|
|
2246 */
|
|
2247
|
|
2248 enum window_loop
|
|
2249 {
|
|
2250 WINDOW_LOOP_UNUSED,
|
|
2251 GET_BUFFER_WINDOW, /* Arg is buffer */
|
|
2252 GET_LRU_WINDOW, /* Arg is t for full-width windows only */
|
|
2253 DELETE_OTHER_WINDOWS, /* Arg is window not to delete */
|
|
2254 DELETE_BUFFER_WINDOWS, /* Arg is buffer */
|
|
2255 GET_LARGEST_WINDOW,
|
|
2256 UNSHOW_BUFFER, /* Arg is buffer */
|
|
2257 GET_BUFFER_WINDOW_COUNT, /* Arg is buffer */
|
|
2258 GET_BUFFER_MRU_WINDOW /* Arg is buffer */
|
|
2259 };
|
|
2260
|
|
2261 static Lisp_Object
|
|
2262 window_loop (enum window_loop type,
|
185
|
2263 Lisp_Object obj,
|
0
|
2264 int mini,
|
|
2265 Lisp_Object frames,
|
|
2266 int dedicated_too,
|
|
2267 Lisp_Object console)
|
|
2268 {
|
|
2269 /* This function can GC if type == DELETE_BUFFER_WINDOWS or UNSHOW_BUFFER */
|
|
2270 Lisp_Object w;
|
|
2271 Lisp_Object best_window = Qnil;
|
|
2272 Lisp_Object next_window;
|
|
2273 Lisp_Object last_window;
|
|
2274 struct frame *frame;
|
|
2275 Lisp_Object frame_arg = Qt;
|
|
2276 int count = 0; /* for GET_BUFFER_WINDOW_COUNT */
|
|
2277 /* #### I think the change of "precomputing" last_window and next_window
|
|
2278 * #### catch the lossage this is meant(?) to punt on...
|
|
2279 */
|
185
|
2280 int lose_lose = 0;
|
0
|
2281 Lisp_Object devcons, concons;
|
|
2282
|
|
2283 /* FRAME_ARG is Qlambda to stick to one frame,
|
|
2284 Qvisible to consider all visible frames,
|
|
2285 or Qt otherwise. */
|
|
2286
|
|
2287 /* If we're only looping through windows on a particular frame,
|
|
2288 FRAME points to that frame. If we're looping through windows
|
|
2289 on all frames, FRAME is 0. */
|
|
2290
|
|
2291 if (FRAMEP (frames))
|
|
2292 frame = XFRAME (frames);
|
|
2293 else if (NILP (frames))
|
|
2294 frame = selected_frame ();
|
|
2295 else
|
|
2296 frame = 0;
|
|
2297 if (frame)
|
|
2298 frame_arg = Qlambda;
|
|
2299 else if (ZEROP (frames))
|
|
2300 frame_arg = frames;
|
|
2301 else if (EQ (frames, Qvisible))
|
|
2302 frame_arg = frames;
|
185
|
2303
|
0
|
2304 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
2305 {
|
|
2306 Lisp_Object device = XCAR (devcons);
|
|
2307 Lisp_Object the_frame = Qnil;
|
|
2308
|
|
2309 if (frame)
|
|
2310 XSETFRAME (the_frame, frame);
|
|
2311 else
|
|
2312 the_frame = DEVICE_SELECTED_FRAME (XDEVICE (device));
|
|
2313
|
|
2314 if (NILP (the_frame))
|
|
2315 continue;
|
|
2316
|
|
2317 if (!device_matches_console_spec (the_frame, device, console))
|
|
2318 continue;
|
|
2319
|
|
2320 /* Pick a window to start with. */
|
|
2321 if (WINDOWP (obj))
|
|
2322 w = obj;
|
|
2323 else
|
|
2324 w = FRAME_SELECTED_WINDOW (XFRAME (the_frame));
|
|
2325
|
|
2326 /* Figure out the last window we're going to mess with. Since
|
|
2327 Fnext_window, given the same options, is guaranteed to go in a
|
|
2328 ring, we can just use Fprevious_window to find the last one.
|
|
2329
|
|
2330 We can't just wait until we hit the first window again,
|
|
2331 because it might be deleted. */
|
|
2332
|
|
2333 last_window = Fprevious_window (w, mini ? Qt : Qnil, frame_arg, Qt);
|
|
2334
|
|
2335 best_window = Qnil;
|
|
2336 for (;;)
|
|
2337 {
|
|
2338 struct window *p = XWINDOW (w);
|
|
2339 struct frame *w_frame = XFRAME (WINDOW_FRAME (p));
|
|
2340
|
|
2341 /* Pick the next window now, since some operations will delete
|
|
2342 the current window. */
|
|
2343 next_window = Fnext_window (w, mini ? Qt : Qnil, frame_arg, Qt);
|
|
2344
|
|
2345 /* #### Still needed ?? */
|
185
|
2346 /* Given the outstanding quality of the rest of this code,
|
0
|
2347 I feel no shame about putting this piece of shit in. */
|
|
2348 if (++lose_lose >= 500)
|
|
2349 return Qnil;
|
|
2350
|
|
2351 /* Note that we do not pay attention here to whether
|
|
2352 the frame is visible, since Fnext_window skips non-visible frames
|
|
2353 if that is desired, under the control of frame_arg. */
|
|
2354 if (! MINI_WINDOW_P (p)
|
|
2355 || (mini && minibuf_level > 0))
|
|
2356 switch (type)
|
|
2357 {
|
|
2358 case GET_BUFFER_WINDOW:
|
|
2359 {
|
|
2360 if (XBUFFER (p->buffer) == XBUFFER (obj))
|
|
2361 return w;
|
|
2362 break;
|
|
2363 }
|
|
2364
|
|
2365 case GET_BUFFER_WINDOW_COUNT:
|
|
2366 {
|
|
2367 if (XBUFFER (p->buffer) == XBUFFER (obj))
|
|
2368 count++;
|
|
2369 break;
|
|
2370 }
|
|
2371
|
|
2372 case GET_LRU_WINDOW:
|
|
2373 {
|
|
2374 /* t as arg means consider only full-width windows */
|
|
2375 if (!NILP (obj)
|
|
2376 && !window_full_width_p (p))
|
|
2377 break;
|
|
2378 /* Ignore dedicated windows and minibuffers. */
|
|
2379 if (MINI_WINDOW_P (p)
|
|
2380 || (dedicated_too ? 0 : !NILP (p->dedicated)))
|
|
2381 break;
|
|
2382 if (NILP (best_window)
|
|
2383 || (XINT (XWINDOW (best_window)->use_time)
|
|
2384 > XINT (p->use_time)))
|
|
2385 best_window = w;
|
|
2386 break;
|
|
2387 }
|
|
2388
|
|
2389 case GET_BUFFER_MRU_WINDOW:
|
|
2390 {
|
|
2391 /* #### what about the first check in GET_LRU_WINDOW? */
|
|
2392 /* Ignore dedicated windows and minibuffers. */
|
|
2393 if (MINI_WINDOW_P (p)
|
|
2394 || (dedicated_too ? 0 : !NILP (p->dedicated)))
|
|
2395 break;
|
|
2396
|
|
2397 if (XBUFFER (p->buffer) == XBUFFER (obj))
|
|
2398 {
|
|
2399 if (NILP (best_window)
|
|
2400 || (XINT (XWINDOW (best_window)->use_time)
|
|
2401 < XINT (p->use_time)))
|
|
2402 best_window = w;
|
|
2403 }
|
|
2404 break;
|
|
2405 }
|
|
2406
|
|
2407 case DELETE_OTHER_WINDOWS:
|
|
2408 {
|
|
2409 /* Don't delete the last window on a frame; this can
|
|
2410 happen when the minibuffer is selected, and would
|
|
2411 cause the frame to be deleted. */
|
|
2412 if (p != XWINDOW (obj) && !TOP_LEVEL_WINDOW_P (XWINDOW (w)))
|
|
2413 Fdelete_window (w, Qnil);
|
|
2414 break;
|
|
2415 }
|
|
2416
|
|
2417 case DELETE_BUFFER_WINDOWS:
|
|
2418 {
|
|
2419 if (EQ (p->buffer, obj))
|
|
2420 {
|
|
2421 struct frame *f = XFRAME (WINDOW_FRAME (p));
|
|
2422
|
|
2423 /* If this window is dedicated, and in a frame
|
|
2424 of its own, kill the frame. */
|
|
2425 if (EQ (w, FRAME_ROOT_WINDOW (f))
|
|
2426 && !NILP (p->dedicated)
|
|
2427 && other_visible_frames (f))
|
|
2428 {
|
|
2429 /* Skip the other windows on this frame.
|
|
2430 There might be one, the minibuffer! */
|
|
2431 if (! EQ (w, last_window))
|
|
2432 while (f == XFRAME (WINDOW_FRAME
|
|
2433 (XWINDOW (next_window))))
|
|
2434 {
|
|
2435 /* As we go, check for the end of the
|
|
2436 loop. We mustn't start going
|
|
2437 around a second time. */
|
|
2438 if (EQ (next_window, last_window))
|
|
2439 {
|
|
2440 last_window = w;
|
|
2441 break;
|
|
2442 }
|
|
2443 next_window = Fnext_window (next_window,
|
|
2444 mini ? Qt : Qnil,
|
|
2445 frame_arg, Qt);
|
|
2446 }
|
|
2447 /* Now we can safely delete the frame. */
|
|
2448 Fdelete_frame (WINDOW_FRAME (p), Qnil);
|
|
2449 }
|
|
2450 else
|
|
2451 /* If we're deleting the buffer displayed in
|
|
2452 the only window on the frame, find a new
|
|
2453 buffer to display there. */
|
|
2454 if (NILP (p->parent))
|
|
2455 {
|
|
2456 Lisp_Object new_buffer;
|
|
2457 new_buffer = Fother_buffer (obj, Qnil, Qnil);
|
|
2458 if (NILP (new_buffer))
|
|
2459 new_buffer = Fget_buffer_create (QSscratch);
|
|
2460 Fset_window_buffer (w, new_buffer);
|
|
2461 if (EQ (w, Fselected_window (Qnil)))
|
|
2462 Fset_buffer (p->buffer);
|
|
2463 }
|
|
2464 else
|
|
2465 Fdelete_window (w, Qnil);
|
|
2466 }
|
|
2467 break;
|
|
2468 }
|
|
2469
|
|
2470 case GET_LARGEST_WINDOW:
|
|
2471 {
|
|
2472 /* Ignore dedicated windows and minibuffers. */
|
|
2473 if (MINI_WINDOW_P (p)
|
|
2474 || (dedicated_too ? 0 : !NILP (p->dedicated)))
|
|
2475 break;
|
|
2476 {
|
|
2477 /* write the check as follows to avoid tripping
|
|
2478 error_check_window() --ben */
|
|
2479 struct window *b = NILP (best_window) ? 0 :
|
|
2480 XWINDOW (best_window);
|
|
2481 if (NILP (best_window)
|
|
2482 || ((WINDOW_HEIGHT (p) * WINDOW_WIDTH (p))
|
|
2483 > (WINDOW_HEIGHT (b) * WINDOW_WIDTH (b))))
|
|
2484 best_window = w;
|
|
2485 }
|
|
2486 break;
|
|
2487 }
|
|
2488
|
|
2489 case UNSHOW_BUFFER:
|
|
2490 {
|
|
2491 if (EQ (p->buffer, obj))
|
|
2492 {
|
|
2493 /* Find another buffer to show in this window. */
|
|
2494 Lisp_Object another_buffer =
|
|
2495 Fother_buffer (obj, Qnil, Qnil);
|
|
2496 if (NILP (another_buffer))
|
|
2497 another_buffer
|
|
2498 = Fget_buffer_create (QSscratch);
|
|
2499 /* If this window is dedicated, and in a frame
|
|
2500 of its own, kill the frame. */
|
|
2501 if (EQ (w, FRAME_ROOT_WINDOW (w_frame))
|
|
2502 && !NILP (p->dedicated)
|
|
2503 && other_visible_frames (w_frame))
|
|
2504 {
|
|
2505 /* Skip the other windows on this frame.
|
|
2506 There might be one, the minibuffer! */
|
|
2507 if (! EQ (w, last_window))
|
|
2508 while (w_frame == XFRAME (WINDOW_FRAME
|
|
2509 (XWINDOW (next_window))))
|
|
2510 {
|
|
2511 /* As we go, check for the end of the
|
|
2512 loop. We mustn't start going
|
|
2513 around a second time. */
|
|
2514 if (EQ (next_window, last_window))
|
|
2515 {
|
|
2516 last_window = w;
|
|
2517 break;
|
|
2518 }
|
|
2519 next_window = Fnext_window (next_window,
|
|
2520 mini ? Qt : Qnil,
|
|
2521 frame_arg, Qt);
|
|
2522 }
|
|
2523 /* Now we can safely delete the frame. */
|
|
2524 delete_frame_internal (XFRAME (WINDOW_FRAME (p)),
|
|
2525 0, 0, 0);
|
|
2526 }
|
|
2527 else
|
|
2528 {
|
|
2529 /* Otherwise show a different buffer in the
|
|
2530 window. */
|
|
2531 p->dedicated = Qnil;
|
|
2532 Fset_window_buffer (w, another_buffer);
|
|
2533 if (EQ (w, Fselected_window (Qnil)))
|
|
2534 Fset_buffer (p->buffer);
|
|
2535 }
|
|
2536 }
|
|
2537 break;
|
|
2538 }
|
|
2539
|
185
|
2540 default:
|
0
|
2541 abort ();
|
|
2542 }
|
|
2543
|
|
2544 if (EQ (w, last_window))
|
|
2545 break;
|
|
2546
|
|
2547 w = next_window;
|
|
2548 }
|
|
2549 }
|
|
2550
|
173
|
2551 return type == GET_BUFFER_WINDOW_COUNT ? make_int (count) : best_window;
|
0
|
2552 }
|
|
2553
|
|
2554 #if 0 /* not currently used */
|
|
2555
|
|
2556 int
|
|
2557 buffer_window_count (struct buffer *b, struct frame *f)
|
|
2558 {
|
|
2559 Lisp_Object buffer, frame;
|
|
2560
|
|
2561 XSETFRAME (frame, f);
|
|
2562 XSETBUFFER (buffer, b);
|
|
2563
|
|
2564 return XINT (window_loop (GET_BUFFER_WINDOW_COUNT, buffer, 0, frame, 1,
|
|
2565 Qnil));
|
|
2566 }
|
|
2567
|
|
2568 int
|
|
2569 buffer_window_mru (struct window *w)
|
|
2570 {
|
185
|
2571 Lisp_Object window =
|
0
|
2572 window_loop (GET_BUFFER_MRU_WINDOW, w->buffer, 0, w->frame, 1, Qnil);
|
|
2573
|
|
2574 if (NILP (window))
|
|
2575 return 0;
|
|
2576 else if (XWINDOW (window) == w)
|
|
2577 return 1;
|
|
2578 else
|
|
2579 return 0;
|
|
2580 }
|
|
2581
|
|
2582 #endif
|
|
2583
|
|
2584
|
20
|
2585 DEFUN ("get-lru-window", Fget_lru_window, 0, 2, 0, /*
|
0
|
2586 Return the window least recently selected or used for display.
|
|
2587 If optional argument FRAME is `visible', search all visible frames.
|
|
2588 If FRAME is 0, search all visible and iconified frames.
|
|
2589 If FRAME is t, search all frames.
|
|
2590 If FRAME is nil, search only the selected frame.
|
|
2591 If FRAME is a frame, search only that frame.
|
|
2592
|
|
2593 Optional second argument CONSOLE controls which consoles or devices the
|
|
2594 returned window may be on. If CONSOLE is a console, return windows only
|
|
2595 on that console. If CONSOLE is a device, return windows only on that
|
|
2596 device. If CONSOLE is a console type, return windows only on consoles
|
|
2597 of that type. If CONSOLE is 'window-system, return any windows on any
|
|
2598 window-system consoles. If CONSOLE is nil or omitted, return windows only
|
|
2599 on FRAME'S console, or on the selected console if FRAME is not a frame.
|
|
2600 Otherwise, all windows are considered.
|
20
|
2601 */
|
|
2602 (frame, console))
|
0
|
2603 {
|
|
2604 Lisp_Object w;
|
|
2605 /* First try for a non-dedicated window that is full-width */
|
|
2606 w = window_loop (GET_LRU_WINDOW, Qt, 0, frame, 0, console);
|
|
2607 if (!NILP (w) && !EQ (w, Fselected_window (Qnil)))
|
|
2608 return w;
|
|
2609
|
|
2610 /* Then try for any non-dedicated window */
|
|
2611 w = window_loop (GET_LRU_WINDOW, Qnil, 0, frame, 0, console);
|
|
2612 if (!NILP (w) && !EQ (w, Fselected_window (Qnil)))
|
|
2613 return w;
|
|
2614
|
|
2615 #if 0
|
|
2616 /* FSFmacs never returns a dedicated window here. If we do,
|
|
2617 it makes `display-buffer' not work right. #### All of this
|
|
2618 shit is so disgusting and awful that it needs to be rethought
|
|
2619 from scratch. */
|
|
2620 /* then try for a dedicated window that is full-width */
|
|
2621 w = window_loop (GET_LRU_WINDOW, Qt, 0, frame, 1, console);
|
|
2622 if (!NILP (w) && !EQ (w, Fselected_window (Qnil)))
|
|
2623 return w;
|
|
2624
|
|
2625 /* If none of them, then all windows, dedicated or not. */
|
|
2626 w = window_loop (GET_LRU_WINDOW, Qnil, 0, frame, 1, console);
|
|
2627
|
|
2628 /* At this point we damn well better have found something. */
|
|
2629 if (NILP (w)) abort ();
|
|
2630 #endif
|
|
2631
|
173
|
2632 return w;
|
0
|
2633 }
|
|
2634
|
20
|
2635 DEFUN ("get-largest-window", Fget_largest_window, 0, 2, 0, /*
|
0
|
2636 Return the window largest in area.
|
|
2637 If optional argument FRAME is `visible', search all visible frames.
|
|
2638 If FRAME is 0, search all visible and iconified frames.
|
|
2639 If FRAME is t, search all frames.
|
|
2640 If FRAME is nil, search only the selected frame.
|
|
2641 If FRAME is a frame, search only that frame.
|
|
2642
|
|
2643 Optional second argument CONSOLE controls which consoles or devices the
|
|
2644 returned window may be on. If CONSOLE is a console, return windows only
|
|
2645 on that console. If CONSOLE is a device, return windows only on that
|
|
2646 device. If CONSOLE is a console type, return windows only on consoles
|
|
2647 of that type. If CONSOLE is 'window-system, return any windows on any
|
|
2648 window-system consoles. If CONSOLE is nil or omitted, return windows only
|
|
2649 on FRAME'S console, or on the selected console if FRAME is not a frame.
|
|
2650 Otherwise, all windows are considered.
|
20
|
2651 */
|
|
2652 (frame, console))
|
0
|
2653 {
|
|
2654 /* Don't search dedicated windows because FSFmacs doesn't.
|
|
2655 This stuff is all black magic so don't try to apply common
|
|
2656 sense to it. */
|
|
2657 return window_loop (GET_LARGEST_WINDOW, Qnil, 0, frame, 0, console);
|
|
2658 }
|
|
2659
|
20
|
2660 DEFUN ("get-buffer-window", Fget_buffer_window, 1, 3, 0, /*
|
0
|
2661 Return a window currently displaying BUFFER, or nil if none.
|
|
2662 If optional argument FRAME is `visible', search all visible frames.
|
|
2663 If optional argument FRAME is 0, search all visible and iconified frames.
|
|
2664 If FRAME is t, search all frames.
|
|
2665 If FRAME is nil, search only the selected frame.
|
|
2666 If FRAME is a frame, search only that frame.
|
|
2667
|
|
2668 Optional third argument CONSOLE controls which consoles or devices the
|
|
2669 returned window may be on. If CONSOLE is a console, return windows only
|
|
2670 on that console. If CONSOLE is a device, return windows only on that
|
|
2671 device. If CONSOLE is a console type, return windows only on consoles
|
|
2672 of that type. If CONSOLE is 'window-system, return any windows on any
|
|
2673 window-system consoles. If CONSOLE is nil or omitted, return windows only
|
|
2674 on FRAME'S console, or on the selected console if FRAME is not a frame.
|
|
2675 Otherwise, all windows are considered.
|
20
|
2676 */
|
|
2677 (buffer, frame, console))
|
0
|
2678 {
|
|
2679 buffer = Fget_buffer (buffer);
|
|
2680 if (BUFFERP (buffer))
|
|
2681 /* Search dedicated windows too. (Doesn't matter here anyway.) */
|
|
2682 return window_loop (GET_BUFFER_WINDOW, buffer, 1, frame, 1, console);
|
|
2683 else
|
|
2684 return Qnil;
|
|
2685 }
|
|
2686
|
|
2687 /* These functions used to be `buffer-left-margin-pixel-width', etc.
|
|
2688 but there is no sensible way to implement those functions, since
|
|
2689 you can't in general derive a window from a buffer. */
|
|
2690
|
20
|
2691 DEFUN ("window-left-margin-pixel-width",
|
|
2692 Fwindow_left_margin_pixel_width, 0, 1, 0, /*
|
0
|
2693 Return the width in pixels of the left outside margin of window WINDOW.
|
|
2694 If WINDOW is nil, the selected window is assumed.
|
20
|
2695 */
|
|
2696 (window))
|
0
|
2697 {
|
149
|
2698 return make_int (window_left_margin_width (decode_window (window)));
|
0
|
2699 }
|
|
2700
|
20
|
2701 DEFUN ("window-right-margin-pixel-width",
|
|
2702 Fwindow_right_margin_pixel_width, 0, 1, 0, /*
|
0
|
2703 Return the width in pixels of the right outside margin of window WINDOW.
|
|
2704 If WINDOW is nil, the selected window is assumed.
|
20
|
2705 */
|
|
2706 (window))
|
0
|
2707 {
|
149
|
2708 return make_int (window_right_margin_width (decode_window (window)));
|
0
|
2709 }
|
|
2710
|
20
|
2711 DEFUN ("delete-other-windows", Fdelete_other_windows, 0, 1, "", /*
|
0
|
2712 Make WINDOW (or the selected window) fill its frame.
|
|
2713 Only the frame WINDOW is on is affected.
|
|
2714 This function tries to reduce display jumps
|
|
2715 by keeping the text previously visible in WINDOW
|
|
2716 in the same place on the frame. Doing this depends on
|
|
2717 the value of (window-start WINDOW), so if calling this function
|
|
2718 in a program gives strange scrolling, make sure the window-start
|
|
2719 value is reasonable when this function is called.
|
20
|
2720 */
|
|
2721 (window))
|
0
|
2722 {
|
|
2723 struct window *w = decode_window (window);
|
|
2724 struct buffer *b = XBUFFER (w->buffer);
|
|
2725 Bufpos start_pos;
|
|
2726 int old_top = WINDOW_TOP (w);
|
|
2727
|
|
2728 XSETWINDOW (window, w);
|
|
2729
|
|
2730 if (MINI_WINDOW_P (w) && old_top > 0)
|
|
2731 error ("Can't expand minibuffer to full frame");
|
|
2732
|
|
2733 /* Ignore dedicated windows. */
|
|
2734 window_loop (DELETE_OTHER_WINDOWS, window, 0, w->frame, 0, Qnil);
|
|
2735
|
|
2736 start_pos = marker_position (w->start[CURRENT_DISP]);
|
|
2737
|
|
2738 /* Try to minimize scrolling, by setting the window start to the
|
|
2739 point which will cause the text at the old window start to be at
|
|
2740 the same place on the frame. But don't try to do this if the
|
|
2741 window start is outside the visible portion (as might happen when
|
|
2742 the display is not current, due to typeahead). */
|
|
2743 if (start_pos >= BUF_BEGV (b) && start_pos <= BUF_ZV (b)
|
|
2744 && !MINI_WINDOW_P (w))
|
|
2745 {
|
|
2746 Bufpos new_start = start_with_line_at_pixpos (w, start_pos, old_top);
|
|
2747
|
|
2748 if (new_start >= BUF_BEGV (b) && new_start <= BUF_ZV (b))
|
|
2749 {
|
|
2750 Fset_marker (w->start[CURRENT_DISP], make_int (new_start),
|
|
2751 w->buffer);
|
|
2752 w->start_at_line_beg = beginning_of_line_p (b, new_start);
|
|
2753 }
|
|
2754 /* We need to do this, so that the window-scroll-functions
|
|
2755 get called. */
|
|
2756 w->force_start = 1;
|
|
2757 }
|
|
2758
|
|
2759 return Qnil;
|
|
2760 }
|
|
2761
|
20
|
2762 DEFUN ("delete-windows-on", Fdelete_windows_on, 1, 3,
|
|
2763 "bDelete windows on (buffer): ", /*
|
0
|
2764 Delete all windows showing BUFFER.
|
|
2765 Optional second argument FRAME controls which frames are affected.
|
|
2766 If nil or omitted, delete all windows showing BUFFER in any frame.
|
|
2767 If t, delete only windows showing BUFFER in the selected frame.
|
|
2768 If `visible', delete all windows showing BUFFER in any visible frame.
|
|
2769 If a frame, delete only windows showing BUFFER in that frame.
|
|
2770
|
|
2771 Optional third argument CONSOLE controls which consoles or devices the
|
|
2772 returned window may be on. If CONSOLE is a console, return windows only
|
|
2773 on that console. If CONSOLE is a device, return windows only on that
|
|
2774 device. If CONSOLE is a console type, return windows only on consoles
|
|
2775 of that type. If CONSOLE is 'window-system, return any windows on any
|
|
2776 window-system consoles. If CONSOLE is nil or omitted, return windows only
|
|
2777 on FRAME'S console, or on the selected console if FRAME is not a frame.
|
|
2778 Otherwise, all windows are considered.
|
20
|
2779 */
|
|
2780 (buffer, frame, console))
|
0
|
2781 {
|
|
2782 /* This function can GC */
|
|
2783 /* FRAME uses t and nil to mean the opposite of what window_loop
|
|
2784 expects. */
|
|
2785 if (!FRAMEP (frame))
|
|
2786 frame = NILP (frame) ? Qt : Qnil;
|
|
2787
|
|
2788 if (!NILP (buffer))
|
|
2789 {
|
|
2790 buffer = Fget_buffer (buffer);
|
|
2791 CHECK_BUFFER (buffer);
|
|
2792 /* Ignore dedicated windows. */
|
|
2793 window_loop (DELETE_BUFFER_WINDOWS, buffer, 0, frame, 0, console);
|
|
2794 }
|
|
2795 return Qnil;
|
|
2796 }
|
|
2797
|
20
|
2798 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows, 1, 1,
|
|
2799 "bReplace buffer in windows: ", /*
|
0
|
2800 Replace BUFFER with some other buffer in all windows showing it.
|
20
|
2801 */
|
|
2802 (buffer))
|
0
|
2803 {
|
|
2804 /* This function can GC */
|
|
2805 if (!NILP (buffer))
|
|
2806 {
|
|
2807 buffer = Fget_buffer (buffer);
|
|
2808 CHECK_BUFFER (buffer);
|
|
2809 /* Ignore dedicated windows. */
|
|
2810 window_loop (UNSHOW_BUFFER, buffer, 0, Qt, 0, Qnil);
|
|
2811 }
|
|
2812 return Qnil;
|
|
2813 }
|
|
2814
|
|
2815 /* The smallest acceptable dimensions for a window. Anything smaller
|
|
2816 might crash Emacs. */
|
|
2817 #define MIN_SAFE_WINDOW_WIDTH (2)
|
|
2818 #define MIN_SAFE_WINDOW_HEIGHT (2)
|
|
2819
|
|
2820 /* Make sure that window_min_height and window_min_width are
|
|
2821 not too small; if they are, set them to safe minima. */
|
|
2822
|
|
2823 static void
|
|
2824 check_min_window_sizes (void)
|
|
2825 {
|
|
2826 /* Smaller values might permit a crash. */
|
|
2827 if (window_min_width < MIN_SAFE_WINDOW_WIDTH)
|
|
2828 window_min_width = MIN_SAFE_WINDOW_WIDTH;
|
|
2829 if (window_min_height < MIN_SAFE_WINDOW_HEIGHT)
|
|
2830 window_min_height = MIN_SAFE_WINDOW_HEIGHT;
|
|
2831 }
|
|
2832
|
|
2833 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
|
|
2834 minimum allowable size. */
|
|
2835 void
|
|
2836 check_frame_size (struct frame *frame, int *rows, int *cols)
|
|
2837 {
|
|
2838 /* For height, we have to see whether the frame has a minibuffer, and
|
|
2839 whether it wants a modeline. */
|
|
2840 int min_height =
|
|
2841 (FRAME_MINIBUF_ONLY_P (frame) ? MIN_SAFE_WINDOW_HEIGHT - 1
|
|
2842 : (! FRAME_HAS_MINIBUF_P (frame)) ? MIN_SAFE_WINDOW_HEIGHT
|
|
2843 : 2 * MIN_SAFE_WINDOW_HEIGHT - 1);
|
|
2844
|
|
2845 if (*rows < min_height)
|
|
2846 *rows = min_height;
|
|
2847 if (*cols < MIN_SAFE_WINDOW_WIDTH)
|
|
2848 *cols = MIN_SAFE_WINDOW_WIDTH;
|
|
2849 }
|
|
2850
|
|
2851 /* Normally the window is deleted if it gets too small.
|
|
2852 nodelete nonzero means do not do this.
|
|
2853 (The caller should check later and do so if appropriate) */
|
|
2854 static void
|
|
2855 set_window_pixsize (Lisp_Object window, int new_pixsize, int nodelete,
|
|
2856 int set_height)
|
|
2857 {
|
|
2858 struct window *w = XWINDOW (window);
|
|
2859 struct frame *f = XFRAME (w->frame);
|
|
2860 struct window *c;
|
|
2861 int old_pixsize = (set_height ? WINDOW_HEIGHT (w) : WINDOW_WIDTH (w));
|
|
2862 Lisp_Object child, minor_kid, major_kid;
|
|
2863 int minsize;
|
|
2864 int line_size;
|
|
2865 int defheight, defwidth;
|
|
2866
|
|
2867 /* #### This is very likely incorrect and instead the char_to_pixel_
|
|
2868 functions should be called. */
|
|
2869 default_face_height_and_width (window, &defheight, &defwidth);
|
|
2870 line_size = (set_height ? defheight : defwidth);
|
|
2871
|
|
2872 minsize = (set_height ? window_min_height : window_min_width);
|
|
2873 minsize *= line_size;
|
|
2874
|
|
2875 check_min_window_sizes ();
|
|
2876
|
|
2877 if (!nodelete
|
|
2878 && !TOP_LEVEL_WINDOW_P (w)
|
|
2879 && new_pixsize < minsize)
|
|
2880 {
|
|
2881 Fdelete_window (window, Qnil);
|
|
2882 return;
|
|
2883 }
|
|
2884
|
|
2885 SET_LAST_MODIFIED (w, 0);
|
|
2886 SET_LAST_FACECHANGE (w);
|
|
2887 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f); /* multiple windows affected */
|
|
2888 if (set_height)
|
|
2889 {
|
|
2890 WINDOW_HEIGHT (w) = new_pixsize;
|
|
2891 major_kid = w->vchild;
|
|
2892 minor_kid = w->hchild;
|
|
2893 }
|
|
2894 else
|
|
2895 {
|
|
2896 WINDOW_WIDTH (w) = new_pixsize;
|
|
2897 major_kid = w->hchild;
|
|
2898 minor_kid = w->vchild;
|
|
2899 }
|
|
2900
|
|
2901 if (!NILP (minor_kid))
|
|
2902 {
|
|
2903 for (child = minor_kid; !NILP (child); child = XWINDOW (child)->next)
|
|
2904 {
|
|
2905 if (set_height)
|
|
2906 WINDOW_TOP (XWINDOW (child)) = WINDOW_TOP (w);
|
|
2907 else
|
|
2908 WINDOW_LEFT (XWINDOW (child)) = WINDOW_LEFT (w);
|
|
2909
|
|
2910 set_window_pixsize (child, new_pixsize, nodelete, set_height);
|
|
2911 }
|
|
2912 }
|
|
2913 else if (!NILP (major_kid))
|
|
2914 {
|
|
2915 int last_pos, last_old_pos, pos, old_pos, first;
|
215
|
2916 int pixel_adj_left = new_pixsize - old_pixsize;
|
0
|
2917 int div_val = old_pixsize << 1;
|
|
2918
|
209
|
2919 /*
|
|
2920 * Previously we bailed out here if there was no size change.
|
215
|
2921 * (pixel_adj_left == 0) But this broke toolbar updates. If a
|
|
2922 * toolbar appears or disappears, windows may not change size,
|
|
2923 * but their top and left coordinates need to be updated.
|
209
|
2924 *
|
215
|
2925 * So we don't bail until after the loop below.
|
209
|
2926 */
|
0
|
2927
|
|
2928 last_pos = first = (set_height ? WINDOW_TOP (w) : WINDOW_LEFT (w));
|
|
2929 last_old_pos = 0;
|
|
2930
|
|
2931 for (child = major_kid; !NILP (child); child = c->next)
|
|
2932 {
|
|
2933 c = XWINDOW (child);
|
|
2934
|
|
2935 if (set_height)
|
|
2936 {
|
|
2937 old_pos = last_old_pos + WINDOW_HEIGHT (c);
|
|
2938 WINDOW_TOP (c) = last_pos;
|
|
2939 }
|
|
2940 else
|
|
2941 {
|
|
2942 old_pos = last_old_pos + WINDOW_WIDTH (c);
|
|
2943 WINDOW_LEFT (c) = last_pos;
|
|
2944 }
|
|
2945
|
|
2946 pos = (((old_pos * new_pixsize) << 1) + old_pixsize) / div_val;
|
2
|
2947 /* All but the last window should have a height which is
|
0
|
2948 a multiple of the default line height. */
|
|
2949 if (!NILP (c->next))
|
|
2950 pos = (pos / line_size) * line_size;
|
|
2951
|
|
2952 /* Avoid confusion: don't delete child if it becomes too small */
|
|
2953 set_window_pixsize (child, pos + first - last_pos, 1, set_height);
|
|
2954
|
|
2955 last_pos = pos + first;
|
|
2956 last_old_pos = old_pos;
|
|
2957 }
|
|
2958
|
215
|
2959 /* Sometimes we may get called with our old size. In that case
|
|
2960 we don't need to do anything else. */
|
|
2961 if (!pixel_adj_left)
|
|
2962 return;
|
|
2963
|
0
|
2964 /* Now delete any children that became too small. */
|
|
2965 if (!nodelete)
|
|
2966 for (child = major_kid; !NILP (child); child = XWINDOW (child)->next)
|
|
2967 {
|
|
2968 if (set_height)
|
|
2969 set_window_pixheight (child, WINDOW_HEIGHT (XWINDOW (child)), 0);
|
|
2970 else
|
|
2971 set_window_pixwidth (child, WINDOW_WIDTH (XWINDOW (child)), 0);
|
|
2972 }
|
|
2973 }
|
|
2974 }
|
|
2975
|
|
2976 /* Set the height of WINDOW and all its inferiors. */
|
|
2977 void
|
|
2978 set_window_pixheight (Lisp_Object window, int new_pixheight, int nodelete)
|
|
2979 {
|
|
2980 set_window_pixsize (window, new_pixheight, nodelete, 1);
|
|
2981 }
|
|
2982
|
|
2983 /* Recursively set width of WINDOW and its inferiors. */
|
|
2984 void
|
|
2985 set_window_pixwidth (Lisp_Object window, int new_pixwidth, int nodelete)
|
|
2986 {
|
|
2987 set_window_pixsize (window, new_pixwidth, nodelete, 0);
|
|
2988 }
|
|
2989
|
|
2990
|
|
2991 static int window_select_count;
|
|
2992
|
20
|
2993 DEFUN ("set-window-buffer", Fset_window_buffer, 2, 2, 0, /*
|
0
|
2994 Make WINDOW display BUFFER as its contents.
|
|
2995 BUFFER can be a buffer or buffer name.
|
20
|
2996 */
|
|
2997 (window, buffer))
|
0
|
2998 {
|
|
2999 Lisp_Object tem;
|
|
3000 struct window *w = decode_window (window);
|
|
3001
|
|
3002 buffer = Fget_buffer (buffer);
|
|
3003 CHECK_BUFFER (buffer);
|
|
3004
|
|
3005 if (!BUFFER_LIVE_P (XBUFFER (buffer)))
|
|
3006 error ("Attempt to display deleted buffer");
|
|
3007
|
|
3008 tem = w->buffer;
|
|
3009 if (NILP (tem))
|
|
3010 error ("Window is deleted");
|
|
3011
|
|
3012 /* While this seems like a logical thing to do, it causes problems
|
|
3013 because of saved window configurations. It is possible for a
|
|
3014 buffer to get restored into a window in which it is already being
|
|
3015 displayed, but start and point are actually at completely
|
|
3016 different locations. So we let this function complete fully and
|
|
3017 it will then make sure redisplay correctly updates things.
|
|
3018
|
|
3019 #### This is a kludge. The correct approach is not to do this
|
|
3020 but to fix set-window-configuration. */
|
|
3021 #if 0
|
|
3022 else if (EQ (tem, buffer))
|
149
|
3023 return Qnil;
|
0
|
3024 #endif
|
|
3025 else if (! EQ (tem, Qt)) /* w->buffer is t when the window
|
|
3026 is first being set up. */
|
|
3027 {
|
|
3028 if (!NILP (w->dedicated) && !EQ (tem, buffer))
|
|
3029 error ("Window is dedicated to buffer %s",
|
16
|
3030 XSTRING_DATA (XBUFFER (tem)->name));
|
0
|
3031
|
|
3032 unshow_buffer (w);
|
|
3033 }
|
|
3034
|
|
3035 w->buffer = buffer;
|
|
3036 w->window_end_pos[CURRENT_DISP] = 0;
|
|
3037 w->hscroll = 0;;
|
|
3038 Fset_marker (w->pointm[CURRENT_DISP],
|
|
3039 make_int (BUF_PT (XBUFFER (buffer))),
|
|
3040 buffer);
|
|
3041 set_marker_restricted (w->start[CURRENT_DISP],
|
|
3042 make_int (XBUFFER (buffer)->last_window_start),
|
|
3043 buffer);
|
|
3044 Fset_marker (w->sb_point, w->start[CURRENT_DISP], buffer);
|
|
3045 w->start_at_line_beg = 0;
|
|
3046 w->force_start = 0; /* Lucid fix */
|
|
3047 SET_LAST_MODIFIED (w, 1);
|
|
3048 SET_LAST_FACECHANGE (w);
|
|
3049 MARK_WINDOWS_CHANGED (w);
|
|
3050 recompute_all_cached_specifiers_in_window (w);
|
|
3051 if (EQ (window, Fselected_window (Qnil)))
|
|
3052 {
|
|
3053 Fset_buffer (buffer);
|
|
3054 }
|
|
3055 return Qnil;
|
|
3056 }
|
|
3057
|
20
|
3058 DEFUN ("select-window", Fselect_window, 1, 1, 0, /*
|
0
|
3059 Select WINDOW. Most editing will apply to WINDOW's buffer.
|
|
3060 The main editor command loop selects the buffer of the selected window
|
|
3061 before each command.
|
20
|
3062 */
|
|
3063 (window))
|
0
|
3064 {
|
|
3065 struct window *w;
|
|
3066 Lisp_Object old_selected_window = Fselected_window (Qnil);
|
185
|
3067
|
0
|
3068 CHECK_LIVE_WINDOW (window);
|
|
3069 w = XWINDOW (window);
|
|
3070
|
|
3071 /* we have already caught dead-window errors */
|
|
3072 if (!NILP (w->hchild) || !NILP (w->vchild))
|
|
3073 error ("Trying to select non-leaf window");
|
|
3074
|
|
3075 w->use_time = make_int (++window_select_count);
|
|
3076 if (EQ (window, old_selected_window))
|
|
3077 return window;
|
|
3078
|
|
3079 /* deselect the old window, if it exists (it might not exist if
|
|
3080 the selected device has no frames, which occurs at startup) */
|
|
3081 if (!NILP (old_selected_window))
|
|
3082 {
|
|
3083 struct window *ow = XWINDOW (old_selected_window);
|
|
3084
|
|
3085 Fset_marker (ow->pointm[CURRENT_DISP],
|
|
3086 make_int (BUF_PT (XBUFFER (ow->buffer))),
|
|
3087 ow->buffer);
|
|
3088
|
|
3089 MARK_WINDOWS_CHANGED (ow);
|
|
3090 }
|
|
3091
|
|
3092 /* now select the window's frame */
|
|
3093 set_frame_selected_window (XFRAME (WINDOW_FRAME (w)), window);
|
185
|
3094
|
0
|
3095 select_frame_1 (WINDOW_FRAME (w));
|
|
3096
|
|
3097 /* also select the window's buffer */
|
|
3098 Frecord_buffer (w->buffer);
|
|
3099 Fset_buffer (w->buffer);
|
|
3100
|
|
3101 /* Go to the point recorded in the window.
|
|
3102 This is important when the buffer is in more
|
|
3103 than one window. It also matters when
|
|
3104 redisplay_window has altered point after scrolling,
|
|
3105 because it makes the change only in the window. */
|
|
3106 {
|
|
3107 Bufpos new_point = marker_position (w->pointm[CURRENT_DISP]);
|
|
3108 if (new_point < BUF_BEGV (current_buffer))
|
|
3109 new_point = BUF_BEGV (current_buffer);
|
|
3110 else if (new_point > BUF_ZV (current_buffer))
|
|
3111 new_point = BUF_ZV (current_buffer);
|
|
3112
|
|
3113 BUF_SET_PT (current_buffer, new_point);
|
|
3114 }
|
|
3115
|
|
3116 MARK_WINDOWS_CHANGED (w);
|
|
3117
|
|
3118 return window;
|
|
3119 }
|
|
3120
|
|
3121 Lisp_Object
|
|
3122 display_buffer (Lisp_Object buffer, Lisp_Object not_this_window_p,
|
|
3123 Lisp_Object override_frame)
|
|
3124 {
|
|
3125 return call3 (Qdisplay_buffer, buffer, not_this_window_p, override_frame);
|
|
3126 }
|
|
3127
|
|
3128 void
|
|
3129 temp_output_buffer_show (Lisp_Object buf, Lisp_Object same_frame)
|
|
3130 {
|
|
3131 /* This function can GC */
|
|
3132 Lisp_Object window;
|
|
3133 struct window *w;
|
|
3134 struct buffer *b = XBUFFER (buf);
|
|
3135
|
|
3136 BUF_SAVE_MODIFF (XBUFFER (buf)) = BUF_MODIFF (b);
|
|
3137 widen_buffer (b, 0);
|
|
3138 BUF_SET_PT (b, BUF_BEG (b));
|
|
3139
|
|
3140 if (!EQ (Vtemp_buffer_show_function, Qnil))
|
|
3141 call1 (Vtemp_buffer_show_function, buf);
|
|
3142 else
|
|
3143 {
|
|
3144 window = display_buffer (buf, Qnil, same_frame);
|
|
3145
|
|
3146 if (!EQ (XWINDOW (window)->frame, Fselected_frame (Qnil)))
|
|
3147 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
|
|
3148
|
|
3149 Vminibuf_scroll_window = window;
|
|
3150 w = XWINDOW (window);
|
|
3151 w->hscroll = 0;
|
|
3152 set_marker_restricted (w->start[CURRENT_DISP], make_int (1), buf);
|
|
3153 set_marker_restricted (w->pointm[CURRENT_DISP], make_int (1), buf);
|
|
3154 set_marker_restricted (w->sb_point, make_int (1), buf);
|
|
3155
|
185
|
3156 /* Run temp-buffer-show-hook, with the chosen window selected. */
|
0
|
3157 if (!preparing_for_armageddon)
|
|
3158 {
|
|
3159 Lisp_Object tem;
|
|
3160 tem = Fboundp (Qtemp_buffer_show_hook);
|
|
3161 if (!NILP (tem))
|
|
3162 {
|
|
3163 tem = Fsymbol_value (Qtemp_buffer_show_hook);
|
|
3164 if (!NILP (tem))
|
|
3165 {
|
|
3166 int count = specpdl_depth ();
|
|
3167
|
|
3168 /* Select the window that was chosen, for running
|
|
3169 the hook. */
|
|
3170 record_unwind_protect (save_window_excursion_unwind,
|
|
3171 Fcurrent_window_configuration (Qnil));
|
|
3172
|
|
3173 Fselect_window (window);
|
|
3174 run_hook (Qtemp_buffer_show_hook);
|
|
3175 unbind_to (count, Qnil);
|
|
3176 }
|
|
3177 }
|
|
3178 }
|
|
3179 }
|
|
3180 }
|
|
3181
|
|
3182 static void
|
|
3183 make_dummy_parent (Lisp_Object window)
|
|
3184 {
|
|
3185 Lisp_Object new = Qnil;
|
|
3186 struct window *o = XWINDOW (window);
|
185
|
3187 struct window *p = alloc_lcrecord_type (struct window, lrecord_window);
|
0
|
3188
|
|
3189 XSETWINDOW (new, p);
|
|
3190 copy_lcrecord (p, o);
|
|
3191
|
|
3192 /* Don't copy the pointers to the line start cache or the face
|
|
3193 instances. */
|
185
|
3194 p->line_start_cache = Dynarr_new (line_start_cache);
|
|
3195 p->face_cachels = Dynarr_new (face_cachel);
|
|
3196 p->glyph_cachels = Dynarr_new (glyph_cachel);
|
0
|
3197
|
|
3198 /* Put new into window structure in place of window */
|
|
3199 replace_window (window, new);
|
|
3200
|
|
3201 o->next = Qnil;
|
|
3202 o->prev = Qnil;
|
|
3203 o->vchild = Qnil;
|
|
3204 o->hchild = Qnil;
|
|
3205 o->parent = new;
|
|
3206
|
|
3207 p->start[CURRENT_DISP] = Qnil;
|
|
3208 p->start[DESIRED_DISP] = Qnil;
|
|
3209 p->start[CMOTION_DISP] = Qnil;
|
|
3210 p->pointm[CURRENT_DISP] = Qnil;
|
|
3211 p->pointm[DESIRED_DISP] = Qnil;
|
|
3212 p->pointm[CMOTION_DISP] = Qnil;
|
|
3213 p->sb_point = Qnil;
|
|
3214 p->buffer = Qnil;
|
|
3215 }
|
|
3216
|
20
|
3217 DEFUN ("split-window", Fsplit_window, 0, 3, "", /*
|
0
|
3218 Split WINDOW, putting SIZE lines in the first of the pair.
|
|
3219 WINDOW defaults to selected one and SIZE to half its size.
|
|
3220 If optional third arg HOR-FLAG is non-nil, split side by side
|
|
3221 and put SIZE columns in the first of the pair.
|
20
|
3222 */
|
|
3223 (window, chsize, horflag))
|
0
|
3224 {
|
|
3225 Lisp_Object new;
|
|
3226 struct window *o, *p;
|
|
3227 struct frame *f;
|
|
3228 int size;
|
|
3229 int psize;
|
|
3230
|
|
3231 if (NILP (window))
|
|
3232 window = Fselected_window (Qnil);
|
|
3233 else
|
|
3234 CHECK_WINDOW (window);
|
|
3235
|
|
3236 o = XWINDOW (window);
|
|
3237 f = XFRAME (WINDOW_FRAME (o));
|
|
3238
|
|
3239 if (NILP (chsize))
|
|
3240 {
|
|
3241 if (!NILP (horflag))
|
|
3242 /* In the new scheme, we are symmetric with respect to separators
|
|
3243 so there is no need to do weird things here. */
|
|
3244 {
|
|
3245 psize = WINDOW_WIDTH (o) >> 1;
|
|
3246 size = window_pixel_width_to_char_width (o, psize, 0);
|
|
3247 }
|
|
3248 else
|
|
3249 {
|
|
3250 psize = WINDOW_HEIGHT (o) >> 1;
|
|
3251 size = window_pixel_height_to_char_height (o, psize, 1);
|
|
3252 }
|
|
3253 }
|
|
3254 else
|
|
3255 {
|
|
3256 CHECK_INT (chsize);
|
|
3257 size = XINT (chsize);
|
|
3258 if (!NILP (horflag))
|
|
3259 psize = window_char_width_to_pixel_width (o, size, 0);
|
|
3260 else
|
|
3261 psize = window_char_height_to_pixel_height (o, size, 1);
|
|
3262 }
|
|
3263
|
|
3264 if (MINI_WINDOW_P (o))
|
|
3265 error ("Attempt to split minibuffer window");
|
|
3266 else if (FRAME_NO_SPLIT_P (XFRAME (WINDOW_FRAME (o))))
|
|
3267 error ("Attempt to split unsplittable frame");
|
|
3268
|
|
3269 check_min_window_sizes ();
|
|
3270
|
|
3271 if (NILP (horflag))
|
|
3272 {
|
|
3273 if (size < window_min_height)
|
|
3274 error ("Window height %d too small (after splitting)", size);
|
|
3275 if (size + window_min_height > window_char_height (o, 1))
|
185
|
3276 error ("Window height %d too small (after splitting)",
|
0
|
3277 window_char_height (o, 1) - size);
|
|
3278 if (NILP (o->parent)
|
|
3279 || NILP (XWINDOW (o->parent)->vchild))
|
|
3280 {
|
|
3281 make_dummy_parent (window);
|
|
3282 reset_face_cachels (XWINDOW (window));
|
|
3283 new = o->parent;
|
|
3284 XWINDOW (new)->vchild = window;
|
|
3285 XFRAME (o->frame)->mirror_dirty = 1;
|
|
3286 }
|
|
3287 }
|
|
3288 else
|
|
3289 {
|
|
3290 if (size < window_min_width)
|
|
3291 error ("Window width %d too small (after splitting)", size);
|
|
3292 if (size + window_min_width > window_char_width (o, 0))
|
185
|
3293 error ("Window width %d too small (after splitting)",
|
0
|
3294 window_char_width (o, 0) - size);
|
|
3295 if (NILP (o->parent)
|
|
3296 || NILP (XWINDOW (o->parent)->hchild))
|
|
3297 {
|
|
3298 make_dummy_parent (window);
|
|
3299 reset_face_cachels (XWINDOW (window));
|
|
3300 new = o->parent;
|
|
3301 XWINDOW (new)->hchild = window;
|
|
3302 XFRAME (o->frame)->mirror_dirty = 1;
|
|
3303 }
|
|
3304 }
|
|
3305
|
|
3306 /* Now we know that window's parent is a vertical combination
|
|
3307 if we are dividing vertically, or a horizontal combination
|
|
3308 if we are making side-by-side windows */
|
|
3309
|
|
3310 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
3311 new = allocate_window ();
|
|
3312 p = XWINDOW (new);
|
|
3313
|
|
3314 p->frame = o->frame;
|
|
3315 p->next = o->next;
|
|
3316 if (!NILP (p->next))
|
|
3317 XWINDOW (p->next)->prev = new;
|
|
3318 p->prev = window;
|
|
3319 o->next = new;
|
|
3320 p->parent = o->parent;
|
|
3321 p->buffer = Qt;
|
|
3322
|
|
3323 reset_face_cachels (p);
|
|
3324 reset_glyph_cachels (p);
|
185
|
3325
|
0
|
3326
|
|
3327 /* Apportion the available frame space among the two new windows */
|
|
3328
|
|
3329 if (!NILP (horflag))
|
|
3330 {
|
|
3331 WINDOW_HEIGHT (p) = WINDOW_HEIGHT (o);
|
|
3332 WINDOW_TOP (p) = WINDOW_TOP (o);
|
|
3333 WINDOW_WIDTH (p) = WINDOW_WIDTH (o) - psize;
|
|
3334 WINDOW_WIDTH (o) = psize;
|
|
3335 WINDOW_LEFT (p) = WINDOW_LEFT (o) + psize;
|
|
3336 }
|
|
3337 else
|
|
3338 {
|
|
3339 WINDOW_LEFT (p) = WINDOW_LEFT (o);
|
|
3340 WINDOW_WIDTH (p) = WINDOW_WIDTH (o);
|
|
3341 WINDOW_HEIGHT (p) = WINDOW_HEIGHT (o) - psize;
|
|
3342 WINDOW_HEIGHT (o) = psize;
|
|
3343 WINDOW_TOP (p) = WINDOW_TOP (o) + psize;
|
|
3344 }
|
|
3345
|
|
3346 XFRAME (p->frame)->mirror_dirty = 1;
|
|
3347 /* do this last (after the window is completely initialized and
|
|
3348 the mirror-dirty flag is set) so that specifier recomputation
|
|
3349 caused as a result of this will work properly and not abort. */
|
|
3350 Fset_window_buffer (new, o->buffer);
|
|
3351 return new;
|
|
3352 }
|
|
3353
|
|
3354
|
20
|
3355 DEFUN ("enlarge-window", Fenlarge_window, 1, 3, "_p", /*
|
0
|
3356 Make the selected window ARG lines bigger.
|
|
3357 From program, optional second arg non-nil means grow sideways ARG columns,
|
|
3358 and optional third ARG specifies the window to change instead of the
|
|
3359 selected window.
|
20
|
3360 */
|
|
3361 (n, side, window))
|
0
|
3362 {
|
|
3363 struct window *w = decode_window (window);
|
|
3364 CHECK_INT (n);
|
|
3365 change_window_height (w, XINT (n), !NILP (side));
|
|
3366 return Qnil;
|
|
3367 }
|
|
3368
|
20
|
3369 DEFUN ("shrink-window", Fshrink_window, 1, 3, "_p", /*
|
0
|
3370 Make the selected window ARG lines smaller.
|
|
3371 From program, optional second arg non-nil means shrink sideways ARG columns,
|
|
3372 and optional third ARG specifies the window to change instead of the
|
|
3373 selected window.
|
20
|
3374 */
|
|
3375 (n, side, window))
|
0
|
3376 {
|
|
3377 CHECK_INT (n);
|
149
|
3378 change_window_height (decode_window (window), -XINT (n), !NILP (side));
|
0
|
3379 return Qnil;
|
|
3380 }
|
|
3381
|
|
3382 static int
|
|
3383 window_pixel_height (Lisp_Object window)
|
|
3384 {
|
149
|
3385 return WINDOW_HEIGHT (XWINDOW (window));
|
0
|
3386 }
|
|
3387
|
|
3388 static int
|
|
3389 window_pixel_height_to_char_height (struct window *w, int pixel_height,
|
|
3390 int include_gutters_p)
|
|
3391 {
|
|
3392 int avail_height;
|
|
3393 int defheight, defwidth;
|
|
3394 int char_height;
|
|
3395 Lisp_Object window;
|
185
|
3396
|
0
|
3397 XSETWINDOW (window, w);
|
185
|
3398
|
0
|
3399 avail_height = (pixel_height -
|
|
3400 (include_gutters_p ? 0 :
|
|
3401 window_top_gutter_height (w) +
|
|
3402 window_bottom_gutter_height (w)));
|
185
|
3403
|
0
|
3404 default_face_height_and_width (window, &defheight, &defwidth);
|
|
3405
|
|
3406 char_height = avail_height / defheight;
|
|
3407
|
|
3408 /* It's the calling function's responsibility to check these values
|
|
3409 and make sure they're not out of range.
|
|
3410
|
|
3411 #### We need to go through the calling functions and actually
|
|
3412 do this. */
|
|
3413 if (char_height < 0)
|
|
3414 return 0;
|
|
3415 else
|
|
3416 return char_height;
|
|
3417 }
|
|
3418
|
|
3419 static int
|
|
3420 window_char_height_to_pixel_height (struct window *w, int char_height,
|
|
3421 int include_gutters_p)
|
|
3422 {
|
|
3423 int avail_height;
|
|
3424 int defheight, defwidth;
|
|
3425 int pixel_height;
|
|
3426
|
|
3427 Lisp_Object window;
|
185
|
3428
|
0
|
3429 XSETWINDOW (window, w);
|
185
|
3430
|
0
|
3431 default_face_height_and_width (window, &defheight, &defwidth);
|
|
3432
|
|
3433 avail_height = char_height * defheight;
|
|
3434 pixel_height = (avail_height +
|
|
3435 (include_gutters_p ? 0 :
|
|
3436 window_top_gutter_height (w) +
|
|
3437 window_bottom_gutter_height (w)));
|
|
3438
|
|
3439 /* It's the calling function's responsibility to check these values
|
|
3440 and make sure they're not out of range.
|
|
3441
|
|
3442 #### We need to go through the calling functions and actually
|
|
3443 do this. */
|
|
3444 if (pixel_height < 0)
|
|
3445 return 0;
|
|
3446 else
|
|
3447 return pixel_height;
|
|
3448 }
|
|
3449
|
|
3450 /* Return number of default lines of text can fit in the window W.
|
|
3451 If INCLUDE_GUTTERS_P is 1, include "gutter" space (modeline plus
|
|
3452 horizontal scrollbar) in the space that is used for the calculation.
|
|
3453 */
|
|
3454 int
|
|
3455 window_char_height (struct window *w, int include_gutters_p)
|
|
3456 {
|
|
3457 return window_pixel_height_to_char_height (w, WINDOW_HEIGHT (w),
|
|
3458 include_gutters_p);
|
|
3459 }
|
|
3460
|
|
3461 /*
|
|
3462 * Return number of lines currently displayed in window w. If
|
|
3463 * end-of-buffer is displayed then the area below end-of-buffer is assume
|
|
3464 * to be blank lines of default height.
|
|
3465 * Does not include the modeline.
|
|
3466 */
|
|
3467 int
|
|
3468 window_displayed_height (struct window *w)
|
|
3469 {
|
|
3470 struct buffer *b = XBUFFER (w->buffer);
|
|
3471 display_line_dynarr *dla = window_display_lines (w, CURRENT_DISP);
|
|
3472 int num_lines;
|
|
3473 Charcount end_pos = (BUF_Z (b) - w->window_end_pos[CURRENT_DISP] > BUF_ZV (b)
|
|
3474 ? -1
|
|
3475 : w->window_end_pos[CURRENT_DISP]);
|
|
3476
|
|
3477 if (!Dynarr_length (dla))
|
|
3478 return window_char_height (w, 0);
|
|
3479
|
|
3480 num_lines = Dynarr_length (dla);
|
|
3481
|
|
3482 /* #### Document and assert somewhere that w->window_end_pos == -1
|
|
3483 indicates that end-of-buffer is being displayed. */
|
|
3484 if (end_pos == -1)
|
|
3485 {
|
|
3486 struct display_line *dl = Dynarr_atp (dla, 0);
|
|
3487 int ypos1 = dl->ypos + dl->descent;
|
|
3488 int ypos2 = WINDOW_TEXT_BOTTOM (w);
|
|
3489 Lisp_Object window;
|
|
3490 int defheight, defwidth;
|
|
3491
|
|
3492 XSETWINDOW (window, w);
|
|
3493
|
|
3494 if (dl->modeline)
|
|
3495 {
|
|
3496 num_lines--;
|
|
3497
|
|
3498 if (Dynarr_length (dla) == 1)
|
|
3499 ypos1 = WINDOW_TEXT_TOP (w);
|
|
3500 else
|
|
3501 {
|
|
3502 dl = Dynarr_atp (dla, Dynarr_length (dla) - 1);
|
|
3503 /* If this line is clipped then we know that there is no
|
|
3504 blank room between eob and the modeline. If we are
|
|
3505 scrolling on clipped lines just know off the clipped
|
|
3506 line and return .*/
|
|
3507 if (scroll_on_clipped_lines && dl->clip)
|
149
|
3508 return num_lines - 1;
|
0
|
3509 ypos1 = dl->ypos + dl->descent - dl->clip;
|
|
3510 }
|
|
3511 }
|
|
3512
|
|
3513 default_face_height_and_width (window, &defheight, &defwidth);
|
|
3514 /* #### This probably needs to know about the clipping area once a
|
|
3515 final definition is decided on. */
|
|
3516 num_lines += ((ypos2 - ypos1) / defheight);
|
|
3517 }
|
|
3518 else
|
|
3519 {
|
|
3520 if (num_lines > 1 && Dynarr_atp (dla, 0)->modeline)
|
|
3521 num_lines--;
|
|
3522
|
|
3523 if (scroll_on_clipped_lines
|
|
3524 && Dynarr_atp (dla, Dynarr_length (dla) - 1)->clip)
|
|
3525 num_lines--;
|
|
3526 }
|
|
3527
|
|
3528 return num_lines;
|
|
3529 }
|
|
3530
|
|
3531 static int
|
|
3532 window_pixel_width (Lisp_Object window)
|
|
3533 {
|
149
|
3534 return WINDOW_WIDTH (XWINDOW (window));
|
0
|
3535 }
|
|
3536
|
|
3537 static int
|
|
3538 window_pixel_width_to_char_width (struct window *w, int pixel_width,
|
|
3539 int include_margins_p)
|
|
3540 {
|
|
3541 int avail_width;
|
|
3542 int char_width;
|
|
3543 int defheight, defwidth;
|
|
3544 Lisp_Object window;
|
185
|
3545
|
0
|
3546 XSETWINDOW (window, w);
|
185
|
3547
|
0
|
3548 avail_width = (pixel_width -
|
|
3549 window_left_gutter_width (w, 0) -
|
|
3550 window_right_gutter_width (w, 0) -
|
|
3551 (include_margins_p ? 0 : window_left_margin_width (w)) -
|
|
3552 (include_margins_p ? 0 : window_right_margin_width (w)));
|
185
|
3553
|
0
|
3554 default_face_height_and_width (window, &defheight, &defwidth);
|
185
|
3555
|
0
|
3556 char_width = (avail_width / defwidth);
|
|
3557
|
|
3558 /* It's the calling function's responsibility to check these values
|
|
3559 and make sure they're not out of range.
|
|
3560
|
|
3561 #### We need to go through the calling functions and actually
|
|
3562 do this. */
|
|
3563 if (char_width < 0)
|
|
3564 return 0;
|
|
3565 else
|
|
3566 return char_width;
|
|
3567 }
|
|
3568
|
|
3569 static int
|
|
3570 window_char_width_to_pixel_width (struct window *w, int char_width,
|
|
3571 int include_margins_p)
|
|
3572 {
|
|
3573 int avail_width;
|
|
3574 int pixel_width;
|
|
3575 int defheight, defwidth;
|
|
3576 Lisp_Object window;
|
|
3577
|
|
3578 XSETWINDOW (window, w);
|
|
3579
|
|
3580 default_face_height_and_width (window, &defheight, &defwidth);
|
|
3581
|
|
3582 avail_width = char_width * defwidth;
|
|
3583 pixel_width = (avail_width +
|
|
3584 window_left_gutter_width (w, 0) +
|
|
3585 window_right_gutter_width (w, 0) +
|
|
3586 (include_margins_p ? 0 : window_left_margin_width (w)) +
|
|
3587 (include_margins_p ? 0 : window_right_margin_width (w)));
|
|
3588
|
|
3589 /* It's the calling function's responsibility to check these values
|
|
3590 and make sure they're not out of range.
|
|
3591
|
|
3592 #### We need to go through the calling functions and actually
|
|
3593 do this. */
|
|
3594 if (pixel_width < 0)
|
|
3595 return 0;
|
|
3596 else
|
|
3597 return pixel_width;
|
|
3598 }
|
|
3599
|
|
3600 /* This returns the usable space which doesn't include space needed by
|
|
3601 scrollbars or divider lines. */
|
|
3602 int
|
|
3603 window_char_width (struct window *w, int include_margins_p)
|
|
3604 {
|
|
3605 return window_pixel_width_to_char_width (w, WINDOW_WIDTH (w),
|
|
3606 include_margins_p);
|
|
3607 }
|
|
3608
|
|
3609 #define MINSIZE(w) \
|
|
3610 (widthflag \
|
|
3611 ? window_min_width * defwidth \
|
|
3612 : (defheight * (MINI_WINDOW_P (XWINDOW (w)) ? 1 : window_min_height)))
|
|
3613
|
|
3614 #define CURBEG(w) \
|
|
3615 *(widthflag ? (int *) &WINDOW_LEFT (w) : (int *) &WINDOW_TOP (w))
|
|
3616
|
|
3617 #define CURSIZE(w) \
|
|
3618 *(widthflag ? (int *) &WINDOW_WIDTH (w) : (int *) &WINDOW_HEIGHT (w))
|
|
3619
|
|
3620 #define CURCHARSIZE(w) \
|
|
3621 (widthflag ? window_char_width (w, 0) : window_char_height (w, 1))
|
|
3622
|
|
3623 #define MINCHARSIZE(window) \
|
|
3624 (widthflag ? window_min_width : MINI_WINDOW_P (XWINDOW (window)) \
|
|
3625 ? 1 : window_min_height)
|
|
3626
|
|
3627 /* Unlike set_window_pixheight, this function
|
|
3628 also changes the heights of the siblings so as to
|
|
3629 keep everything consistent. */
|
|
3630
|
|
3631 static void
|
|
3632 change_window_height (struct window *win, int delta, int widthflag)
|
|
3633 {
|
|
3634 Lisp_Object parent;
|
|
3635 Lisp_Object window = Qnil;
|
|
3636 struct window *w;
|
|
3637 struct frame *f;
|
|
3638 int *sizep;
|
|
3639 int (*sizefun) (Lisp_Object) = (widthflag
|
|
3640 ? window_pixel_width
|
|
3641 : window_pixel_height);
|
|
3642 void (*setsizefun) (Lisp_Object, int, int) = (widthflag
|
|
3643 ? set_window_pixwidth
|
|
3644 : set_window_pixheight);
|
|
3645 int dim;
|
|
3646 int defheight, defwidth;
|
|
3647
|
|
3648 if (delta == 0)
|
|
3649 return;
|
|
3650
|
|
3651 check_min_window_sizes ();
|
|
3652
|
|
3653 XSETWINDOW (window, win);
|
|
3654 f = XFRAME (win->frame);
|
|
3655 if (EQ (window, FRAME_ROOT_WINDOW (f)))
|
|
3656 error ("Won't change only window");
|
|
3657
|
|
3658 /* #### This is very likely incorrect and instead the char_to_pixel_
|
|
3659 functions should be called. */
|
|
3660 default_face_height_and_width (window, &defheight, &defwidth);
|
|
3661
|
|
3662 while (1)
|
|
3663 {
|
|
3664 w = XWINDOW (window);
|
|
3665 parent = w->parent;
|
|
3666 if (NILP (parent))
|
|
3667 {
|
|
3668 if (widthflag)
|
|
3669 error ("No other window to side of this one");
|
|
3670 break;
|
|
3671 }
|
|
3672 if (widthflag
|
|
3673 ? !NILP (XWINDOW (parent)->hchild)
|
|
3674 : !NILP (XWINDOW (parent)->vchild))
|
|
3675 break;
|
|
3676 window = parent;
|
|
3677 }
|
|
3678
|
|
3679 sizep = &CURSIZE (w);
|
|
3680 dim = CURCHARSIZE (w);
|
|
3681
|
|
3682 if ((dim + delta) < MINCHARSIZE (window))
|
|
3683 {
|
|
3684 if (MINI_WINDOW_P (XWINDOW (window)))
|
|
3685 return;
|
|
3686 else if (!NILP (parent))
|
|
3687 {
|
|
3688 Fdelete_window (window, Qnil);
|
|
3689 return;
|
|
3690 }
|
|
3691 }
|
|
3692
|
|
3693 delta *= (widthflag ? defwidth : defheight);
|
|
3694
|
|
3695 {
|
|
3696 int maxdelta;
|
|
3697
|
|
3698 maxdelta = ((!NILP (parent))
|
|
3699 ? (*sizefun) (parent) - *sizep
|
|
3700 : ((!NILP (w->next))
|
|
3701 ? (*sizefun) (w->next) - MINSIZE (w->next)
|
|
3702 : ((!NILP (w->prev))
|
|
3703 ? (*sizefun) (w->prev) - MINSIZE (w->prev)
|
185
|
3704 /* This is a frame with only one window,
|
0
|
3705 a minibuffer-only or a minibufferless frame. */
|
|
3706 : (delta = 0))));
|
|
3707
|
|
3708 if (delta > maxdelta)
|
|
3709 /* This case traps trying to make the minibuffer
|
|
3710 the full frame, or make the only window aside from the
|
|
3711 minibuffer the full frame. */
|
|
3712 delta = maxdelta;
|
|
3713
|
|
3714 if (delta == 0)
|
|
3715 return;
|
|
3716
|
|
3717 #if 0 /* FSFmacs */
|
|
3718 /* #### Chuck: is this correct? */
|
|
3719 if (*sizep + delta < MINSIZE (window))
|
|
3720 {
|
|
3721 Fdelete_window (window);
|
|
3722 return;
|
|
3723 }
|
|
3724 #endif
|
|
3725 }
|
|
3726
|
|
3727 if (!NILP (w->next) &&
|
|
3728 (*sizefun) (w->next) - delta >= (int) MINSIZE (w->next))
|
|
3729 {
|
|
3730 CURBEG (XWINDOW (w->next)) += delta;
|
|
3731 (*setsizefun) (w->next, (*sizefun) (w->next) - delta, 0);
|
|
3732 (*setsizefun) (window, *sizep + delta, 0);
|
|
3733 }
|
|
3734 else if (!NILP (w->prev) &&
|
|
3735 (*sizefun) (w->prev) - delta >= (int) MINSIZE (w->prev))
|
|
3736 {
|
|
3737 (*setsizefun) (w->prev, (*sizefun) (w->prev) - delta, 0);
|
|
3738 CURBEG (w) -= delta;
|
|
3739 (*setsizefun) (window, *sizep + delta, 0);
|
|
3740 }
|
|
3741 else
|
|
3742 {
|
|
3743 int delta1;
|
|
3744 int opht = (*sizefun) (parent);
|
|
3745
|
|
3746 /* If trying to grow this window to or beyond size of the parent,
|
|
3747 make delta1 so big that, on shrinking back down,
|
|
3748 all the siblings end up with less than one line and are deleted. */
|
|
3749 if (opht <= *sizep + delta)
|
|
3750 delta1 = opht * opht * 2;
|
|
3751 /* Otherwise, make delta1 just right so that if we add delta1
|
|
3752 lines to this window and to the parent, and then shrink
|
|
3753 the parent back to its original size, the new proportional
|
|
3754 size of this window will increase by delta. */
|
|
3755 else
|
|
3756 delta1 = (delta * opht * 100) / ((opht - *sizep - delta) * 100);
|
|
3757
|
|
3758 /* Add delta1 lines or columns to this window, and to the parent,
|
|
3759 keeping things consistent while not affecting siblings. */
|
|
3760 CURSIZE (XWINDOW (parent)) = opht + delta1;
|
|
3761 (*setsizefun) (window, *sizep + delta1, 0);
|
|
3762
|
|
3763 /* Squeeze out delta1 lines or columns from our parent,
|
|
3764 shriking this window and siblings proportionately.
|
|
3765 This brings parent back to correct size.
|
|
3766 Delta1 was calculated so this makes this window the desired size,
|
|
3767 taking it all out of the siblings. */
|
|
3768 (*setsizefun) (parent, opht, 0);
|
|
3769 }
|
|
3770
|
|
3771 SET_LAST_MODIFIED (w, 0);
|
|
3772 SET_LAST_FACECHANGE (w);
|
|
3773 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
3774 }
|
|
3775 #undef MINSIZE
|
|
3776 #undef CURBEG
|
|
3777 #undef CURSIZE
|
|
3778 #undef CURCHARSIZE
|
|
3779 #undef MINCHARSIZE
|
|
3780
|
|
3781
|
|
3782
|
|
3783 /* Scroll contents of window WINDOW up N lines. */
|
|
3784 void
|
|
3785 window_scroll (Lisp_Object window, Lisp_Object n, int direction,
|
|
3786 Error_behavior errb)
|
|
3787 {
|
|
3788 struct window *w = XWINDOW (window);
|
|
3789 struct buffer *b = XBUFFER (w->buffer);
|
|
3790 int selected = EQ (window, Fselected_window (Qnil));
|
|
3791 int value = 0;
|
|
3792 Lisp_Object point, tem;
|
|
3793
|
|
3794 if (selected)
|
|
3795 point = make_int (BUF_PT (b));
|
|
3796 else
|
|
3797 {
|
|
3798 Bufpos pos = marker_position (w->pointm[CURRENT_DISP]);
|
|
3799
|
|
3800 if (pos < BUF_BEGV (b))
|
|
3801 pos = BUF_BEGV (b);
|
|
3802 else if (pos > BUF_ZV (b))
|
|
3803 pos = BUF_ZV (b);
|
|
3804
|
|
3805 point = make_int (pos);
|
|
3806 }
|
|
3807
|
|
3808 /* Always set force_start so that redisplay_window will run
|
|
3809 thw window-scroll-functions. */
|
|
3810 w->force_start = 1;
|
|
3811
|
|
3812 /* #### When the fuck does this happen? I'm so glad that history has
|
|
3813 completely documented the behavior of the scrolling functions under
|
|
3814 all circumstances. */
|
|
3815 tem = Fpos_visible_in_window_p (point, window);
|
|
3816 if (NILP (tem))
|
|
3817 {
|
|
3818 Fvertical_motion (make_int (-window_char_height (w, 0) / 2), window);
|
|
3819 Fset_marker (w->start[CURRENT_DISP], point, w->buffer);
|
|
3820 w->start_at_line_beg = beginning_of_line_p (b, XINT (point));
|
|
3821 MARK_WINDOWS_CHANGED (w);
|
|
3822 }
|
|
3823
|
|
3824 if (!NILP (n))
|
|
3825 {
|
|
3826 if (EQ (n, Qminus))
|
|
3827 direction *= -1;
|
|
3828 else
|
|
3829 {
|
|
3830 n = Fprefix_numeric_value (n);
|
|
3831 value = XINT (n) * direction;
|
|
3832
|
|
3833 if (!value)
|
|
3834 return; /* someone just made a pointless call */
|
|
3835 }
|
|
3836 }
|
|
3837
|
|
3838 /* If the user didn't specify how far to scroll then we have to figure it
|
|
3839 out by ourselves. */
|
|
3840 if (NILP (n) || EQ (n, Qminus))
|
|
3841 {
|
|
3842 /* Going forwards is easy. If that is what we are doing then just
|
|
3843 set value and the section which handles the user specifying a
|
|
3844 positive value will work. */
|
|
3845 if (direction == 1)
|
|
3846 {
|
|
3847 value = window_displayed_height (w) - next_screen_context_lines;
|
|
3848 value = (value < 1 ? 1 : value);
|
|
3849 }
|
|
3850
|
|
3851 /* Going backwards is hard. We can't use the same loop used if the
|
|
3852 user specified a negative value because we care about
|
|
3853 next_screen_context_lines. In a variable height world you don't
|
|
3854 know how many lines above you can actually be displayed and still
|
|
3855 have the context lines appear. So we leave value set to 0 and add
|
|
3856 a separate section to deal with this. */
|
|
3857
|
|
3858 }
|
|
3859
|
|
3860 if (direction == 1 && !value)
|
|
3861 {
|
|
3862 return;
|
|
3863 }
|
|
3864 else if (value > 0)
|
|
3865 {
|
|
3866 int vtarget;
|
|
3867 Bufpos startp, old_start;
|
|
3868
|
|
3869 old_start = marker_position (w->start[CURRENT_DISP]);
|
|
3870 startp = vmotion (w, old_start, value, &vtarget);
|
|
3871
|
|
3872 if (vtarget < value &&
|
|
3873 (w->window_end_pos[CURRENT_DISP] == -1
|
|
3874 || (BUF_Z (b) - w->window_end_pos[CURRENT_DISP] > BUF_ZV (b))))
|
|
3875 {
|
|
3876 maybe_signal_error (Qend_of_buffer, Qnil, Qwindow, errb);
|
|
3877 return;
|
|
3878 }
|
|
3879 else
|
|
3880 {
|
|
3881 set_marker_restricted (w->start[CURRENT_DISP], make_int (startp),
|
|
3882 w->buffer);
|
|
3883 w->force_start = 1;
|
|
3884 w->start_at_line_beg = beginning_of_line_p (b, startp);
|
|
3885 MARK_WINDOWS_CHANGED (w);
|
|
3886
|
|
3887 if (!point_would_be_visible (w, startp, XINT (point)))
|
|
3888 {
|
|
3889 if (selected)
|
|
3890 BUF_SET_PT (b, startp);
|
|
3891 else
|
|
3892 set_marker_restricted (w->pointm[CURRENT_DISP],
|
|
3893 make_int (startp),
|
|
3894 w->buffer);
|
|
3895 }
|
|
3896 }
|
|
3897 }
|
|
3898 else if (value < 0)
|
|
3899 {
|
|
3900 int vtarget;
|
|
3901 Bufpos startp, old_start;
|
|
3902
|
|
3903 old_start = marker_position (w->start[CURRENT_DISP]);
|
|
3904 startp = vmotion (w, old_start, value, &vtarget);
|
|
3905
|
|
3906 if (vtarget > value
|
|
3907 && marker_position (w->start[CURRENT_DISP]) == BUF_BEGV (b))
|
|
3908 {
|
|
3909 maybe_signal_error (Qbeginning_of_buffer, Qnil, Qwindow, errb);
|
|
3910 return;
|
|
3911 }
|
|
3912 else
|
|
3913 {
|
|
3914 set_marker_restricted (w->start[CURRENT_DISP], make_int (startp),
|
|
3915 w->buffer);
|
|
3916 w->force_start = 1;
|
|
3917 w->start_at_line_beg = beginning_of_line_p (b, startp);
|
|
3918 MARK_WINDOWS_CHANGED (w);
|
|
3919
|
|
3920 if (!point_would_be_visible (w, startp, XINT (point)))
|
|
3921 {
|
|
3922 Bufpos new_point;
|
|
3923
|
|
3924 if (MINI_WINDOW_P (w))
|
|
3925 new_point = startp;
|
|
3926 else
|
|
3927 new_point = start_of_last_line (w, startp);
|
|
3928
|
|
3929 if (selected)
|
|
3930 BUF_SET_PT (b, new_point);
|
|
3931 else
|
|
3932 set_marker_restricted (w->pointm[CURRENT_DISP],
|
|
3933 make_int (new_point),
|
|
3934 w->buffer);
|
|
3935 }
|
|
3936 }
|
|
3937 }
|
|
3938 else /* value == 0 && direction == -1 */
|
|
3939 {
|
|
3940 if (marker_position (w->start[CURRENT_DISP]) == BUF_BEGV (b))
|
|
3941 {
|
|
3942 maybe_signal_error (Qbeginning_of_buffer, Qnil, Qwindow, errb);
|
|
3943 return;
|
|
3944 }
|
|
3945 else
|
|
3946 {
|
|
3947 int vtarget;
|
|
3948 int movement = next_screen_context_lines - 1;
|
|
3949 Bufpos old_startp = marker_position (w->start[CURRENT_DISP]);
|
|
3950 Bufpos bottom = vmotion (w, old_startp, movement, &vtarget);
|
|
3951 Bufpos startp =
|
|
3952 start_with_point_on_display_line (w, bottom,
|
|
3953 -1 - (movement - vtarget));
|
|
3954
|
|
3955 if (startp >= old_startp)
|
|
3956 startp = vmotion (w, old_startp, -1, NULL);
|
|
3957
|
|
3958 set_marker_restricted (w->start[CURRENT_DISP], make_int (startp),
|
|
3959 w->buffer);
|
|
3960 w->force_start = 1;
|
|
3961 w->start_at_line_beg = beginning_of_line_p (b, startp);
|
|
3962 MARK_WINDOWS_CHANGED (w);
|
|
3963
|
|
3964 if (!point_would_be_visible (w, startp, XINT (point)))
|
|
3965 {
|
|
3966 Bufpos new_point = start_of_last_line (w, startp);
|
|
3967
|
|
3968 if (selected)
|
|
3969 BUF_SET_PT (b, new_point);
|
|
3970 else
|
|
3971 set_marker_restricted (w->pointm[CURRENT_DISP],
|
|
3972 make_int (new_point),
|
|
3973 w->buffer);
|
|
3974 }
|
|
3975 }
|
|
3976 }
|
|
3977
|
|
3978 }
|
|
3979
|
98
|
3980 extern int signal_error_on_buffer_boundary;
|
|
3981
|
20
|
3982 DEFUN ("scroll-up", Fscroll_up, 0, 1, "_P", /*
|
0
|
3983 Scroll text of current window upward ARG lines; or near full screen if no ARG.
|
|
3984 A near full screen is `next-screen-context-lines' less than a full screen.
|
|
3985 Negative ARG means scroll downward.
|
|
3986 When calling from a program, supply a number as argument or nil.
|
98
|
3987
|
|
3988 If `signal-error-on-buffer-boundary' is nil, the usual error and
|
|
3989 loss of zmacs region is suppressed when moving past end of buffer.
|
20
|
3990 */
|
|
3991 (n))
|
0
|
3992 {
|
98
|
3993 Error_behavior errb =
|
|
3994 signal_error_on_buffer_boundary ? ERROR_ME : ERROR_ME_NOT;
|
|
3995
|
|
3996 window_scroll (Fselected_window (Qnil), n, 1, errb);
|
0
|
3997 return Qnil;
|
|
3998 }
|
|
3999
|
20
|
4000 DEFUN ("scroll-down", Fscroll_down, 0, 1, "_P", /*
|
0
|
4001 Scroll text of current window downward ARG lines; or near full screen if no ARG.
|
|
4002 A near full screen is `next-screen-context-lines' less than a full screen.
|
|
4003 Negative ARG means scroll upward.
|
|
4004 When calling from a program, supply a number as argument or nil.
|
98
|
4005
|
|
4006 If `signal-error-on-buffer-boundary' is nil, the usual error and
|
|
4007 loss of zmacs region is suppressed when moving past end of buffer.
|
20
|
4008 */
|
|
4009 (n))
|
0
|
4010 {
|
98
|
4011 Error_behavior errb =
|
|
4012 signal_error_on_buffer_boundary ? ERROR_ME : ERROR_ME_NOT;
|
|
4013
|
|
4014 window_scroll (Fselected_window (Qnil), n, -1, errb);
|
0
|
4015 return Qnil;
|
|
4016 }
|
|
4017
|
20
|
4018 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling, 0, 0, 0, /*
|
185
|
4019 Return the other window for "other window scroll" commands.
|
0
|
4020 If in the minibuffer, `minibuffer-scroll-window' if non-nil
|
|
4021 specifies the window.
|
|
4022 If `other-window-scroll-buffer' is non-nil, a window
|
|
4023 showing that buffer is used.
|
20
|
4024 */
|
|
4025 ())
|
0
|
4026 {
|
|
4027 Lisp_Object window;
|
|
4028 Lisp_Object selected_window = Fselected_window (Qnil);
|
|
4029
|
|
4030 if (MINI_WINDOW_P (XWINDOW (selected_window))
|
|
4031 && !NILP (Vminibuf_scroll_window))
|
|
4032 window = Vminibuf_scroll_window;
|
|
4033 /* If buffer is specified, scroll that buffer. */
|
|
4034 else if (!NILP (Vother_window_scroll_buffer))
|
|
4035 {
|
|
4036 window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil, Qnil);
|
|
4037 if (NILP (window))
|
|
4038 window = display_buffer (Vother_window_scroll_buffer, Qt, Qnil);
|
|
4039 }
|
|
4040 else
|
|
4041 {
|
|
4042 /* Nothing specified; look for a neighboring window on the same
|
|
4043 frame. */
|
|
4044 window = Fnext_window (selected_window, Qnil, Qnil, Qnil);
|
|
4045
|
|
4046 if (EQ (window, selected_window))
|
|
4047 /* That didn't get us anywhere; look for a window on another
|
|
4048 visible frame. */
|
|
4049 do
|
|
4050 window = Fnext_window (window, Qnil, Qt, Qnil);
|
|
4051 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window))))
|
|
4052 && ! EQ (window, selected_window));
|
|
4053 }
|
|
4054
|
|
4055 CHECK_LIVE_WINDOW (window);
|
|
4056
|
|
4057 if (EQ (window, selected_window))
|
|
4058 error ("There is no other window");
|
|
4059
|
|
4060 return window;
|
|
4061 }
|
|
4062
|
20
|
4063 DEFUN ("scroll-other-window", Fscroll_other_window, 0, 1, "_P", /*
|
0
|
4064 Scroll next window upward ARG lines; or near full frame if no ARG.
|
|
4065 The next window is the one below the current one; or the one at the top
|
|
4066 if the current one is at the bottom. Negative ARG means scroll downward.
|
|
4067 When calling from a program, supply a number as argument or nil.
|
|
4068
|
|
4069 If in the minibuffer, `minibuf-scroll-window' if non-nil
|
|
4070 specifies the window to scroll.
|
|
4071 If `other-window-scroll-buffer' is non-nil, scroll the window
|
|
4072 showing that buffer, popping the buffer up if necessary.
|
20
|
4073 */
|
|
4074 (n))
|
0
|
4075 {
|
|
4076 window_scroll (Fother_window_for_scrolling (), n, 1, ERROR_ME);
|
|
4077 return Qnil;
|
|
4078 }
|
|
4079
|
20
|
4080 DEFUN ("scroll-left", Fscroll_left, 0, 1, "_P", /*
|
0
|
4081 Scroll selected window display ARG columns left.
|
|
4082 Default for ARG is window width minus 2.
|
20
|
4083 */
|
|
4084 (arg))
|
0
|
4085 {
|
|
4086 Lisp_Object window = Fselected_window (Qnil);
|
|
4087 struct window *w = XWINDOW (window);
|
|
4088
|
|
4089 if (NILP (arg))
|
|
4090 arg = make_int (window_char_width (w, 0) - 2);
|
|
4091 else
|
|
4092 arg = Fprefix_numeric_value (arg);
|
|
4093
|
149
|
4094 return Fset_window_hscroll (window, make_int (w->hscroll + XINT (arg)));
|
0
|
4095 }
|
|
4096
|
20
|
4097 DEFUN ("scroll-right", Fscroll_right, 0, 1, "_P", /*
|
0
|
4098 Scroll selected window display ARG columns right.
|
|
4099 Default for ARG is window width minus 2.
|
20
|
4100 */
|
|
4101 (arg))
|
0
|
4102 {
|
|
4103 Lisp_Object window = Fselected_window (Qnil);
|
|
4104 struct window *w = XWINDOW (window);
|
|
4105
|
|
4106 if (NILP (arg))
|
|
4107 arg = make_int (window_char_width (w, 0) - 2);
|
|
4108 else
|
|
4109 arg = Fprefix_numeric_value (arg);
|
|
4110
|
149
|
4111 return Fset_window_hscroll (window, make_int (w->hscroll - XINT (arg)));
|
0
|
4112 }
|
|
4113
|
20
|
4114 DEFUN ("recenter", Frecenter, 0, 2, "_P", /*
|
201
|
4115 Center point in WINDOW and redisplay frame. With N, put point on line N.
|
0
|
4116 The desired position of point is always relative to the window.
|
|
4117 Just C-u as prefix means put point in the center of the window.
|
201
|
4118 No N (i.e., it is nil) erases the entire frame and then
|
0
|
4119 redraws with point in the center of the window.
|
|
4120 If WINDOW is nil, the selected window is used.
|
20
|
4121 */
|
|
4122 (n, window))
|
0
|
4123 {
|
|
4124 struct window *w;
|
|
4125 struct buffer *b;
|
|
4126 Bufpos startp;
|
|
4127 Bufpos opoint;
|
|
4128
|
|
4129 if (NILP (window))
|
|
4130 window = Fselected_window (Qnil);
|
|
4131 else
|
|
4132 CHECK_WINDOW (window);
|
|
4133 w = XWINDOW (window);
|
|
4134 b = XBUFFER (w->buffer);
|
|
4135
|
|
4136 opoint = BUF_PT (b);
|
|
4137
|
|
4138 if (NILP (n) || CONSP (n))
|
|
4139 {
|
|
4140 struct frame *f = XFRAME (w->frame);
|
|
4141
|
|
4142 if (NILP (n))
|
|
4143 {
|
|
4144 MARK_FRAME_CHANGED (f);
|
|
4145 SET_FRAME_CLEAR (f);
|
|
4146 }
|
|
4147
|
|
4148 startp = start_with_line_at_pixpos (w, opoint, window_half_pixpos (w));
|
|
4149 }
|
|
4150 else
|
|
4151 {
|
|
4152 n = Fprefix_numeric_value (n);
|
|
4153 CHECK_INT (n);
|
|
4154
|
|
4155 startp = start_with_point_on_display_line (w, opoint, XINT (n));
|
|
4156 }
|
|
4157
|
|
4158 Fset_marker (w->start[CURRENT_DISP], make_int (startp), w->buffer);
|
185
|
4159
|
0
|
4160 w->start_at_line_beg = beginning_of_line_p (b, startp);
|
|
4161 w->force_start = 1;
|
|
4162 MARK_WINDOWS_CHANGED (w);
|
|
4163 return Qnil;
|
|
4164 }
|
|
4165
|
20
|
4166 DEFUN ("move-to-window-line", Fmove_to_window_line, 1, 2, "_P", /*
|
0
|
4167 Position point relative to WINDOW.
|
|
4168 With no argument, position text at center of window.
|
|
4169 An argument specifies window line; zero means top of window,
|
|
4170 negative means relative to bottom of window.
|
|
4171 If WINDOW is nil, the selected window is used.
|
20
|
4172 */
|
|
4173 (arg, window))
|
0
|
4174 {
|
|
4175 struct window *w;
|
|
4176 struct buffer *b;
|
|
4177 int height;
|
|
4178 Bufpos start, new_point;
|
|
4179 int selected;
|
|
4180
|
|
4181 if (NILP (window))
|
|
4182 window = Fselected_window (Qnil);
|
|
4183 else
|
|
4184 CHECK_WINDOW (window);
|
|
4185 w = XWINDOW (window);
|
|
4186 b = XBUFFER (w->buffer);
|
|
4187
|
|
4188 height = window_displayed_height (w);
|
|
4189 selected = EQ (window, Fselected_window (w->frame));
|
|
4190
|
|
4191 if (NILP (arg))
|
|
4192 {
|
|
4193 int retval;
|
|
4194
|
|
4195 if (XINT (w->last_modified[CURRENT_DISP]) >= BUF_MODIFF (b)
|
|
4196 && XINT (w->last_facechange[CURRENT_DISP]) >= BUF_FACECHANGE (b))
|
|
4197 {
|
|
4198 new_point = point_at_center (w, CURRENT_DISP, 0, 0);
|
|
4199
|
|
4200 if (selected)
|
|
4201 BUF_SET_PT (b, new_point);
|
|
4202 else
|
|
4203 Fset_window_point (window, make_int (new_point));
|
|
4204
|
|
4205 retval = line_at_center (w, CURRENT_DISP, 0, 0);
|
|
4206 }
|
|
4207 else
|
|
4208 {
|
|
4209 start = marker_position (w->start[CURRENT_DISP]);
|
|
4210 if (start < BUF_BEGV (b))
|
|
4211 start = BUF_BEGV (b);
|
|
4212 else if (start > BUF_ZV (b))
|
|
4213 start = BUF_ZV (b);
|
|
4214
|
|
4215 if (selected)
|
|
4216 new_point = BUF_PT (b);
|
|
4217 else
|
|
4218 new_point = marker_position (w->pointm[CURRENT_DISP]);
|
|
4219
|
|
4220 new_point = point_at_center (w, CMOTION_DISP, start, BUF_PT (b));
|
|
4221
|
|
4222 if (selected)
|
|
4223 BUF_SET_PT (b, new_point);
|
|
4224 else
|
|
4225 Fset_window_point (window, make_int (new_point));
|
|
4226
|
|
4227 retval = line_at_center (w, CMOTION_DISP, start, BUF_PT (b));
|
|
4228 }
|
|
4229
|
149
|
4230 return make_int (retval);
|
0
|
4231 }
|
|
4232 else
|
|
4233 {
|
|
4234 /* #### Is this going to work right when at eob? */
|
|
4235 arg = Fprefix_numeric_value (arg);
|
|
4236 if (XINT (arg) < 0)
|
|
4237 XSETINT (arg, XINT (arg) + height);
|
|
4238 }
|
|
4239
|
|
4240 start = marker_position (w->start[CURRENT_DISP]);
|
|
4241 if (start < BUF_BEGV (b) || start > BUF_ZV (b))
|
|
4242 {
|
|
4243 if (selected)
|
|
4244 new_point = BUF_PT (b);
|
|
4245 else
|
|
4246 new_point = marker_position (w->pointm[CURRENT_DISP]);
|
|
4247
|
|
4248 new_point = vmotion (XWINDOW (window), new_point, -height / 2, 0);
|
|
4249
|
|
4250 if (selected)
|
|
4251 BUF_SET_PT (b, new_point);
|
|
4252 else
|
|
4253 Fset_window_point (window, make_int (new_point));
|
|
4254
|
|
4255 Fset_marker (w->start[CURRENT_DISP], make_int (new_point),
|
|
4256 w->buffer);
|
|
4257 w->start_at_line_beg = beginning_of_line_p (b, new_point);
|
|
4258 w->force_start = 1;
|
|
4259 }
|
|
4260 else
|
|
4261 {
|
|
4262 if (selected)
|
|
4263 BUF_SET_PT (b, start);
|
|
4264 else
|
|
4265 Fset_window_point (window, make_int (start));
|
|
4266 }
|
|
4267
|
|
4268 if (selected)
|
|
4269 return Fvertical_motion (arg, window);
|
|
4270 else
|
|
4271 {
|
|
4272 int vpos;
|
|
4273 new_point = vmotion (XWINDOW (window),
|
|
4274 marker_position (w->pointm[CURRENT_DISP]),
|
|
4275 XINT (arg), &vpos);
|
|
4276 Fset_window_point (window, make_int (new_point));
|
|
4277 return make_int (vpos);
|
|
4278 }
|
|
4279 }
|
|
4280
|
|
4281
|
|
4282 static int
|
|
4283 map_windows_1 (Lisp_Object window,
|
|
4284 int (*mapfun) (struct window *w, void *closure),
|
|
4285 void *closure)
|
|
4286 {
|
185
|
4287 int retval;
|
0
|
4288
|
|
4289 for (; !NILP (window); window = XWINDOW (window)->next)
|
|
4290 {
|
|
4291 struct window *w = XWINDOW (window);
|
251
|
4292
|
0
|
4293 if (!NILP (w->vchild))
|
|
4294 retval = map_windows_1 (w->vchild, mapfun, closure);
|
|
4295 else if (!NILP (w->hchild))
|
|
4296 retval = map_windows_1 (w->hchild, mapfun, closure);
|
|
4297 else
|
|
4298 retval = (mapfun) (w, closure);
|
|
4299 if (retval)
|
|
4300 return retval;
|
|
4301 }
|
|
4302
|
251
|
4303 return retval;
|
0
|
4304 }
|
|
4305
|
|
4306 /* Map MAPFUN over the windows in F. CLOSURE is passed to each
|
251
|
4307 invocation of MAPFUN. If any invocation of MAPFUN returns
|
|
4308 non-zero, the mapping is halted. Otherwise, map_windows() maps
|
|
4309 over all windows in F.
|
|
4310
|
|
4311 If MAPFUN create or delete windows, the behaviour is undefined. */
|
|
4312
|
|
4313 void
|
0
|
4314 map_windows (struct frame *f, int (*mapfun) (struct window *w, void *closure),
|
|
4315 void *closure)
|
|
4316 {
|
251
|
4317 if (f)
|
|
4318 map_windows_1 (FRAME_ROOT_WINDOW (f), mapfun, closure);
|
|
4319 else
|
|
4320 {
|
|
4321 Lisp_Object frmcons, devcons, concons;
|
|
4322
|
|
4323 FRAME_LOOP_NO_BREAK(frmcons, devcons, concons)
|
|
4324 {
|
|
4325 if (map_windows_1 (FRAME_ROOT_WINDOW (XFRAME (XCAR (frmcons))),
|
|
4326 mapfun, closure))
|
|
4327 return;
|
|
4328 }
|
|
4329 }
|
0
|
4330 }
|
|
4331
|
|
4332
|
|
4333 static void
|
|
4334 modeline_shadow_thickness_changed (Lisp_Object specifier, struct window *w,
|
|
4335 Lisp_Object oldval)
|
|
4336 {
|
|
4337 w->shadow_thickness_changed = 1;
|
|
4338 MARK_WINDOWS_CHANGED (w);
|
|
4339 }
|
|
4340
|
|
4341 /* also used in scrollbar.c */
|
|
4342 void
|
|
4343 some_window_value_changed (Lisp_Object specifier, struct window *w,
|
|
4344 Lisp_Object oldval)
|
|
4345 {
|
|
4346 MARK_WINDOWS_CHANGED (w);
|
|
4347 }
|
|
4348
|
|
4349 #ifdef MEMORY_USAGE_STATS
|
|
4350
|
|
4351 struct window_stats
|
|
4352 {
|
|
4353 int face;
|
|
4354 int glyph;
|
|
4355 #ifdef HAVE_SCROLLBARS
|
|
4356 int scrollbar;
|
|
4357 #endif
|
|
4358 int line_start;
|
|
4359 int other_redisplay;
|
|
4360 int other;
|
|
4361 };
|
|
4362
|
|
4363 static void
|
|
4364 compute_window_mirror_usage (struct window_mirror *mir,
|
|
4365 struct window_stats *stats,
|
|
4366 struct overhead_stats *ovstats)
|
|
4367 {
|
|
4368 if (!mir)
|
|
4369 return;
|
|
4370 stats->other += malloced_storage_size (mir, sizeof (struct window_mirror),
|
|
4371 ovstats);
|
|
4372 #ifdef HAVE_SCROLLBARS
|
|
4373 {
|
|
4374 struct device *d = XDEVICE (FRAME_DEVICE (mir->frame));
|
|
4375
|
|
4376 stats->scrollbar +=
|
|
4377 compute_scrollbar_instance_usage (d, mir->scrollbar_vertical_instance,
|
|
4378 ovstats);
|
|
4379 stats->scrollbar +=
|
|
4380 compute_scrollbar_instance_usage (d, mir->scrollbar_horizontal_instance,
|
|
4381 ovstats);
|
|
4382 }
|
149
|
4383 #endif /* HAVE_SCROLLBARS */
|
0
|
4384 stats->other_redisplay +=
|
|
4385 compute_display_line_dynarr_usage (mir->current_display_lines, ovstats);
|
|
4386 stats->other_redisplay +=
|
|
4387 compute_display_line_dynarr_usage (mir->desired_display_lines, ovstats);
|
|
4388 }
|
|
4389
|
|
4390 static void
|
|
4391 compute_window_usage (struct window *w, struct window_stats *stats,
|
|
4392 struct overhead_stats *ovstats)
|
|
4393 {
|
|
4394 memset (stats, 0, sizeof (*stats));
|
|
4395 stats->other += malloced_storage_size (w, sizeof (struct window), ovstats);
|
|
4396 stats->face += compute_face_cachel_usage (w->face_cachels, ovstats);
|
|
4397 stats->glyph += compute_glyph_cachel_usage (w->glyph_cachels, ovstats);
|
|
4398 stats->line_start +=
|
|
4399 compute_line_start_cache_dynarr_usage (w->line_start_cache, ovstats);
|
|
4400 compute_window_mirror_usage (find_window_mirror (w), stats, ovstats);
|
|
4401 }
|
|
4402
|
20
|
4403 DEFUN ("window-memory-usage", Fwindow_memory_usage, 1, 1, 0, /*
|
0
|
4404 Return stats about the memory usage of window WINDOW.
|
|
4405 The values returned are in the form an alist of usage types and byte
|
|
4406 counts. The byte counts attempt to encompass all the memory used
|
|
4407 by the window (separate from the memory logically associated with a
|
|
4408 buffer or frame), including internal structures and any malloc()
|
|
4409 overhead associated with them. In practice, the byte counts are
|
|
4410 underestimated because certain memory usage is very hard to determine
|
|
4411 (e.g. the amount of memory used inside the Xt library or inside the
|
|
4412 X server) and because there is other stuff that might logically
|
|
4413 be associated with a window, buffer, or frame (e.g. window configurations,
|
|
4414 glyphs) but should not obviously be included in the usage counts.
|
|
4415
|
|
4416 Multiple slices of the total memory usage may be returned, separated
|
|
4417 by a nil. Each slice represents a particular view of the memory, a
|
|
4418 particular way of partitioning it into groups. Within a slice, there
|
|
4419 is no overlap between the groups of memory, and each slice collectively
|
|
4420 represents all the memory concerned.
|
20
|
4421 */
|
|
4422 (window))
|
0
|
4423 {
|
|
4424 struct window_stats stats;
|
|
4425 struct overhead_stats ovstats;
|
|
4426
|
|
4427 CHECK_WINDOW (window); /* dead windows should be allowed, no? */
|
|
4428 memset (&ovstats, 0, sizeof (ovstats));
|
|
4429 compute_window_usage (XWINDOW (window), &stats, &ovstats);
|
|
4430
|
|
4431 return nconc2 (
|
|
4432 #ifdef HAVE_SCROLLBARS
|
|
4433 list6
|
|
4434 #else
|
|
4435 list5
|
|
4436 #endif
|
|
4437 (Fcons (Qface_cache, make_int (stats.face)),
|
|
4438 Fcons (Qglyph_cache, make_int (stats.glyph)),
|
|
4439 #ifdef HAVE_SCROLLBARS
|
|
4440 Fcons (Qscrollbar_instances, make_int (stats.scrollbar)),
|
|
4441 #endif
|
|
4442 Fcons (Qline_start_cache, make_int (stats.line_start)),
|
|
4443 Fcons (Qother_redisplay, make_int (stats.other_redisplay)),
|
|
4444 Fcons (Qother, make_int (stats.other))),
|
|
4445 list4 (Qnil,
|
|
4446 Fcons (Qactually_requested,
|
|
4447 make_int (ovstats.was_requested)),
|
|
4448 Fcons (Qmalloc_overhead,
|
|
4449 make_int (ovstats.malloc_overhead)),
|
|
4450 Fcons (Qdynarr_overhead,
|
|
4451 make_int (ovstats.dynarr_overhead))));
|
|
4452 }
|
|
4453
|
|
4454 #endif /* MEMORY_USAGE_STATS */
|
|
4455
|
|
4456
|
|
4457 /************************************************************************/
|
|
4458 /* Window configurations */
|
|
4459 /************************************************************************/
|
|
4460
|
|
4461 /* #### This window configuration stuff has had serious bugs lurking in it
|
|
4462 for years; it would be a -huge- win if this was reimplemented in lisp.
|
|
4463 */
|
|
4464
|
|
4465 /* If you add anything to this structure make sure saved_window_equal
|
|
4466 knows about it. */
|
|
4467 struct saved_window
|
|
4468 {
|
|
4469 Lisp_Object window; /* window */
|
|
4470 Lisp_Object buffer; /* buffer */
|
|
4471 Lisp_Object start; /* copied marker */
|
|
4472 Lisp_Object pointm; /* copied marker */
|
|
4473 Lisp_Object sb_point; /* copied marker */
|
|
4474 Lisp_Object mark; /* copied marker */
|
|
4475 int pixel_left;
|
|
4476 int pixel_top;
|
|
4477 int pixel_width;
|
|
4478 int pixel_height;
|
|
4479 int hscroll;
|
|
4480 int parent_index; /* index into saved_windows */
|
|
4481 int prev_index; /* index into saved_windows */
|
|
4482 Lisp_Object dedicated;
|
|
4483 char start_at_line_beg; /* boolean */
|
255
|
4484 Lisp_Object display_table;
|
|
4485 Lisp_Object modeline_shadow_thickness;
|
|
4486 Lisp_Object has_modeline_p;
|
|
4487 #ifdef HAVE_SCROLLBARS
|
|
4488 Lisp_Object scrollbar_width;
|
|
4489 Lisp_Object scrollbar_height;
|
|
4490 Lisp_Object scrollbar_pointer;
|
|
4491 #endif /* HAVE_SCROLLBARS */
|
|
4492 #ifdef HAVE_TOOLBARS
|
|
4493 Lisp_Object toolbar[4];
|
|
4494 Lisp_Object toolbar_size[4];
|
|
4495 Lisp_Object toolbar_border_width[4];
|
|
4496 Lisp_Object toolbar_visible_p[4];
|
|
4497 Lisp_Object toolbar_buttons_captioned_p;
|
|
4498 Lisp_Object default_toolbar;
|
|
4499 Lisp_Object default_toolbar_width, default_toolbar_height;
|
|
4500 Lisp_Object default_toolbar_visible_p;
|
|
4501 Lisp_Object default_toolbar_border_width;
|
|
4502 #endif /* HAVE_TOOLBARS */
|
|
4503 Lisp_Object left_margin_width, right_margin_width;
|
|
4504 Lisp_Object minimum_line_ascent, minimum_line_descent;
|
|
4505 Lisp_Object use_left_overflow, use_right_overflow;
|
|
4506 #ifdef HAVE_MENUBARS
|
|
4507 Lisp_Object menubar_visible_p;
|
|
4508 #endif /* HAVE_MENUBARS */
|
|
4509 Lisp_Object text_cursor_visible_p;
|
0
|
4510 };
|
|
4511
|
|
4512 /* If you add anything to this structure make sure window_config_equal
|
|
4513 knows about it. */
|
|
4514 struct window_config
|
|
4515 {
|
|
4516 struct lcrecord_header header;
|
|
4517 int frame_width;
|
|
4518 int frame_height;
|
|
4519 #if 0 /* FSFmacs */
|
|
4520 Lisp_Object selected_frame;
|
|
4521 #endif
|
|
4522 Lisp_Object current_window;
|
|
4523 Lisp_Object current_buffer;
|
|
4524 Lisp_Object minibuf_scroll_window;
|
|
4525 Lisp_Object root_window;
|
|
4526 /* Record the values of window-min-width and window-min-height
|
|
4527 so that window sizes remain consistent with them. */
|
|
4528 int min_width, min_height;
|
|
4529 int saved_windows_count;
|
|
4530 /* Zero-sized arrays aren't ANSI C */
|
|
4531 struct saved_window saved_windows[1];
|
|
4532 };
|
|
4533 #define SAVED_WINDOW_N(conf, n) (&((conf)->saved_windows[(n)]))
|
|
4534
|
|
4535 static Lisp_Object mark_window_config (Lisp_Object, void (*) (Lisp_Object));
|
|
4536 static void print_window_config (Lisp_Object, Lisp_Object, int);
|
|
4537 static unsigned int sizeof_window_config (CONST void *);
|
|
4538
|
|
4539 #define XWINDOW_CONFIGURATION(x) XRECORD (x, window_configuration, struct window_config)
|
|
4540 #define XSETWINDOW_CONFIGURATION(x, p) XSETRECORD (x, p, window_configuration)
|
|
4541 #define WINDOW_CONFIGURATIONP(x) RECORDP (x, window_configuration)
|
|
4542 #define GC_WINDOW_CONFIGURATIONP(x) GC_RECORDP (x, window_configuration)
|
|
4543 #define CHECK_WINDOW_CONFIGURATION(x) CHECK_RECORD (x, window_configuration)
|
|
4544
|
|
4545 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION ("window-configuration",
|
|
4546 window_configuration,
|
|
4547 mark_window_config,
|
185
|
4548 print_window_config,
|
0
|
4549 0, 0, 0, sizeof_window_config,
|
|
4550 struct window_config);
|
|
4551
|
|
4552 static Lisp_Object
|
|
4553 mark_window_config (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
4554 {
|
|
4555 struct window_config *config = XWINDOW_CONFIGURATION (obj);
|
|
4556 int i;
|
|
4557 ((markobj) (config->current_window));
|
|
4558 ((markobj) (config->current_buffer));
|
|
4559 ((markobj) (config->minibuf_scroll_window));
|
|
4560 ((markobj) (config->root_window));
|
217
|
4561
|
0
|
4562 for (i = 0; i < config->saved_windows_count; i++)
|
|
4563 {
|
|
4564 struct saved_window *s = SAVED_WINDOW_N (config, i);
|
|
4565 ((markobj) (s->window));
|
|
4566 ((markobj) (s->buffer));
|
|
4567 ((markobj) (s->start));
|
|
4568 ((markobj) (s->pointm));
|
|
4569 ((markobj) (s->sb_point));
|
|
4570 ((markobj) (s->mark));
|
|
4571 ((markobj) (s->dedicated));
|
|
4572 }
|
149
|
4573 return Qnil;
|
0
|
4574 }
|
|
4575
|
|
4576 static int
|
|
4577 sizeof_window_config_for_n_windows (int n)
|
|
4578 {
|
|
4579 return (sizeof (struct window_config) +
|
|
4580 /* n - 1 because zero-sized arrays aren't ANSI C */
|
|
4581 (n - 1) *sizeof (struct saved_window));
|
|
4582 }
|
|
4583
|
|
4584 static unsigned int
|
|
4585 sizeof_window_config (CONST void *h)
|
|
4586 {
|
185
|
4587 CONST struct window_config *c = (CONST struct window_config *) h;
|
0
|
4588 return sizeof_window_config_for_n_windows (c->saved_windows_count);
|
|
4589 }
|
|
4590
|
|
4591 static void
|
|
4592 print_window_config (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
4593 {
|
|
4594 struct window_config *config = XWINDOW_CONFIGURATION (obj);
|
|
4595 char buf[200];
|
|
4596 if (print_readably)
|
|
4597 error ("printing unreadable object #<window-configuration 0x%x>",
|
|
4598 config->header.uid);
|
|
4599 write_c_string ("#<window-configuration ", printcharfun);
|
|
4600 sprintf (buf, "0x%x>", config->header.uid);
|
|
4601 write_c_string (buf, printcharfun);
|
|
4602 }
|
|
4603
|
|
4604 /* Returns a boolean indicating whether the two saved windows are
|
|
4605 identical. */
|
|
4606 static int
|
|
4607 saved_window_equal (struct saved_window *win1, struct saved_window *win2)
|
|
4608 {
|
149
|
4609 return
|
|
4610 EQ (win1->window, win2->window) &&
|
|
4611 EQ (win1->buffer, win2->buffer) &&
|
195
|
4612 internal_equal (win1->start, win2->start, 0) &&
|
|
4613 internal_equal (win1->pointm, win2->pointm, 0) &&
|
|
4614 internal_equal (win1->sb_point, win2->sb_point, 0) &&
|
|
4615 internal_equal (win1->mark, win2->mark, 0) &&
|
149
|
4616 win1->pixel_left == win2->pixel_left &&
|
|
4617 win1->pixel_top == win2->pixel_top &&
|
|
4618 win1->pixel_width == win2->pixel_width &&
|
|
4619 win1->pixel_height == win2->pixel_height &&
|
|
4620 win1->hscroll == win2->hscroll &&
|
|
4621 win1->parent_index == win2->parent_index &&
|
|
4622 win1->prev_index == win2->prev_index &&
|
|
4623 EQ (win1->dedicated, win2->dedicated) &&
|
255
|
4624 win1->start_at_line_beg == win2->start_at_line_beg &&
|
|
4625 internal_equal(win1->display_table, win2->display_table, 0) &&
|
|
4626 EQ(win1->modeline_shadow_thickness, win2->modeline_shadow_thickness) &&
|
|
4627 EQ(win1->has_modeline_p, win2->has_modeline_p) &&
|
|
4628 #ifdef HAVE_SCROLLBARS
|
|
4629 EQ(win1->scrollbar_width, win2->scrollbar_width) &&
|
|
4630 EQ(win1->scrollbar_height, win2->scrollbar_height) &&
|
|
4631 EQ(win1->scrollbar_pointer, win2->scrollbar_pointer) &&
|
|
4632 #endif /* HAVE_SCROLLBARS */
|
|
4633 #ifdef HAVE_TOOLBARS
|
|
4634 internal_equal(win1->toolbar[0], win2->toolbar[0], 0) &&
|
|
4635 internal_equal(win1->toolbar[1], win2->toolbar[1], 0) &&
|
|
4636 internal_equal(win1->toolbar[2], win2->toolbar[2], 0) &&
|
|
4637 internal_equal(win1->toolbar[3], win2->toolbar[3], 0) &&
|
|
4638 internal_equal(win1->toolbar_border_width[0], win2->toolbar_border_width[0], 0) &&
|
|
4639 internal_equal(win1->toolbar_border_width[1], win2->toolbar_border_width[1], 0) &&
|
|
4640 internal_equal(win1->toolbar_border_width[2], win2->toolbar_border_width[2], 0) &&
|
|
4641 internal_equal(win1->toolbar_border_width[3], win2->toolbar_border_width[3], 0) &&
|
|
4642 internal_equal(win1->toolbar_size[0], win2->toolbar_size[0], 0) &&
|
|
4643 internal_equal(win1->toolbar_size[1], win2->toolbar_size[1], 0) &&
|
|
4644 internal_equal(win1->toolbar_size[2], win2->toolbar_size[2], 0) &&
|
|
4645 internal_equal(win1->toolbar_size[3], win2->toolbar_size[3], 0) &&
|
|
4646 internal_equal(win1->toolbar_visible_p[0], win2->toolbar_visible_p[0], 0) &&
|
|
4647 internal_equal(win1->toolbar_visible_p[1], win2->toolbar_visible_p[1], 0) &&
|
|
4648 internal_equal(win1->toolbar_visible_p[2], win2->toolbar_visible_p[2], 0) &&
|
|
4649 internal_equal(win1->toolbar_visible_p[3], win2->toolbar_visible_p[3], 0) &&
|
|
4650 EQ(win1->toolbar_buttons_captioned_p, win2->toolbar_buttons_captioned_p) &&
|
|
4651 internal_equal(win1->default_toolbar, win2->default_toolbar, 0) &&
|
|
4652 EQ(win1->default_toolbar_width, win2->default_toolbar_width) &&
|
|
4653 EQ(win1->default_toolbar_height, win2->default_toolbar_height) &&
|
|
4654 EQ(win1->default_toolbar_visible_p, win2->default_toolbar_visible_p) &&
|
|
4655 EQ(win1->default_toolbar_border_width, win2->default_toolbar_border_width) &&
|
|
4656 #endif /* HAVE_TOOLBARS */
|
|
4657 EQ(win1->left_margin_width, win2->left_margin_width) &&
|
|
4658 EQ(win1->right_margin_width, win2->right_margin_width) &&
|
|
4659 EQ(win1->minimum_line_ascent, win2->minimum_line_ascent) &&
|
|
4660 EQ(win1->minimum_line_descent, win2->minimum_line_descent) &&
|
|
4661 EQ(win1->use_left_overflow, win2->use_left_overflow) &&
|
|
4662 EQ(win1->use_right_overflow, win2->use_right_overflow) &&
|
|
4663 #ifdef HAVE_MENUBARS
|
|
4664 EQ(win1->menubar_visible_p, win2->menubar_visible_p) &&
|
|
4665 #endif /* HAVE_MENUBARS */
|
|
4666 EQ(win1->text_cursor_visible_p, win2->text_cursor_visible_p);
|
0
|
4667 }
|
|
4668
|
|
4669 /* Returns a boolean indicating whether the two given configurations
|
|
4670 are identical. */
|
|
4671 static int
|
|
4672 window_config_equal (Lisp_Object conf1, Lisp_Object conf2)
|
|
4673 {
|
|
4674 struct window_config *fig1, *fig2;
|
|
4675 int i;
|
|
4676
|
|
4677 /* First check if they are truly the same. */
|
|
4678 if (EQ (conf1, conf2))
|
|
4679 return 1;
|
|
4680
|
|
4681 fig1 = XWINDOW_CONFIGURATION (conf1);
|
|
4682 fig2 = XWINDOW_CONFIGURATION (conf2);
|
|
4683
|
149
|
4684 if (!((fig1->saved_windows_count == fig2->saved_windows_count) &&
|
|
4685 EQ (fig1->current_window, fig2->current_window) &&
|
|
4686 EQ (fig1->current_buffer, fig2->current_buffer) &&
|
|
4687 EQ (fig1->root_window, fig2->root_window) &&
|
|
4688 EQ (fig1->minibuf_scroll_window, fig2->minibuf_scroll_window) &&
|
|
4689 fig1->frame_width == fig2->frame_width &&
|
|
4690 fig1->frame_height == fig2->frame_height))
|
0
|
4691 return 0;
|
|
4692
|
|
4693 for (i = 0; i < fig1->saved_windows_count; i++)
|
|
4694 {
|
|
4695 if (!saved_window_equal (SAVED_WINDOW_N (fig1, i),
|
|
4696 SAVED_WINDOW_N (fig2, i)))
|
|
4697 return 0;
|
|
4698 }
|
|
4699
|
|
4700 return 1;
|
|
4701 }
|
|
4702
|
20
|
4703 DEFUN ("window-configuration-p", Fwindow_configuration_p, 1, 1, 0, /*
|
0
|
4704 T if OBJECT is a window-configuration object.
|
20
|
4705 */
|
|
4706 (obj))
|
0
|
4707 {
|
149
|
4708 return WINDOW_CONFIGURATIONP (obj) ? Qt : Qnil;
|
0
|
4709 }
|
|
4710
|
251
|
4711 static int
|
|
4712 mark_windows_in_use_closure (struct window *w, void *closure)
|
0
|
4713 {
|
251
|
4714 int mark = *(int *)closure;
|
|
4715 w->config_mark = mark;
|
|
4716 return 0;
|
|
4717 }
|
|
4718
|
|
4719 static void
|
|
4720 mark_windows_in_use (struct frame *f, int mark)
|
|
4721 {
|
|
4722 map_windows (f, mark_windows_in_use_closure, &mark);
|
0
|
4723 }
|
|
4724
|
|
4725 /* Lisp_Object return value so it can be used in record_unwind_protect() */
|
|
4726 static Lisp_Object
|
|
4727 free_window_configuration (Lisp_Object window_config)
|
|
4728 {
|
|
4729 int i;
|
|
4730 struct window_config *config = XWINDOW_CONFIGURATION (window_config);
|
|
4731
|
|
4732 /* Free all the markers. It's not completely necessary that
|
|
4733 we do this (window configs sitting in a free list aren't
|
|
4734 marked normally so the markers wouldn't be marked anyway)
|
|
4735 but it's more efficient. */
|
|
4736 for (i = 0; i < config->saved_windows_count; i++)
|
|
4737 {
|
|
4738 struct saved_window *p = SAVED_WINDOW_N (config, i);
|
|
4739
|
|
4740 if (!NILP (p->pointm))
|
|
4741 {
|
|
4742 free_marker (XMARKER (p->pointm));
|
|
4743 p->pointm = Qnil;
|
|
4744 }
|
|
4745 if (!NILP (p->start))
|
|
4746 {
|
|
4747 free_marker (XMARKER (p->start));
|
|
4748 p->start = Qnil;
|
|
4749 }
|
|
4750 if (!NILP (p->sb_point))
|
|
4751 {
|
|
4752 free_marker (XMARKER (p->sb_point));
|
|
4753 p->sb_point = Qnil;
|
|
4754 }
|
|
4755 if (!NILP (p->mark))
|
|
4756 {
|
|
4757 free_marker (XMARKER (p->mark));
|
|
4758 p->mark = Qnil;
|
|
4759 }
|
|
4760 }
|
|
4761
|
|
4762 if (config->saved_windows_count <= countof (Vwindow_configuration_free_list))
|
|
4763 free_managed_lcrecord (Vwindow_configuration_free_list
|
|
4764 [config->saved_windows_count - 1],
|
|
4765 window_config);
|
|
4766
|
|
4767 return Qnil;
|
|
4768 }
|
|
4769
|
20
|
4770 DEFUN ("set-window-configuration", Fset_window_configuration, 1, 1, 0, /*
|
0
|
4771 Set the configuration of windows and buffers as specified by CONFIGURATION.
|
|
4772 CONFIGURATION must be a value previously returned
|
|
4773 by `current-window-configuration' (which see).
|
20
|
4774 */
|
|
4775 (configuration))
|
0
|
4776 {
|
|
4777 struct window *w;
|
|
4778 struct window_config *config;
|
|
4779 struct saved_window *p;
|
|
4780 Lisp_Object new_current_buffer;
|
|
4781 int k;
|
|
4782 Lisp_Object frame;
|
|
4783 struct frame *f;
|
|
4784 struct gcpro gcpro1;
|
|
4785 Lisp_Object old_window_config;
|
|
4786 int previous_frame_height;
|
|
4787 int previous_frame_width;
|
|
4788 int specpdl_count = specpdl_depth ();
|
|
4789
|
|
4790 GCPRO1 (configuration);
|
|
4791
|
|
4792 CHECK_WINDOW_CONFIGURATION (configuration);
|
|
4793 config = XWINDOW_CONFIGURATION (configuration);
|
|
4794
|
|
4795 frame = XWINDOW (SAVED_WINDOW_N (config, 0)->window)->frame;
|
|
4796 f = XFRAME (frame);
|
|
4797
|
|
4798 /* Do not signal an error here if the frame was deleted. There are
|
|
4799 reasonable cases where we could get here with a deleted frame and
|
|
4800 just want to do close to nothing instead. */
|
|
4801
|
|
4802 if (FRAME_LIVE_P (f))
|
|
4803 {
|
|
4804 /* restore the frame characteristics */
|
185
|
4805
|
0
|
4806 new_current_buffer = config->current_buffer;
|
|
4807 if (!BUFFER_LIVE_P (XBUFFER (new_current_buffer)))
|
|
4808 new_current_buffer = Qnil;
|
|
4809
|
|
4810 /*
|
|
4811 * Assumed precondition: w->config_mark = 0 for all w
|
|
4812 * This procedure should ensure this is true by the time it exits
|
|
4813 * to ensure the precondition for future calls.
|
|
4814 *
|
|
4815 * We use w->config_mark to know whether we're modifying a
|
|
4816 * window that is currently visible on the frame (#### we
|
|
4817 * should just be able to check whether the window is dead
|
|
4818 * or not, but this way is safer?). As we process each
|
|
4819 * window, we set its config_mark to 0. At the end, we
|
|
4820 * go through all the windows that used to be on the frame,
|
|
4821 * set each one's config_mark to 0 (to maintain the
|
|
4822 * assumed precondition) and delete each one that's no
|
|
4823 * longer in use.
|
|
4824 *
|
|
4825 * #### Using a window-configuration to keep track of
|
|
4826 * the current windows is wasteful. All we need is the
|
|
4827 * list of windows, so we could just use a dynarr.
|
|
4828 */
|
|
4829 old_window_config = Fcurrent_window_configuration (frame);
|
|
4830
|
|
4831 /* If the new configuration is already equal to the old, then stop
|
|
4832 right here. This saves the work below and it also saves
|
|
4833 triggering a full redisplay of this window. This is a huge win
|
|
4834 when using the mouse since the mode motion code uses
|
|
4835 save-window-excursion extensively but will rarely cause the
|
|
4836 configuration to actually change. */
|
|
4837 if (window_config_equal (configuration, old_window_config))
|
|
4838 {
|
|
4839 free_window_configuration (old_window_config);
|
|
4840 UNGCPRO;
|
|
4841 return Qnil;
|
|
4842 }
|
|
4843
|
|
4844 /* We can't quit or even check for quit because that may cause
|
|
4845 investigation of the frame state, which may crash if the frame is
|
|
4846 in an inconsistent state. */
|
|
4847 begin_dont_check_for_quit ();
|
|
4848 record_unwind_protect (free_window_configuration, old_window_config);
|
|
4849
|
251
|
4850 mark_windows_in_use (f, 1);
|
0
|
4851
|
|
4852 previous_frame_width = FRAME_WIDTH (f);
|
|
4853 previous_frame_height = FRAME_HEIGHT (f);
|
|
4854 /* If the frame has been resized since this window configuration was
|
|
4855 made, we change the frame to the size specified in the
|
|
4856 configuration, restore the configuration, and then resize it
|
|
4857 back. We keep track of the prevailing height in these variables. */
|
|
4858 if (config->frame_height != FRAME_HEIGHT (f)
|
|
4859 || config->frame_width != FRAME_WIDTH (f))
|
|
4860 change_frame_size (f, config->frame_height, config->frame_width, 0);
|
|
4861
|
|
4862 /* Temporarily avoid any problems with windows that are smaller
|
|
4863 than they are supposed to be. */
|
|
4864 window_min_height = 1;
|
|
4865 window_min_width = 1;
|
|
4866
|
|
4867 /* OK, now restore all the windows in the window config.
|
|
4868 This may involve "undeleting" windows, since the
|
|
4869 windows in the window config may be deleted.
|
|
4870 */
|
|
4871 for (k = 0; k < config->saved_windows_count; k++)
|
|
4872 {
|
|
4873 p = SAVED_WINDOW_N (config, k);
|
|
4874 w = XWINDOW (p->window);
|
|
4875 w->next = Qnil;
|
|
4876
|
|
4877 /* The window might be dead. In this case, its redisplay
|
|
4878 structures were freed, so we need to reallocate them. */
|
|
4879 if (!w->face_cachels)
|
|
4880 {
|
185
|
4881 w->face_cachels = Dynarr_new (face_cachel);
|
0
|
4882 reset_face_cachels (w);
|
|
4883 }
|
|
4884 if (!w->glyph_cachels)
|
185
|
4885 w->glyph_cachels = Dynarr_new (glyph_cachel);
|
0
|
4886 if (!w->line_start_cache)
|
185
|
4887 w->line_start_cache = Dynarr_new (line_start_cache);
|
0
|
4888 w->dead = 0;
|
|
4889
|
|
4890 if (p->parent_index >= 0)
|
|
4891 w->parent = SAVED_WINDOW_N (config, p->parent_index)->window;
|
|
4892 else
|
|
4893 w->parent = Qnil;
|
|
4894
|
|
4895 if (p->prev_index >= 0)
|
|
4896 {
|
|
4897 w->prev = SAVED_WINDOW_N (config, p->prev_index)->window;
|
|
4898
|
|
4899 /* This is true for a minibuffer-only frame. */
|
|
4900 if (!NILP (w->mini_p) && EQ (w->prev, p->window))
|
|
4901 w->next = Qnil;
|
|
4902 else
|
|
4903 XWINDOW (w->prev)->next = p->window;
|
|
4904 }
|
|
4905 else
|
|
4906 {
|
|
4907 w->prev = Qnil;
|
|
4908 if (!NILP (w->parent))
|
|
4909 {
|
|
4910 if (WINDOW_WIDTH (p) == WINDOW_WIDTH (XWINDOW (w->parent)))
|
|
4911 {
|
|
4912 XWINDOW (w->parent)->vchild = p->window;
|
|
4913 XWINDOW (w->parent)->hchild = Qnil;
|
|
4914 }
|
|
4915 else
|
|
4916 {
|
|
4917 XWINDOW (w->parent)->hchild = p->window;
|
|
4918 XWINDOW (w->parent)->vchild = Qnil;
|
|
4919 }
|
|
4920 }
|
|
4921 }
|
|
4922 if (!w->config_mark)
|
|
4923 {
|
|
4924 /* #### This should be equivalent to the window previously
|
|
4925 having been dead. If we're brave, we'll put in an
|
|
4926 assertion to this effect. */
|
|
4927 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
4928 }
|
|
4929 else /* if (!EQ (w->buffer, p->buffer)) */
|
|
4930 {
|
|
4931 /* With the new redisplay we let it know that a change has
|
|
4932 been made and it will take care of the rest. If we don't
|
|
4933 tell it something has possibly changed it could lead to
|
|
4934 incorrect display. */
|
|
4935 MARK_WINDOWS_CHANGED (w);
|
|
4936 }
|
|
4937
|
|
4938 WINDOW_LEFT (w) = WINDOW_LEFT (p);
|
|
4939 WINDOW_TOP (w) = WINDOW_TOP (p);
|
|
4940 WINDOW_WIDTH (w) = WINDOW_WIDTH (p);
|
|
4941 WINDOW_HEIGHT (w) = WINDOW_HEIGHT (p);
|
|
4942 w->hscroll = p->hscroll;
|
255
|
4943 w->display_table = p->display_table;
|
|
4944 w->modeline_shadow_thickness = p->modeline_shadow_thickness;
|
|
4945 w->has_modeline_p = p->has_modeline_p;
|
|
4946 #ifdef HAVE_SCROLLBARS
|
|
4947 w->scrollbar_width = p->scrollbar_width;
|
|
4948 w->scrollbar_height = p->scrollbar_height;
|
|
4949 w->scrollbar_pointer = p->scrollbar_pointer;
|
|
4950 #endif /* HAVE_SCROLLBARS */
|
|
4951 #ifdef HAVE_TOOLBARS
|
|
4952 {
|
|
4953 int ix;
|
|
4954 for (ix = 0; ix < 4; ix++)
|
|
4955 {
|
|
4956 w->toolbar[ix] = p->toolbar[ix];
|
|
4957 w->toolbar_size[ix] = p->toolbar_size[ix];
|
|
4958 w->toolbar_border_width[ix] = p->toolbar_border_width[ix];
|
|
4959 w->toolbar_visible_p[ix] = p->toolbar_visible_p[ix];
|
|
4960 }
|
|
4961 }
|
|
4962 w->toolbar_buttons_captioned_p = p->toolbar_buttons_captioned_p;
|
|
4963 w->default_toolbar = p->default_toolbar;
|
|
4964 w->default_toolbar_width = p->default_toolbar_width;
|
|
4965 w->default_toolbar_visible_p = p->default_toolbar_visible_p;
|
|
4966 w->default_toolbar_border_width = p->default_toolbar_border_width;
|
|
4967 #endif /* HAVE_TOOLBARS */
|
|
4968 w->left_margin_width = p->left_margin_width;
|
|
4969 w->right_margin_width = p->right_margin_width;
|
|
4970 w->minimum_line_ascent = p->minimum_line_ascent;
|
|
4971 w->minimum_line_descent = p->minimum_line_descent;
|
|
4972 w->use_left_overflow = p->use_left_overflow;
|
|
4973 w->use_right_overflow = p->use_right_overflow;
|
|
4974 #ifdef HAVE_MENUBARS
|
|
4975 w->menubar_visible_p = p->menubar_visible_p;
|
|
4976 #endif /* HAVE_MENUBARS */
|
|
4977 w->text_cursor_visible_p = p->text_cursor_visible_p;
|
0
|
4978 w->dedicated = p->dedicated;
|
|
4979 w->line_cache_last_updated = Qzero;
|
|
4980 SET_LAST_MODIFIED (w, 1);
|
|
4981 SET_LAST_FACECHANGE (w);
|
|
4982 w->config_mark = 0;
|
|
4983
|
|
4984 /* Reinstall the saved buffer and pointers into it. */
|
|
4985 if (NILP (p->buffer))
|
|
4986 w->buffer = p->buffer;
|
|
4987 else
|
|
4988 {
|
|
4989 if (BUFFER_LIVE_P (XBUFFER (p->buffer)))
|
|
4990 /* If saved buffer is alive, install it. */
|
|
4991 {
|
|
4992 w->buffer = p->buffer;
|
|
4993 w->start_at_line_beg = p->start_at_line_beg;
|
|
4994 set_marker_restricted (w->start[CURRENT_DISP],
|
|
4995 Fmarker_position (p->start),
|
|
4996 w->buffer);
|
|
4997 set_marker_restricted (w->pointm[CURRENT_DISP],
|
|
4998 Fmarker_position (p->pointm),
|
|
4999 w->buffer);
|
|
5000 set_marker_restricted (w->sb_point,
|
|
5001 Fmarker_position (p->sb_point),
|
|
5002 w->buffer);
|
|
5003 Fset_marker (XBUFFER (w->buffer)->mark,
|
|
5004 Fmarker_position (p->mark), w->buffer);
|
|
5005
|
|
5006 /* As documented in Fcurrent_window_configuration, don't
|
|
5007 save the location of point in the buffer which was current
|
|
5008 when the window configuration was recorded. */
|
|
5009 if (!EQ (p->buffer, new_current_buffer) &&
|
|
5010 XBUFFER (p->buffer) == current_buffer)
|
223
|
5011 Fgoto_char (w->pointm[CURRENT_DISP], Qnil);
|
0
|
5012 }
|
|
5013 else if (NILP (w->buffer) ||
|
|
5014 !BUFFER_LIVE_P (XBUFFER (w->buffer)))
|
|
5015 /* Else if window's old buffer is dead too, get a live one. */
|
|
5016 {
|
|
5017 /* #### The following line makes me nervous... */
|
|
5018 /* w->buffer = Fcdr (Fcar (XFRAME (w->frame)->buffer_alist));*/
|
|
5019 w->buffer = Fget_buffer_create (QSscratch);
|
|
5020 /* w->buffer = Fother_buffer (Qnil, w->frame, Qnil); */
|
|
5021 /* This will set the markers to beginning of visible
|
|
5022 range. */
|
|
5023 set_marker_restricted (w->start[CURRENT_DISP], Qzero, w->buffer);
|
|
5024 set_marker_restricted (w->pointm[CURRENT_DISP], Qzero,
|
|
5025 w->buffer);
|
|
5026 set_marker_restricted (w->sb_point, Qzero, w->buffer);
|
|
5027 w->start_at_line_beg = 1;
|
|
5028 }
|
|
5029 else
|
|
5030 /* Keeping window's old buffer; make sure the markers
|
|
5031 are real. */
|
|
5032 {
|
|
5033 /* Set window markers at start of visible range. */
|
|
5034 if (XMARKER (w->start[CURRENT_DISP])->buffer == 0)
|
|
5035 set_marker_restricted (w->start[CURRENT_DISP], Qzero,
|
|
5036 w->buffer);
|
|
5037 if (XMARKER (w->sb_point)->buffer == 0)
|
|
5038 set_marker_restricted (w->sb_point, Qzero, w->buffer);
|
|
5039 if (XMARKER (w->pointm[CURRENT_DISP])->buffer == 0)
|
|
5040 set_marker_restricted (w->pointm[CURRENT_DISP],
|
|
5041 make_int
|
|
5042 (BUF_PT (XBUFFER (w->buffer))),
|
|
5043 w->buffer);
|
|
5044 w->start_at_line_beg = 1;
|
|
5045 }
|
|
5046 }
|
|
5047 }
|
|
5048
|
|
5049 FRAME_ROOT_WINDOW (f) = config->root_window;
|
|
5050 /* Note that FSFmacs unilaterally calls Fselect_window() here, and
|
|
5051 then calls do_switch_frame() below to select the frame that was
|
|
5052 recorded in the window config as being selected.
|
|
5053
|
|
5054 Instead, we don't ever change the selected frame, and either
|
|
5055 call Fselect_window() below if the window config's frame is
|
|
5056 currently selected, or just set the selected window of the
|
|
5057 window config's frame. */
|
|
5058
|
|
5059 /* Set the frame height to the value it had before this function. */
|
|
5060 if (previous_frame_height != FRAME_HEIGHT (f)
|
|
5061 || previous_frame_width != FRAME_WIDTH (f))
|
|
5062 change_frame_size (f, previous_frame_height, previous_frame_width, 0);
|
|
5063
|
|
5064 /* If restoring in the current frame make the window current,
|
|
5065 otherwise just update the frame selected_window slot to be
|
|
5066 the restored current_window. */
|
|
5067 if (f == selected_frame ())
|
|
5068 {
|
|
5069 /* When using `pop-window-configuration', often the minibuffer
|
|
5070 ends up as the selected window even though it's not active ...
|
|
5071 I really don't know the cause of this, but it should never
|
|
5072 happen. This kludge should fix it.
|
|
5073
|
|
5074 #### Find out why this is really going wrong. */
|
|
5075 if (!minibuf_level &&
|
|
5076 MINI_WINDOW_P (XWINDOW (config->current_window)))
|
|
5077 Fselect_window (Fnext_window (config->current_window,
|
|
5078 Qnil, Qnil, Qnil));
|
|
5079 else
|
|
5080 Fselect_window (config->current_window);
|
|
5081 if (!NILP (new_current_buffer))
|
|
5082 Fset_buffer (new_current_buffer);
|
|
5083 else
|
|
5084 Fset_buffer (XWINDOW (Fselected_window (Qnil))->buffer);
|
|
5085 }
|
|
5086 else
|
|
5087 set_frame_selected_window (f, config->current_window);
|
|
5088 }
|
173
|
5089 else
|
|
5090 old_window_config = Qnil; /* Warning suppression */
|
0
|
5091
|
|
5092 /* Restore the minimum heights recorded in the configuration. */
|
|
5093 window_min_height = config->min_height;
|
|
5094 window_min_width = config->min_width;
|
|
5095
|
|
5096 #if 0 /* FSFmacs */
|
|
5097 /* see above comment */
|
|
5098 /* Fselect_window will have made f the selected frame, so we
|
|
5099 reselect the proper frame here. Fhandle_switch_frame will change the
|
|
5100 selected window too, but that doesn't make the call to
|
|
5101 Fselect_window above totally superfluous; it still sets f's
|
|
5102 selected window. */
|
|
5103 if (FRAME_LIVE_P (XFRAME (config->selected_frame)))
|
|
5104 do_switch_frame (config->selected_frame, Qnil, 0);
|
|
5105 #endif
|
|
5106
|
|
5107 Vminibuf_scroll_window = config->minibuf_scroll_window;
|
|
5108
|
|
5109 if (FRAME_LIVE_P (f))
|
|
5110 {
|
|
5111 /* Do this before calling recompute_all_cached_specifiers_in_window()
|
|
5112 so that things like redisplay_redraw_cursor() won't abort due
|
|
5113 to no window mirror present. */
|
|
5114 f->mirror_dirty = 1;
|
|
5115
|
|
5116 config = XWINDOW_CONFIGURATION (old_window_config);
|
|
5117 for (k = 0; k < config->saved_windows_count; k++)
|
|
5118 {
|
|
5119 p = SAVED_WINDOW_N (config, k);
|
|
5120 w = XWINDOW (p->window);
|
|
5121 /* Remember, we set w->config_mark on all currently visible
|
|
5122 windows, and reset it on all newly visible windows.
|
|
5123 Any windows still marked need to be deleted. */
|
|
5124 if (w->config_mark)
|
|
5125 {
|
|
5126 mark_window_as_deleted (w);
|
|
5127 w->config_mark = 0;
|
|
5128 }
|
|
5129 else
|
|
5130 {
|
|
5131 /* We just potentially changed the window's buffer and
|
|
5132 potentially turned a dead window into a live one,
|
|
5133 so we need to recompute the cached specifier values. */
|
|
5134 recompute_all_cached_specifiers_in_window (w);
|
|
5135 }
|
|
5136 }
|
|
5137 }
|
|
5138
|
|
5139 /* Now restore things, when everything else if OK. */
|
|
5140
|
|
5141 unbind_to (specpdl_count, Qnil);
|
|
5142
|
|
5143 UNGCPRO;
|
|
5144
|
149
|
5145 return Qnil;
|
0
|
5146 }
|
|
5147
|
|
5148 /* Mark all subwindows of a window as deleted. The argument
|
|
5149 W is actually the subwindow tree of the window in question. */
|
|
5150
|
|
5151 void
|
|
5152 delete_all_subwindows (struct window *w)
|
|
5153 {
|
|
5154 if (!NILP (w->next))
|
|
5155 delete_all_subwindows (XWINDOW (w->next));
|
|
5156 if (!NILP (w->vchild))
|
|
5157 delete_all_subwindows (XWINDOW (w->vchild));
|
|
5158 if (!NILP (w->hchild))
|
|
5159 delete_all_subwindows (XWINDOW (w->hchild));
|
|
5160
|
|
5161 mark_window_as_deleted (w);
|
|
5162 }
|
|
5163
|
|
5164
|
|
5165 static int
|
|
5166 count_windows (struct window *window)
|
|
5167 {
|
|
5168 int count = 1;
|
|
5169 if (!NILP (window->next))
|
|
5170 count += count_windows (XWINDOW (window->next));
|
|
5171 if (!NILP (window->vchild))
|
|
5172 count += count_windows (XWINDOW (window->vchild));
|
|
5173 if (!NILP (window->hchild))
|
|
5174 count += count_windows (XWINDOW (window->hchild));
|
|
5175 return count;
|
|
5176 }
|
|
5177
|
|
5178 static int
|
|
5179 saved_window_index (Lisp_Object window, struct window_config *config, int lim)
|
|
5180 {
|
|
5181 int j;
|
|
5182 for (j = 0; j < lim; j++)
|
|
5183 {
|
|
5184 if (EQ (SAVED_WINDOW_N (config, j)->window, window))
|
149
|
5185 return j;
|
0
|
5186 }
|
|
5187 abort ();
|
|
5188 return 0; /* suppress compiler warning */
|
|
5189 }
|
|
5190
|
|
5191 static int
|
|
5192 save_window_save (Lisp_Object window, struct window_config *config, int i)
|
|
5193 {
|
|
5194 struct saved_window *p;
|
|
5195 struct window *w;
|
|
5196
|
|
5197 for (; !NILP (window); window = w->next)
|
|
5198 {
|
|
5199 p = SAVED_WINDOW_N (config, i);
|
|
5200 w = XWINDOW (window);
|
|
5201
|
|
5202 i++;
|
|
5203 p->window = window;
|
|
5204 p->buffer = w->buffer;
|
|
5205 WINDOW_LEFT (p) = WINDOW_LEFT (w);
|
|
5206 WINDOW_TOP (p) = WINDOW_TOP (w);
|
|
5207 WINDOW_WIDTH (p) = WINDOW_WIDTH (w);
|
|
5208 WINDOW_HEIGHT (p) = WINDOW_HEIGHT (w);
|
|
5209 p->hscroll = w->hscroll;
|
255
|
5210 p->display_table = w->display_table;
|
|
5211 p->modeline_shadow_thickness = w->modeline_shadow_thickness;
|
|
5212 p->has_modeline_p = w->has_modeline_p;
|
|
5213 #ifdef HAVE_SCROLLBARS
|
|
5214 p->scrollbar_width = w->scrollbar_width;
|
|
5215 p->scrollbar_height = w->scrollbar_height;
|
|
5216 p->scrollbar_pointer = w->scrollbar_pointer;
|
|
5217 #endif /* HAVE_SCROLLBARS */
|
|
5218 #ifdef HAVE_TOOLBARS
|
|
5219 {
|
|
5220 int ix;
|
|
5221 for (ix = 0; ix < 4; ix++)
|
|
5222 {
|
|
5223 p->toolbar[ix] = w->toolbar[ix];
|
|
5224 p->toolbar_size[ix] = w->toolbar_size[ix];
|
|
5225 p->toolbar_border_width[ix] = w->toolbar_border_width[ix];
|
|
5226 p->toolbar_visible_p[ix] = w->toolbar_visible_p[ix];
|
|
5227 }
|
|
5228 }
|
|
5229 p->toolbar_buttons_captioned_p = w->toolbar_buttons_captioned_p;
|
|
5230 p->default_toolbar = w->default_toolbar;
|
|
5231 p->default_toolbar_width = w->default_toolbar_width;
|
|
5232 p->default_toolbar_visible_p = w->default_toolbar_visible_p;
|
|
5233 p->default_toolbar_border_width = w->default_toolbar_border_width;
|
|
5234 #endif /* HAVE_TOOLBARS */
|
|
5235 p->left_margin_width = w->left_margin_width;
|
|
5236 p->right_margin_width = w->right_margin_width;
|
|
5237 p->minimum_line_ascent = w->minimum_line_ascent;
|
|
5238 p->minimum_line_descent = w->minimum_line_descent;
|
|
5239 p->use_left_overflow = w->use_left_overflow;
|
|
5240 p->use_right_overflow = w->use_right_overflow;
|
|
5241 #ifdef HAVE_MENUBARS
|
|
5242 p->menubar_visible_p = w->menubar_visible_p;
|
|
5243 #endif /* HAVE_MENUBARS */
|
|
5244 p->text_cursor_visible_p = w->text_cursor_visible_p;
|
|
5245
|
0
|
5246 if (!NILP (w->buffer))
|
|
5247 {
|
|
5248 /* Save w's value of point in the window configuration.
|
|
5249 If w is the selected window, then get the value of point
|
|
5250 from the buffer; pointm is garbage in the selected window. */
|
|
5251 if (EQ (window, Fselected_window (Qnil)))
|
|
5252 {
|
|
5253 p->pointm = noseeum_make_marker ();
|
|
5254 Fset_marker (p->pointm,
|
|
5255 make_int (BUF_PT (XBUFFER (w->buffer))),
|
|
5256 w->buffer);
|
|
5257 }
|
|
5258 else
|
|
5259 p->pointm = noseeum_copy_marker (w->pointm[CURRENT_DISP], Qnil);
|
|
5260
|
|
5261 p->start = noseeum_copy_marker (w->start[CURRENT_DISP], Qnil);
|
|
5262 p->sb_point = noseeum_copy_marker (w->sb_point, Qnil);
|
|
5263 p->start_at_line_beg = w->start_at_line_beg;
|
|
5264
|
|
5265 p->mark = noseeum_copy_marker (XBUFFER (w->buffer)->mark, Qnil);
|
|
5266 }
|
|
5267 else
|
|
5268 {
|
|
5269 p->pointm = Qnil;
|
|
5270 p->start = Qnil;
|
|
5271 p->sb_point = Qnil;
|
|
5272 p->mark = Qnil;
|
|
5273 p->start_at_line_beg = 0;
|
|
5274 }
|
|
5275
|
|
5276 if (NILP (w->parent))
|
|
5277 p->parent_index = -1;
|
|
5278 else
|
|
5279 p->parent_index = saved_window_index (w->parent, config, i);
|
|
5280 if (NILP (w->prev))
|
|
5281 p->prev_index = -1;
|
|
5282 else
|
|
5283 p->prev_index = saved_window_index (w->prev, config, i);
|
|
5284 p->dedicated = w->dedicated;
|
|
5285 if (!NILP (w->vchild))
|
|
5286 i = save_window_save (w->vchild, config, i);
|
|
5287 if (!NILP (w->hchild))
|
|
5288 i = save_window_save (w->hchild, config, i);
|
|
5289 }
|
|
5290
|
|
5291 return i;
|
|
5292 }
|
|
5293
|
|
5294 #if 0 /* FSFmacs */
|
|
5295 /* Added to doc string:
|
|
5296
|
|
5297 This also records the currently selected frame, and FRAME's focus
|
|
5298 redirection (see `redirect-frame-focus').
|
|
5299
|
|
5300 */
|
|
5301 #endif
|
|
5302
|
20
|
5303 DEFUN ("current-window-configuration", Fcurrent_window_configuration, 0, 1, 0, /*
|
0
|
5304 Return an object representing the current window configuration of FRAME.
|
|
5305 If FRAME is nil or omitted, use the selected frame.
|
|
5306 This describes the number of windows, their sizes and current buffers,
|
|
5307 and for each displayed buffer, where display starts, and the positions of
|
|
5308 point and mark. An exception is made for point in the current buffer:
|
|
5309 its value is -not- saved.
|
20
|
5310 */
|
|
5311 (frame))
|
0
|
5312 {
|
|
5313 Lisp_Object result = Qnil;
|
|
5314 struct frame *f;
|
|
5315 int n_windows;
|
|
5316
|
|
5317 struct window_config *config;
|
|
5318
|
|
5319 f = decode_frame (frame);
|
|
5320
|
|
5321 n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
|
|
5322 if (n_windows <= countof (Vwindow_configuration_free_list))
|
|
5323 config =
|
|
5324 XWINDOW_CONFIGURATION (allocate_managed_lcrecord
|
|
5325 (Vwindow_configuration_free_list
|
|
5326 [n_windows - 1]));
|
|
5327 else
|
|
5328 /* More than ten windows; just allocate directly */
|
185
|
5329 config = (struct window_config *)
|
|
5330 alloc_lcrecord (sizeof_window_config_for_n_windows (n_windows),
|
|
5331 lrecord_window_configuration);
|
0
|
5332 XSETWINDOW_CONFIGURATION (result, config);
|
|
5333
|
|
5334 config->frame_width = FRAME_WIDTH (f);
|
|
5335 config->frame_height = FRAME_HEIGHT (f);
|
|
5336 config->current_window = FRAME_SELECTED_WINDOW (f);
|
|
5337 XSETBUFFER (config->current_buffer, current_buffer);
|
|
5338 config->minibuf_scroll_window = Vminibuf_scroll_window;
|
|
5339 config->root_window = FRAME_ROOT_WINDOW (f);
|
|
5340 config->min_height = window_min_height;
|
|
5341 config->min_width = window_min_width;
|
|
5342 config->saved_windows_count = n_windows;
|
|
5343 save_window_save (FRAME_ROOT_WINDOW (f), config, 0);
|
149
|
5344 return result;
|
0
|
5345 }
|
|
5346
|
|
5347 Lisp_Object
|
|
5348 save_window_excursion_unwind (Lisp_Object window_config)
|
|
5349 {
|
|
5350 Lisp_Object val = Fset_window_configuration (window_config);
|
|
5351 free_window_configuration (window_config);
|
|
5352 return val;
|
|
5353 }
|
|
5354
|
20
|
5355 DEFUN ("save-window-excursion", Fsave_window_excursion, 0, UNEVALLED, 0, /*
|
0
|
5356 Execute body, preserving window sizes and contents.
|
|
5357 Restores which buffer appears in which window, where display starts,
|
|
5358 as well as the current buffer.
|
|
5359 Does not restore the value of point in current buffer.
|
20
|
5360 */
|
|
5361 (args))
|
0
|
5362 {
|
|
5363 /* This function can GC */
|
|
5364 Lisp_Object val;
|
|
5365 int speccount = specpdl_depth ();
|
|
5366
|
|
5367 record_unwind_protect (save_window_excursion_unwind,
|
|
5368 Fcurrent_window_configuration (Qnil));
|
|
5369 val = Fprogn (args);
|
|
5370 return unbind_to (speccount, val);
|
|
5371 }
|
|
5372
|
|
5373
|
|
5374 #ifdef DEBUG_XEMACS
|
|
5375 /* This is short and simple in elisp, but... it was written to debug
|
|
5376 problems purely on the C side. That is where we need to call it so
|
|
5377 here it is. */
|
|
5378 static void
|
|
5379 debug_print_window (Lisp_Object window, int level)
|
|
5380 {
|
|
5381 Lisp_Object child;
|
|
5382 int i = level;
|
|
5383
|
|
5384 child = Fwindow_first_vchild (window);
|
|
5385 if (NILP (child))
|
|
5386 child = Fwindow_first_hchild (window);
|
|
5387
|
|
5388 while (i > 0)
|
|
5389 {
|
|
5390 fprintf (stderr, "\t");
|
|
5391 i--;
|
|
5392 }
|
|
5393
|
|
5394 fprintf (stderr, "#<window");
|
|
5395 if (!NILP (XWINDOW (window)->buffer) && BUFFERP (XWINDOW (window)->buffer))
|
|
5396 {
|
|
5397 struct buffer *b = XBUFFER (XWINDOW (window)->buffer);
|
16
|
5398 fprintf (stderr, " on %s", XSTRING_DATA (b->name));
|
0
|
5399 }
|
|
5400 fprintf (stderr, " 0x%x>", XWINDOW (window)->header.uid);
|
|
5401
|
|
5402 while (!NILP (child))
|
|
5403 {
|
|
5404 debug_print_window (child, level + 1);
|
|
5405 child = Fwindow_next_child (child);
|
|
5406 }
|
|
5407 }
|
|
5408
|
|
5409 void debug_print_windows (struct frame *f);
|
|
5410 void
|
|
5411 debug_print_windows (struct frame *f)
|
|
5412 {
|
|
5413 debug_print_window (f->root_window, 0);
|
|
5414 fprintf (stderr, "\n");
|
|
5415 }
|
|
5416 #endif /* DEBUG_XEMACS */
|
|
5417
|
|
5418
|
|
5419 /************************************************************************/
|
|
5420 /* initialization */
|
|
5421 /************************************************************************/
|
|
5422
|
|
5423 void
|
|
5424 syms_of_window (void)
|
|
5425 {
|
|
5426 defsymbol (&Qwindowp, "windowp");
|
|
5427 defsymbol (&Qwindow_live_p, "window-live-p");
|
|
5428 defsymbol (&Qwindow_configurationp, "window-configuration-p");
|
|
5429 defsymbol (&Qscroll_up, "scroll-up");
|
|
5430 defsymbol (&Qscroll_down, "scroll-down");
|
|
5431 defsymbol (&Qtemp_buffer_show_hook, "temp-buffer-show-hook");
|
|
5432 defsymbol (&Qdisplay_buffer, "display-buffer");
|
|
5433
|
|
5434 #ifdef MEMORY_USAGE_STATS
|
|
5435 defsymbol (&Qface_cache, "face-cache");
|
|
5436 defsymbol (&Qglyph_cache, "glyph-cache");
|
|
5437 defsymbol (&Qline_start_cache, "line-start-cache");
|
|
5438 #ifdef HAVE_SCROLLBARS
|
|
5439 defsymbol (&Qscrollbar_instances, "scrollbar-instances");
|
|
5440 #endif
|
|
5441 defsymbol (&Qother_redisplay, "other-redisplay");
|
|
5442 /* Qother in general.c */
|
|
5443 #endif
|
|
5444
|
20
|
5445 DEFSUBR (Fselected_window);
|
|
5446 DEFSUBR (Fminibuffer_window);
|
|
5447 DEFSUBR (Fwindow_minibuffer_p);
|
|
5448 DEFSUBR (Fwindowp);
|
|
5449 DEFSUBR (Fwindow_live_p);
|
|
5450 DEFSUBR (Fwindow_first_hchild);
|
|
5451 DEFSUBR (Fwindow_first_vchild);
|
|
5452 DEFSUBR (Fwindow_next_child);
|
|
5453 DEFSUBR (Fwindow_previous_child);
|
|
5454 DEFSUBR (Fwindow_parent);
|
|
5455 DEFSUBR (Fwindow_lowest_p);
|
|
5456 DEFSUBR (Fwindow_highest_p);
|
|
5457 DEFSUBR (Fwindow_leftmost_p);
|
|
5458 DEFSUBR (Fwindow_rightmost_p);
|
|
5459 DEFSUBR (Fpos_visible_in_window_p);
|
|
5460 DEFSUBR (Fwindow_buffer);
|
|
5461 DEFSUBR (Fwindow_frame);
|
|
5462 DEFSUBR (Fwindow_height);
|
|
5463 DEFSUBR (Fwindow_displayed_height);
|
|
5464 DEFSUBR (Fwindow_width);
|
|
5465 DEFSUBR (Fwindow_pixel_height);
|
|
5466 DEFSUBR (Fwindow_pixel_width);
|
|
5467 DEFSUBR (Fwindow_hscroll);
|
251
|
5468 #if 0 /* bogus crock */
|
20
|
5469 DEFSUBR (Fwindow_redisplay_end_trigger);
|
|
5470 DEFSUBR (Fset_window_redisplay_end_trigger);
|
0
|
5471 #endif
|
20
|
5472 DEFSUBR (Fset_window_hscroll);
|
|
5473 DEFSUBR (Fwindow_pixel_edges);
|
|
5474 DEFSUBR (Fwindow_point);
|
|
5475 DEFSUBR (Fwindow_start);
|
|
5476 DEFSUBR (Fwindow_end);
|
|
5477 DEFSUBR (Fset_window_point);
|
|
5478 DEFSUBR (Fset_window_start);
|
|
5479 DEFSUBR (Fwindow_dedicated_p);
|
|
5480 DEFSUBR (Fset_window_dedicated_p);
|
|
5481 DEFSUBR (Fnext_window);
|
|
5482 DEFSUBR (Fprevious_window);
|
|
5483 DEFSUBR (Fnext_vertical_window);
|
|
5484 DEFSUBR (Fother_window);
|
|
5485 DEFSUBR (Fget_lru_window);
|
|
5486 DEFSUBR (Fget_largest_window);
|
|
5487 DEFSUBR (Fget_buffer_window);
|
|
5488 DEFSUBR (Fwindow_left_margin_pixel_width);
|
|
5489 DEFSUBR (Fwindow_right_margin_pixel_width);
|
|
5490 DEFSUBR (Fdelete_other_windows);
|
|
5491 DEFSUBR (Fdelete_windows_on);
|
|
5492 DEFSUBR (Freplace_buffer_in_windows);
|
|
5493 DEFSUBR (Fdelete_window);
|
|
5494 DEFSUBR (Fset_window_buffer);
|
|
5495 DEFSUBR (Fselect_window);
|
|
5496 DEFSUBR (Fsplit_window);
|
|
5497 DEFSUBR (Fenlarge_window);
|
|
5498 DEFSUBR (Fshrink_window);
|
|
5499 DEFSUBR (Fscroll_up);
|
|
5500 DEFSUBR (Fscroll_down);
|
|
5501 DEFSUBR (Fscroll_left);
|
|
5502 DEFSUBR (Fscroll_right);
|
|
5503 DEFSUBR (Fother_window_for_scrolling);
|
|
5504 DEFSUBR (Fscroll_other_window);
|
|
5505 DEFSUBR (Frecenter);
|
|
5506 DEFSUBR (Fmove_to_window_line);
|
0
|
5507 #ifdef MEMORY_USAGE_STATS
|
20
|
5508 DEFSUBR (Fwindow_memory_usage);
|
0
|
5509 #endif
|
20
|
5510 DEFSUBR (Fwindow_configuration_p);
|
|
5511 DEFSUBR (Fset_window_configuration);
|
|
5512 DEFSUBR (Fcurrent_window_configuration);
|
|
5513 DEFSUBR (Fsave_window_excursion);
|
0
|
5514 }
|
|
5515
|
|
5516 void
|
|
5517 vars_of_window (void)
|
|
5518 {
|
|
5519 /* Make sure all windows get marked */
|
|
5520 minibuf_window = Qnil;
|
|
5521 staticpro (&minibuf_window);
|
|
5522
|
|
5523 DEFVAR_BOOL ("scroll-on-clipped-lines", &scroll_on_clipped_lines /*
|
|
5524 *Non-nil means to scroll if point lands on a line which is clipped.
|
|
5525 */ );
|
|
5526 scroll_on_clipped_lines = 1;
|
|
5527
|
|
5528 DEFVAR_LISP ("temp-buffer-show-hook", &Vtemp_buffer_show_hook /*
|
|
5529 See `temp-buffer-show-function'.
|
|
5530 */ );
|
|
5531 Vtemp_buffer_show_hook = Qnil;
|
|
5532
|
|
5533 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function /*
|
|
5534 Non-nil means call as function to display a help buffer.
|
|
5535 The function is called with one argument, the buffer to be displayed.
|
|
5536 Used by `with-output-to-temp-buffer'.
|
|
5537 If this function is used, then it must do the entire job of showing
|
|
5538 the buffer; `temp-buffer-show-hook' is not run unless this function runs it.
|
|
5539 */ );
|
|
5540 Vtemp_buffer_show_function = Qnil;
|
|
5541
|
|
5542 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window /*
|
|
5543 Non-nil means it is the window that \\<minibuffer-local-map>\\[scroll-other-window] in minibuffer should scroll.
|
|
5544 */ );
|
|
5545 Vminibuf_scroll_window = Qnil;
|
|
5546
|
|
5547 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer /*
|
|
5548 If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window.
|
|
5549 */ );
|
|
5550 Vother_window_scroll_buffer = Qnil;
|
|
5551
|
|
5552 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines /*
|
|
5553 *Number of lines of continuity when scrolling by screenfuls.
|
|
5554 */ );
|
|
5555 next_screen_context_lines = 2;
|
|
5556
|
|
5557 DEFVAR_INT ("window-min-height", &window_min_height /*
|
|
5558 *Delete any window less than this tall (including its modeline).
|
|
5559 */ );
|
|
5560 window_min_height = 4;
|
|
5561
|
|
5562 DEFVAR_INT ("window-min-width", &window_min_width /*
|
|
5563 *Delete any window less than this wide.
|
|
5564 */ );
|
|
5565 window_min_width = 10;
|
|
5566
|
|
5567 {
|
|
5568 int i;
|
|
5569
|
|
5570 for (i = 0; i < countof (Vwindow_configuration_free_list); i++)
|
|
5571 {
|
|
5572 Vwindow_configuration_free_list[i] =
|
|
5573 make_lcrecord_list (sizeof_window_config_for_n_windows (i + 1),
|
|
5574 lrecord_window_configuration);
|
|
5575 staticpro (&Vwindow_configuration_free_list[i]);
|
|
5576 }
|
|
5577 }
|
|
5578 }
|
|
5579
|
|
5580 void
|
|
5581 specifier_vars_of_window (void)
|
|
5582 {
|
|
5583 DEFVAR_SPECIFIER ("modeline-shadow-thickness", &Vmodeline_shadow_thickness /*
|
|
5584 *How thick to draw 3D shadows around modelines.
|
|
5585 If this is set to 0, modelines will be the traditional 2D. Sizes above
|
|
5586 10 will be accepted but the maximum thickness that will be drawn is 10.
|
|
5587 This is a specifier; use `set-specifier' to change it.
|
|
5588 */ );
|
|
5589 Vmodeline_shadow_thickness = Fmake_specifier (Qinteger);
|
|
5590 /* The initial value for modeline-shadow-thickness is 2, but if the
|
|
5591 user removes all specifications we provide a fallback value of 0,
|
|
5592 which is probably what was expected. */
|
|
5593 set_specifier_fallback (Vmodeline_shadow_thickness,
|
|
5594 list1 (Fcons (Qnil, Qzero)));
|
|
5595 Fadd_spec_to_specifier (Vmodeline_shadow_thickness, make_int (2),
|
|
5596 Qnil, Qnil, Qnil);
|
|
5597 set_specifier_caching (Vmodeline_shadow_thickness,
|
|
5598 slot_offset (struct window,
|
|
5599 modeline_shadow_thickness),
|
|
5600 modeline_shadow_thickness_changed,
|
|
5601 0, 0);
|
185
|
5602
|
0
|
5603 DEFVAR_SPECIFIER ("has-modeline-p", &Vhas_modeline_p /*
|
|
5604 *Whether the modeline should be displayed.
|
|
5605 This is a specifier; use `set-specifier' to change it.
|
|
5606 */ );
|
|
5607 Vhas_modeline_p = Fmake_specifier (Qboolean);
|
|
5608 set_specifier_fallback (Vhas_modeline_p,
|
|
5609 list1 (Fcons (Qnil, Qt)));
|
|
5610 set_specifier_caching (Vhas_modeline_p,
|
|
5611 slot_offset (struct window,
|
|
5612 has_modeline_p),
|
|
5613 /* #### It's strange that we need a special
|
|
5614 flag to indicate that the shadow-thickness
|
|
5615 has changed, but not one to indicate that
|
|
5616 the modeline has been turned off or on. */
|
|
5617 some_window_value_changed,
|
|
5618 0, 0);
|
|
5619 }
|