- Lisp_Object tem;
-
- CHECK_STRING (buffer_name);
-
- tem = Fmember (buffer_name, Vsame_window_buffer_names);
- if (!NILP (tem))
- return Qt;
-
- tem = Fassoc (buffer_name, Vsame_window_buffer_names);
- if (!NILP (tem))
- return Qt;
-
- for (tem = Vsame_window_regexps; CONSP (tem); tem = XCDR (tem))
- {
- Lisp_Object car = XCAR (tem);
- if (STRINGP (car)
- && fast_string_match (car, buffer_name) >= 0)
- return Qt;
- else if (CONSP (car)
- && STRINGP (XCAR (car))
- && fast_string_match (XCAR (car), buffer_name) >= 0)
- return Qt;
- }
- return Qnil;
-}
-
-/* Use B so the default is (other-buffer). */
-DEFUN ("display-buffer", Fdisplay_buffer, Sdisplay_buffer, 1, 3,
- "BDisplay buffer: \nP",
- doc: /* Make BUFFER appear in some window but don't select it.
-BUFFER must be the name of an existing buffer, or, when called from Lisp,
-a buffer.
-If BUFFER is shown already in some window, just use that one,
-unless the window is the selected window and the optional second
-argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).
-If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
-Returns the window displaying BUFFER.
-If `display-buffer-reuse-frames' is non-nil, and another frame is currently
-displaying BUFFER, then simply raise that frame.
-
-The variables `special-display-buffer-names',
-`special-display-regexps', `same-window-buffer-names', and
-`same-window-regexps' customize how certain buffer names are handled.
-The latter two take effect only if NOT-THIS-WINDOW is nil.
-
-If optional argument FRAME is `visible', check all visible frames
-for a window to use.
-If FRAME is 0, check all visible and iconified frames.
-If FRAME is t, check all frames.
-If FRAME is a frame, check only that frame.
-If FRAME is nil, check only the selected frame
- (actually the last nonminibuffer frame),
- unless `pop-up-frames' or `display-buffer-reuse-frames' is non-nil,
- which means search visible and iconified frames.
-
-If a full-width window on a splittable frame is available to display
-the buffer, it may be split, subject to the value of the variable
-`split-height-threshold'.
-
-If `even-window-heights' is non-nil, window heights will be evened out
-if displaying the buffer causes two vertically adjacent windows to be
-displayed. */)
- (buffer, not_this_window, frame)
- Lisp_Object buffer, not_this_window, frame;
-{
- register Lisp_Object window, tem, swp;
- struct frame *f;
-
- swp = Qnil;
- buffer = Fget_buffer (buffer);
- CHECK_BUFFER (buffer);
-
- if (!NILP (Vdisplay_buffer_function))
- return call2 (Vdisplay_buffer_function, buffer, not_this_window);
-
- if (NILP (not_this_window)
- && XBUFFER (XWINDOW (selected_window)->buffer) == XBUFFER (buffer))
- return display_buffer_1 (selected_window);
-
- /* See if the user has specified this buffer should appear
- in the selected window. */
- if (NILP (not_this_window))
- {
- swp = Fsame_window_p (XBUFFER (buffer)->name);
- if (!NILP (swp) && !no_switch_window (selected_window))
- {
- Fswitch_to_buffer (buffer, Qnil);
- return display_buffer_1 (selected_window);
- }
- }
-
- /* If the user wants pop-up-frames or display-buffer-reuse-frames,
- look for a window showing BUFFER on any visible or iconified frame.
- Otherwise search only the current frame. */
- if (! NILP (frame))
- tem = frame;
- else if (pop_up_frames
- || display_buffer_reuse_frames
- || last_nonminibuf_frame == 0)
- XSETFASTINT (tem, 0);
- else
- XSETFRAME (tem, last_nonminibuf_frame);
-
- window = Fget_buffer_window (buffer, tem);
- if (!NILP (window)
- && (NILP (not_this_window) || !EQ (window, selected_window)))
- return display_buffer_1 (window);
-
- /* Certain buffer names get special handling. */
- if (!NILP (Vspecial_display_function) && NILP (swp))
- {
- tem = Fspecial_display_p (XBUFFER (buffer)->name);
- if (EQ (tem, Qt))
- return call1 (Vspecial_display_function, buffer);
- if (CONSP (tem))
- return call2 (Vspecial_display_function, buffer, tem);
- }
-
- /* If there are no frames open that have more than a minibuffer,
- we need to create a new frame. */
- if (pop_up_frames || last_nonminibuf_frame == 0)
- {
- window = Fframe_selected_window (call0 (Vpop_up_frame_function));
- Fset_window_buffer (window, buffer, Qnil);
- return display_buffer_1 (window);
- }
-
- f = SELECTED_FRAME ();
- if (pop_up_windows
- || FRAME_MINIBUF_ONLY_P (f)
- /* If the current frame is a special display frame,
- don't try to reuse its windows. */
- || !NILP (XWINDOW (FRAME_ROOT_WINDOW (f))->dedicated))
- {
- Lisp_Object frames;
- struct gcpro gcpro1;
- GCPRO1 (buffer);
-
- frames = Qnil;
- if (FRAME_MINIBUF_ONLY_P (f))
- XSETFRAME (frames, last_nonminibuf_frame);
-
- /* Note that both Fget_largest_window and Fget_lru_window
- ignore minibuffers and dedicated windows.
- This means they can return nil. */
-
- /* If the frame we would try to split cannot be split,
- try other frames. */
- if (FRAME_NO_SPLIT_P (NILP (frames) ? f : last_nonminibuf_frame))
- {
- /* Try visible frames first. */
- window = Fget_largest_window (Qvisible, Qt);
- /* If that didn't work, try iconified frames. */
- if (NILP (window))
- window = Fget_largest_window (make_number (0), Qt);
-#if 0 /* Don't try windows on other displays. */
- if (NILP (window))
- window = Fget_largest_window (Qt, Qt);
-#endif
- }
- else
- window = Fget_largest_window (frames, Qt);
-
- /* If the largest window is tall enough, full-width, and either eligible
- for splitting or the only window, split it. */
- if (!NILP (window)
- && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window)->frame))
- && WINDOW_FULL_WIDTH_P (XWINDOW (window))
- && (window_height (window) >= split_height_threshold
- || (NILP (XWINDOW (window)->parent)))
- && (window_height (window)
- >= (2 * window_min_size_2 (XWINDOW (window), 0))))
- window = call1 (Vsplit_window_preferred_function, window);
- else
- {
- Lisp_Object upper, other;
-
- window = Fget_lru_window (frames, Qt);
- /* If the LRU window is tall enough, and either eligible for
- splitting and selected or the only window, split it. */
- if (!NILP (window)
- && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window)->frame))
- && ((EQ (window, selected_window)
- && window_height (window) >= split_height_threshold)
- || (NILP (XWINDOW (window)->parent)))
- && (window_height (window)
- >= (2 * window_min_size_2 (XWINDOW (window), 0))))
- window = call1 (Vsplit_window_preferred_function, window);
- else
- window = Fget_lru_window (frames, Qnil);
- /* If Fget_lru_window returned nil, try other approaches. */
-
- /* Try visible frames first. */
- if (NILP (window))
- window = Fget_buffer_window (buffer, Qvisible);
- if (NILP (window))
- window = Fget_largest_window (Qvisible, Qnil);
- /* If that didn't work, try iconified frames. */
- if (NILP (window))
- window = Fget_buffer_window (buffer, make_number (0));
- if (NILP (window))
- window = Fget_largest_window (make_number (0), Qnil);
-
-#if 0 /* Don't try frames on other displays. */
- if (NILP (window))
- window = Fget_buffer_window (buffer, Qt);
- if (NILP (window))
- window = Fget_largest_window (Qt, Qnil);
-#endif
- /* As a last resort, make a new frame. */
- if (NILP (window))
- window = Fframe_selected_window (call0 (Vpop_up_frame_function));
- /* If window appears above or below another,
- even out their heights. */
- other = upper = Qnil;
- if (!NILP (XWINDOW (window)->prev))
- other = upper = XWINDOW (window)->prev;
- if (!NILP (XWINDOW (window)->next))
- other = XWINDOW (window)->next, upper = window;
- if (!NILP (other)
- && !NILP (Veven_window_heights)
- /* Check that OTHER and WINDOW are vertically arrayed. */
- && !EQ (XWINDOW (other)->top_line, XWINDOW (window)->top_line)
- && (XFASTINT (XWINDOW (other)->total_lines)
- > XFASTINT (XWINDOW (window)->total_lines)))
- {
- int total = (XFASTINT (XWINDOW (other)->total_lines)
- + XFASTINT (XWINDOW (window)->total_lines));
- enlarge_window (upper,
- total / 2 - XFASTINT (XWINDOW (upper)->total_lines),
- 0);
- }
- }
- UNGCPRO;
- }
- else
- window = Fget_lru_window (Qnil, Qnil);
-
- Fset_window_buffer (window, buffer, Qnil);
- return display_buffer_1 (window);