Commit 565212e5 authored by Dmitry Antipov's avatar Dmitry Antipov

Avoid code duplication between prev_frame and next_frame.

* frame.c (candidate_frame): New function.  Add comment.
(prev_frame, next_frame): Use it.  Adjust comment.
parent d8ad4d3f
2012-12-06 Dmitry Antipov <dmantipov@yandex.ru>
Avoid code duplication between prev_frame and next_frame.
* frame.c (candidate_frame): New function. Add comment.
(prev_frame, next_frame): Use it. Adjust comment.
2012-12-06 Eli Zaretskii <eliz@gnu.org>
* callproc.c (Fcall_process_region) [!HAVE_MKSTEMP]: If mktemp
......
......@@ -895,13 +895,58 @@ DEFUN ("frame-list", Fframe_list, Sframe_list,
return frames;
}
/* Return the next frame in the frame list after FRAME.
If MINIBUF is nil, exclude minibuffer-only frames.
If MINIBUF is a window, include only its own frame
and any frame now using that window as the minibuffer.
If MINIBUF is `visible', include all visible frames.
If MINIBUF is 0, include all visible and iconified frames.
Otherwise, include all frames. */
/* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
same tty (for tty frames) or among frames which uses FRAME's keyboard.
If MINIBUF is nil, do not consider minibuffer-only candidate.
If MINIBUF is `visible', do not consider an invisible candidate.
If MINIBUF is a window, consider only its own frame and candidate now
using that window as the minibuffer.
If MINIBUF is 0, consider candidate if it is visible or iconified.
Otherwise consider any candidate and return nil if CANDIDATE is not
acceptable. */
static Lisp_Object
candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
{
struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
&& FRAME_KBOARD (c) == FRAME_KBOARD (f))
|| (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
&& FRAME_TTY (c) == FRAME_TTY (f)))
{
if (NILP (minibuf))
{
if (!FRAME_MINIBUF_ONLY_P (c))
return candidate;
}
else if (EQ (minibuf, Qvisible))
{
FRAME_SAMPLE_VISIBILITY (c);
if (FRAME_VISIBLE_P (c))
return candidate;
}
else if (WINDOWP (minibuf))
{
if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
|| EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
|| EQ (WINDOW_FRAME (XWINDOW (minibuf)),
FRAME_FOCUS_FRAME (c)))
return candidate;
}
else if (XFASTINT (minibuf) == 0)
{
FRAME_SAMPLE_VISIBILITY (c);
if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
return candidate;
}
else
return candidate;
}
return Qnil;
}
/* Return the next frame in the frame list after FRAME. */
static Lisp_Object
next_frame (Lisp_Object frame, Lisp_Object minibuf)
......@@ -910,72 +955,24 @@ next_frame (Lisp_Object frame, Lisp_Object minibuf)
int passed = 0;
/* There must always be at least one frame in Vframe_list. */
if (! CONSP (Vframe_list))
emacs_abort ();
/* If this frame is dead, it won't be in Vframe_list, and we'll loop
forever. Forestall that. */
CHECK_LIVE_FRAME (frame);
eassert (CONSP (Vframe_list));
while (1)
while (passed < 2)
FOR_EACH_FRAME (tail, f)
{
if (passed
&& ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
&& FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
|| (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
&& FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
if (passed)
{
/* Decide whether this frame is eligible to be returned. */
/* If we've looped all the way around without finding any
eligible frames, return the original frame. */
if (EQ (f, frame))
return f;
/* Let minibuf decide if this frame is acceptable. */
if (NILP (minibuf))
{
if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
return f;
}
else if (EQ (minibuf, Qvisible))
{
FRAME_SAMPLE_VISIBILITY (XFRAME (f));
if (FRAME_VISIBLE_P (XFRAME (f)))
return f;
}
else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
{
FRAME_SAMPLE_VISIBILITY (XFRAME (f));
if (FRAME_VISIBLE_P (XFRAME (f))
|| FRAME_ICONIFIED_P (XFRAME (f)))
return f;
}
else if (WINDOWP (minibuf))
{
if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
|| EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
|| EQ (WINDOW_FRAME (XWINDOW (minibuf)),
FRAME_FOCUS_FRAME (XFRAME (f))))
return f;
}
else
f = candidate_frame (f, frame, minibuf);
if (!NILP (f))
return f;
}
if (EQ (frame, f))
passed++;
}
return frame;
}
/* Return the previous frame in the frame list before FRAME.
If MINIBUF is nil, exclude minibuffer-only frames.
If MINIBUF is a window, include only its own frame
and any frame now using that window as the minibuffer.
If MINIBUF is `visible', include all visible frames.
If MINIBUF is 0, include all visible and iconified frames.
Otherwise, include all frames. */
/* Return the previous frame in the frame list before FRAME. */
static Lisp_Object
prev_frame (Lisp_Object frame, Lisp_Object minibuf)
......@@ -989,43 +986,9 @@ prev_frame (Lisp_Object frame, Lisp_Object minibuf)
{
if (EQ (frame, f) && !NILP (prev))
return prev;
if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
&& FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
|| (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
&& FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
{
/* Decide whether this frame is eligible to be returned,
according to minibuf. */
if (NILP (minibuf))
{
if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
prev = f;
}
else if (WINDOWP (minibuf))
{
if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
|| EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
|| EQ (WINDOW_FRAME (XWINDOW (minibuf)),
FRAME_FOCUS_FRAME (XFRAME (f))))
prev = f;
}
else if (EQ (minibuf, Qvisible))
{
FRAME_SAMPLE_VISIBILITY (XFRAME (f));
if (FRAME_VISIBLE_P (XFRAME (f)))
prev = f;
}
else if (XFASTINT (minibuf) == 0)
{
FRAME_SAMPLE_VISIBILITY (XFRAME (f));
if (FRAME_VISIBLE_P (XFRAME (f))
|| FRAME_ICONIFIED_P (XFRAME (f)))
prev = f;
}
else
prev = f;
}
f = candidate_frame (f, frame, minibuf);
if (!NILP (f))
prev = f;
}
/* We've scanned the entire list. */
......@@ -1056,7 +1019,6 @@ Otherwise, include all frames. */)
{
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
return next_frame (frame, miniframe);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment