X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/fabc1281e9cde34ff9a19d843316d2ceca8647ad..578098f346bf9e1f23ca86ed764fc00b035b427f:/src/window.c diff --git a/src/window.c b/src/window.c index 4d92566b24..86f86deedb 100644 --- a/src/window.c +++ b/src/window.c @@ -23,7 +23,6 @@ along with GNU Emacs. If not, see . */ #define WINDOW_INLINE EXTERN_INLINE #include -#include #include "lisp.h" #include "character.h" @@ -54,14 +53,14 @@ along with GNU Emacs. If not, see . */ #include "nsterm.h" #endif -Lisp_Object Qwindowp, Qwindow_live_p, Qwindow_valid_p; +Lisp_Object Qwindowp, Qwindow_live_p; +static Lisp_Object Qwindow_valid_p; static Lisp_Object Qwindow_configuration_p, Qrecord_window_buffer; static Lisp_Object Qwindow_deletable_p, Qdelete_window, Qdisplay_buffer; static Lisp_Object Qreplace_buffer_in_windows, Qget_mru_window; static Lisp_Object Qwindow_resize_root_window, Qwindow_resize_root_window_vertically; static Lisp_Object Qscroll_up, Qscroll_down, Qscroll_command; -static Lisp_Object Qsafe, Qabove, Qbelow; -static Lisp_Object Qauto_buffer_name, Qclone_of; +static Lisp_Object Qsafe, Qabove, Qbelow, Qtemp_buffer_resize, Qclone_of; static int displayed_window_lines (struct window *); static int count_windows (struct window *); @@ -175,11 +174,6 @@ wset_new_total (struct window *w, Lisp_Object val) w->new_total = val; } static inline void -wset_next_buffers (struct window *w, Lisp_Object val) -{ - w->next_buffers = val; -} -static inline void wset_normal_cols (struct window *w, Lisp_Object val) { w->normal_cols = val; @@ -200,11 +194,6 @@ wset_pointm (struct window *w, Lisp_Object val) w->pointm = val; } static inline void -wset_prev_buffers (struct window *w, Lisp_Object val) -{ - w->prev_buffers = val; -} -static inline void wset_right_fringe_width (struct window *w, Lisp_Object val) { w->right_fringe_width = val; @@ -268,7 +257,7 @@ decode_any_window (register Lisp_Object window) return w; } -struct window * +static struct window * decode_valid_window (register Lisp_Object window) { struct window *w; @@ -385,7 +374,7 @@ the first window of that frame. */) else if (! NILP (XWINDOW (window)->vchild)) window = XWINDOW (window)->vchild; else - abort (); + emacs_abort (); } return window; @@ -623,10 +612,10 @@ WINDOW are never \(re-)combined with WINDOW's siblings. */) DEFUN ("set-window-combination-limit", Fset_window_combination_limit, Sset_window_combination_limit, 2, 2, 0, doc: /* Set combination limit of window WINDOW to LIMIT; return LIMIT. WINDOW must be a valid window and defaults to the selected one. -If LIMIT is nil, child windows of WINDOW can be recombined with -WINDOW's siblings. LIMIT t means that child windows of WINDOW are -never \(re-)combined with WINDOW's siblings. Other values are reserved -for future use. */) +If LIMIT is nil, child windows of WINDOW can be recombined with WINDOW's +siblings. LIMIT t means that child windows of WINDOW are never +\(re-)combined with WINDOW's siblings. Other values are reserved for +future use. */) (Lisp_Object window, Lisp_Object limit) { wset_combination_limit (decode_valid_window (window), limit); @@ -1288,7 +1277,7 @@ If they are in the windows's left or right marginal areas, `left-margin'\n\ return Qnil; default: - abort (); + emacs_abort (); } } @@ -1865,23 +1854,23 @@ return value is a list of elements of the form (PARAMETER . VALUE). */) DEFUN ("window-parameter", Fwindow_parameter, Swindow_parameter, 2, 2, 0, doc: /* Return WINDOW's value for PARAMETER. -WINDOW must be a valid window and defaults to the selected one. */) +WINDOW can be any window and defaults to the selected one. */) (Lisp_Object window, Lisp_Object parameter) { Lisp_Object result; - result = Fassq (parameter, decode_valid_window (window)->window_parameters); + result = Fassq (parameter, decode_any_window (window)->window_parameters); return CDR_SAFE (result); } DEFUN ("set-window-parameter", Fset_window_parameter, Sset_window_parameter, 3, 3, 0, doc: /* Set WINDOW's value of PARAMETER to VALUE. -WINDOW must be a valid window and defaults to the selected one. +WINDOW can be any window and defaults to the selected one. Return VALUE. */) (Lisp_Object window, Lisp_Object parameter, Lisp_Object value) { - register struct window *w = decode_valid_window (window); + register struct window *w = decode_any_window (window); Lisp_Object old_alist_elt; old_alist_elt = Fassq (parameter, w->window_parameters); @@ -1947,7 +1936,7 @@ unshow_buffer (register struct window *w) buf = w->buffer; b = XBUFFER (buf); if (b != XMARKER (w->pointm)->buffer) - abort (); + emacs_abort (); #if 0 if (w == XWINDOW (selected_window) @@ -1968,6 +1957,9 @@ unshow_buffer (register struct window *w) is actually stored in that buffer, and the window's pointm isn't used. So don't clobber point in that buffer. */ if (! EQ (buf, XWINDOW (selected_window)->buffer) + /* Don't clobber point in current buffer either (this could be + useful in connection with bug#12208). + && XBUFFER (buf) != current_buffer */ /* This line helps to fix Horsley's testbug.el bug. */ && !(WINDOWP (BVAR (b, last_selected_window)) && w != XWINDOW (BVAR (b, last_selected_window)) @@ -2664,8 +2656,8 @@ window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frame /* Check for a window that has a killed buffer. */ case CHECK_ALL_WINDOWS: if (! NILP (w->buffer) - && NILP (BVAR (XBUFFER (w->buffer), name))) - abort (); + && !BUFFER_LIVE_P (XBUFFER (w->buffer))) + emacs_abort (); break; case WINDOW_LOOP_UNUSED: @@ -2827,7 +2819,7 @@ window-start value is reasonable when this function is called. */) } } - BLOCK_INPUT; + block_input (); if (!FRAME_INITIAL_P (f)) { Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); @@ -2969,7 +2961,7 @@ window-start value is reasonable when this function is called. */) } adjust_glyphs (f); - UNBLOCK_INPUT; + unblock_input (); run_window_configuration_change_hook (f); @@ -3097,7 +3089,7 @@ run_window_configuration_change_hook (struct frame *f) /* Use the right buffer. Matters when running the local hooks. */ if (current_buffer != XBUFFER (Fwindow_buffer (Qnil))) { - record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); + record_unwind_current_buffer (); Fset_buffer (Fwindow_buffer (Qnil)); } @@ -3134,7 +3126,7 @@ run_window_configuration_change_hook (struct frame *f) DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook, Srun_window_configuration_change_hook, 1, 1, 0, doc: /* Run `window-configuration-change-hook' for FRAME. */) - (Lisp_Object frame) + (Lisp_Object frame) { CHECK_LIVE_FRAME (frame); run_window_configuration_change_hook (XFRAME (frame)); @@ -3201,7 +3193,7 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int because that might itself be a local variable. */ if (window_initialized) { - record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); + record_unwind_current_buffer (); Fset_buffer (buffer); } @@ -3269,7 +3261,7 @@ This function runs `window-scroll-functions' before running XSETWINDOW (window, w); buffer = Fget_buffer (buffer_or_name); CHECK_BUFFER (buffer); - if (NILP (BVAR (XBUFFER (buffer), name))) + if (!BUFFER_LIVE_P (XBUFFER (buffer))) error ("Attempt to display deleted buffer"); tem = w->buffer; @@ -3334,7 +3326,7 @@ displaying that buffer. */) if (STRINGP (object)) object = Fget_buffer (object); - if (BUFFERP (object) && !NILP (BVAR (XBUFFER (object), name))) + if (BUFFERP (object) && BUFFER_LIVE_P (XBUFFER (object))) { /* Walk all windows looking for buffer, and force update of each of those windows. */ @@ -3469,6 +3461,10 @@ make_window (void) wset_vertical_scroll_bar_type (w, Qt); wset_window_end_pos (w, make_number (0)); wset_window_end_vpos (w, make_number (0)); + /* These Lisp fields are marked specially so they're not set to nil by + allocate_window. */ + wset_prev_buffers (w, Qnil); + wset_next_buffers (w, Qnil); /* Initialize non-Lisp data. Note that allocate_window zeroes out all non-Lisp data, so do it only for slots which should not be zero. */ @@ -3700,14 +3696,14 @@ be applied on the Elisp level. */) (horflag ? r->total_cols : r->total_lines))) return Qnil; - BLOCK_INPUT; + block_input (); window_resize_apply (r, horflag); windows_or_buffers_changed++; FRAME_WINDOW_SIZES_CHANGED (f) = 1; adjust_glyphs (f); - UNBLOCK_INPUT; + unblock_input (); run_window_configuration_change_hook (f); @@ -3851,7 +3847,7 @@ set correctly. See the code of `split-window' for how this is done. */) We do that if either `window-combination-limit' is t, or OLD has no parent, or OLD is ortho-combined. */ combination_limit = - !NILP (Vwindow_combination_limit) + EQ (Vwindow_combination_limit, Qt) || NILP (o->parent) || NILP (horflag ? (XWINDOW (o->parent)->hchild) @@ -3906,9 +3902,9 @@ set correctly. See the code of `split-window' for how this is done. */) make_parent_window (old, horflag); p = XWINDOW (o->parent); - /* Store value of `window-combination-limit' in new parent's - combination_limit slot. */ - wset_combination_limit (p, Vwindow_combination_limit); + /* Store t in the new parent's combination_limit slot to avoid + that its children get merged into another window. */ + wset_combination_limit (p, Qt); /* These get applied below. */ wset_new_total (p, horflag ? o->total_cols : o->total_lines); wset_new_normal (p, new_normal); @@ -3977,13 +3973,13 @@ set correctly. See the code of `split-window' for how this is done. */) wset_new_total (n, total_size); wset_new_normal (n, normal_size); - BLOCK_INPUT; + block_input (); window_resize_apply (p, horflag); adjust_glyphs (f); /* Set buffer of NEW to buffer of reference window. Don't run any hooks. */ set_window_buffer (new, r->buffer, 0, 1); - UNBLOCK_INPUT; + unblock_input (); /* Maybe we should run the scroll functions in Elisp (which already runs the configuration change hook). */ @@ -4064,7 +4060,7 @@ Signal an error when WINDOW is the only window on its frame. */) { /* Block input. */ - BLOCK_INPUT; + block_input (); window_resize_apply (p, horflag); /* If this window is referred to by the dpyinfo's mouse @@ -4136,7 +4132,7 @@ Signal an error when WINDOW is the only window on its frame. */) else fset_selected_window (f, new_selected_window); - UNBLOCK_INPUT; + unblock_input (); /* Now look whether `get-mru-window' gets us something. */ mru_window = call1 (Qget_mru_window, frame); @@ -4151,7 +4147,7 @@ Signal an error when WINDOW is the only window on its frame. */) fset_selected_window (f, new_selected_window); } else - UNBLOCK_INPUT; + unblock_input (); /* Must be run by the caller: run_window_configuration_change_hook (f); */ @@ -4201,7 +4197,7 @@ grow_mini_window (struct window *w, int delta) root, make_number (- delta)); if (INTEGERP (value) && window_resize_check (r, 0)) { - BLOCK_INPUT; + block_input (); window_resize_apply (r, 0); /* Grow the mini-window. */ @@ -4213,7 +4209,7 @@ grow_mini_window (struct window *w, int delta) w->last_overlay_modified = 0; adjust_glyphs (f); - UNBLOCK_INPUT; + unblock_input (); } } @@ -4238,7 +4234,7 @@ shrink_mini_window (struct window *w) root, make_number (size - 1)); if (INTEGERP (value) && window_resize_check (r, 0)) { - BLOCK_INPUT; + block_input (); window_resize_apply (r, 0); /* Shrink the mini-window. */ @@ -4250,7 +4246,7 @@ shrink_mini_window (struct window *w) w->last_overlay_modified = 0; adjust_glyphs (f); - UNBLOCK_INPUT; + unblock_input (); } /* If the above failed for whatever strange reason we must make a one window frame here. The same routine will be needed when @@ -4282,7 +4278,7 @@ DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal, Sresize_mini && XINT (w->new_total) > 0 && height == XINT (r->new_total) + XINT (w->new_total)) { - BLOCK_INPUT; + block_input (); window_resize_apply (r, 0); wset_total_lines (w, w->new_total); @@ -4292,7 +4288,7 @@ DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal, Sresize_mini windows_or_buffers_changed++; FRAME_WINDOW_SIZES_CHANGED (f) = 1; adjust_glyphs (f); - UNBLOCK_INPUT; + unblock_input (); run_window_configuration_change_hook (f); return Qt; @@ -5536,7 +5532,6 @@ the return value is nil. Otherwise the value is t. */) struct Lisp_Vector *saved_windows; Lisp_Object new_current_buffer; Lisp_Object frame; - Lisp_Object auto_buffer_name; FRAME_PTR f; ptrdiff_t old_point = -1; @@ -5546,7 +5541,7 @@ the return value is nil. Otherwise the value is t. */) saved_windows = XVECTOR (data->saved_windows); new_current_buffer = data->current_buffer; - if (NILP (BVAR (XBUFFER (new_current_buffer), name))) + if (!BUFFER_LIVE_P (XBUFFER (new_current_buffer))) new_current_buffer = Qnil; else { @@ -5612,9 +5607,24 @@ the return value is nil. Otherwise the value is t. */) int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f); int previous_frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f); + /* Don't do this within the main loop below: This may call Lisp + code and is thus potentially unsafe while input is blocked. */ + for (k = 0; k < saved_windows->header.size; k++) + { + p = SAVED_WINDOW_N (saved_windows, k); + window = p->window; + w = XWINDOW (window); + if (!NILP (w->buffer) + && !EQ (w->buffer, p->buffer) + && BUFFER_LIVE_P (XBUFFER (p->buffer))) + /* If a window we restore gets another buffer, record the + window's old buffer. */ + call1 (Qrecord_window_buffer, window); + } + /* The mouse highlighting code could get screwed up if it runs during this. */ - BLOCK_INPUT; + block_input (); if (data->frame_lines != previous_frame_lines || data->frame_cols != previous_frame_cols) @@ -5756,7 +5766,7 @@ the return value is nil. Otherwise the value is t. */) if (NILP (p->buffer)) /* An internal window. */ wset_buffer (w, p->buffer); - else if (!NILP (BVAR (XBUFFER (p->buffer), name))) + else if (BUFFER_LIVE_P (XBUFFER (p->buffer))) /* If saved buffer is alive, install it. */ { wset_buffer (w, p->buffer); @@ -5775,7 +5785,7 @@ the return value is nil. Otherwise the value is t. */) Fgoto_char (w->pointm); } else if (!NILP (w->buffer) - && !NILP (BVAR (XBUFFER (w->buffer), name))) + && BUFFER_LIVE_P (XBUFFER (w->buffer))) /* Keep window's old buffer; make sure the markers are real. */ { @@ -5790,18 +5800,6 @@ the return value is nil. Otherwise the value is t. */) BUF_PT_BYTE (XBUFFER (w->buffer))); w->start_at_line_beg = 1; } - else if (STRINGP (auto_buffer_name = - Fwindow_parameter (window, Qauto_buffer_name)) - && SCHARS (auto_buffer_name) != 0 - && (wset_buffer (w, Fget_buffer_create (auto_buffer_name)), - !NILP (w->buffer))) - { - set_marker_restricted (w->start, - make_number (0), w->buffer); - set_marker_restricted (w->pointm, - make_number (0), w->buffer); - w->start_at_line_beg = 1; - } else /* Window has no live buffer, get one. */ { @@ -5877,7 +5875,7 @@ the return value is nil. Otherwise the value is t. */) } adjust_glyphs (f); - UNBLOCK_INPUT; + unblock_input (); /* Scan dead buffer windows. */ for (; CONSP (dead_windows); dead_windows = XCDR (dead_windows)) @@ -5899,7 +5897,13 @@ the return value is nil. Otherwise the value is t. */) } if (!NILP (new_current_buffer)) - Fset_buffer (new_current_buffer); + { + Fset_buffer (new_current_buffer); + /* If the new current buffer doesn't appear in the selected + window, go to its old point (see bug#12208). */ + if (!EQ (XWINDOW (data->current_window)->buffer, new_current_buffer)) + Fgoto_char (make_number (old_point)); + } Vminibuf_scroll_window = data->minibuf_scroll_window; minibuf_selected_window = data->minibuf_selected_window; @@ -6564,15 +6568,17 @@ freeze_window_starts (struct frame *f, int freeze_p) /* Return 1 if window configurations CONFIGURATION1 and CONFIGURATION2 describe the same state of affairs. This is used by Fequal. - ignore_positions non-zero means ignore non-matching scroll positions + IGNORE_POSITIONS means ignore non-matching scroll positions and the like. This ignores a couple of things like the dedication status of window, combination_limit and the like. This might have to be fixed. */ -int -compare_window_configurations (Lisp_Object configuration1, Lisp_Object configuration2, int ignore_positions) +bool +compare_window_configurations (Lisp_Object configuration1, + Lisp_Object configuration2, + bool ignore_positions) { register struct save_window_data *d1, *d2; struct Lisp_Vector *sws1, *sws2; @@ -6698,10 +6704,10 @@ syms_of_window (void) DEFSYM (Qreplace_buffer_in_windows, "replace-buffer-in-windows"); DEFSYM (Qrecord_window_buffer, "record-window-buffer"); DEFSYM (Qget_mru_window, "get-mru-window"); + DEFSYM (Qtemp_buffer_resize, "temp-buffer-resize"); DEFSYM (Qtemp_buffer_show_hook, "temp-buffer-show-hook"); DEFSYM (Qabove, "above"); DEFSYM (Qbelow, "below"); - DEFSYM (Qauto_buffer_name, "auto-buffer-name"); DEFSYM (Qclone_of, "clone-of"); staticpro (&Vwindow_list); @@ -6794,23 +6800,36 @@ This variable takes no effect if `window-combination-limit' is non-nil. */); Vwindow_combination_resize = Qnil; DEFVAR_LISP ("window-combination-limit", Vwindow_combination_limit, - doc: /* If t, splitting a window makes a new parent window. -If this variable is nil, splitting a window will create a new parent -window only if the window has no parent window or the window shall -become a combination orthogonal to the one it is part of. + doc: /* If non-nil, splitting a window makes a new parent window. +The following values are recognized: -If this variable is t, splitting a window always creates a new parent -window. If all splits behave this way, each frame's window tree is a -binary tree and every window but the frame's root window has exactly one -sibling. +nil means splitting a window will create a new parent window only if the + window has no parent window or the window shall become a combination + orthogonal to the one it is part of. -Other values are reserved for future use. +`temp-buffer-resize' means that splitting a window for displaying a + temporary buffer makes a new parent window provided + `temp-buffer-resize-mode' is enabled. Otherwise, this value is + handled like nil. + +`temp-buffer' means that splitting a window for displaying a temporary + buffer always makes a new parent window. Otherwise, this value is + handled like nil. + + +`display-buffer' means that splitting a window for displaying a buffer + always makes a new parent window. Since temporary buffers are + displayed by the function `display-buffer', this value is stronger + than `temp-buffer'. Splitting a window for other purpose makes a + new parent window only if needed. + +t means that splitting a window always creates a new parent window. If + all splits behave this way, each frame's window tree is a binary + tree and every window but the frame's root window has exactly one + sibling. -The value of this variable is also assigned to the combination limit of -the new parent window. The combination limit of a window can be -retrieved via the function `window-combination-limit' and altered by the -function `set-window-combination-limit'. */); - Vwindow_combination_limit = Qnil; +Other values are reserved for future use. */); + Vwindow_combination_limit = Qtemp_buffer_resize; DEFVAR_LISP ("window-persistent-parameters", Vwindow_persistent_parameters, doc: /* Alist of persistent window parameters.