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