Commit 5b04e9f9 authored by Dmitry Antipov's avatar Dmitry Antipov
Browse files

Simplify by using FOR_EACH_FRAME here and there.

* frame.c (next_frame, prev_frame, other_visible_frames)
(delete_frame, visible-frame-list): Use FOR_EACH_FRAME.
* w32term.c (x_window_to_scroll_bar): Likewise.
* window.c (window_list): Likewise.
* xdisp.c (x_consider_frame_title): Likewise.
* xfaces.c ( Fdisplay_supports_face_attributes_p): Likewise.
* xfns.c (x_window_to_frame, x_any_window_to_frame)
(x_menubar_window_to_frame, x_top_window_to_frame): Likewise.
* xmenu.c (menubar_id_to_frame): Likewise.
* xselect.c (frame_for_x_selection): Likewise.
* xterm.c (x_frame_of_widget, x_window_to_scroll_bar)
(x_window_to_menu_bar): Likewise.
* w32fns.c (x_window_to_frame): Likewise.  Adjust comment.
parent 31f47fba
2012-11-12 Dmitry Antipov <dmantipov@yandex.ru>
Simplify by using FOR_EACH_FRAME here and there.
* frame.c (next_frame, prev_frame, other_visible_frames)
(delete_frame, visible-frame-list): Use FOR_EACH_FRAME.
* w32term.c (x_window_to_scroll_bar): Likewise.
* window.c (window_list): Likewise.
* xdisp.c (x_consider_frame_title): Likewise.
* xfaces.c ( Fdisplay_supports_face_attributes_p): Likewise.
* xfns.c (x_window_to_frame, x_any_window_to_frame)
(x_menubar_window_to_frame, x_top_window_to_frame): Likewise.
* xmenu.c (menubar_id_to_frame): Likewise.
* xselect.c (frame_for_x_selection): Likewise.
* xterm.c (x_frame_of_widget, x_window_to_scroll_bar)
(x_window_to_menu_bar): Likewise.
* w32fns.c (x_window_to_frame): Likewise. Adjust comment.
2012-11-12 Paul Eggert <eggert@cs.ucla.edu> 2012-11-12 Paul Eggert <eggert@cs.ucla.edu>
   
* data.c (Qdefalias_fset_function): Now static. * data.c (Qdefalias_fset_function): Now static.
......
...@@ -906,7 +906,7 @@ DEFUN ("frame-list", Fframe_list, Sframe_list, ...@@ -906,7 +906,7 @@ DEFUN ("frame-list", Fframe_list, Sframe_list,
static Lisp_Object static Lisp_Object
next_frame (Lisp_Object frame, Lisp_Object minibuf) next_frame (Lisp_Object frame, Lisp_Object minibuf)
{ {
Lisp_Object tail; Lisp_Object f, tail;
int passed = 0; int passed = 0;
/* There must always be at least one frame in Vframe_list. */ /* There must always be at least one frame in Vframe_list. */
...@@ -918,12 +918,8 @@ next_frame (Lisp_Object frame, Lisp_Object minibuf) ...@@ -918,12 +918,8 @@ next_frame (Lisp_Object frame, Lisp_Object minibuf)
CHECK_LIVE_FRAME (frame); CHECK_LIVE_FRAME (frame);
while (1) while (1)
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) FOR_EACH_FRAME (tail, f)
{ {
Lisp_Object f;
f = XCAR (tail);
if (passed if (passed
&& ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame)) && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
&& FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame))) && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
...@@ -984,22 +980,13 @@ next_frame (Lisp_Object frame, Lisp_Object minibuf) ...@@ -984,22 +980,13 @@ next_frame (Lisp_Object frame, Lisp_Object minibuf)
static Lisp_Object static Lisp_Object
prev_frame (Lisp_Object frame, Lisp_Object minibuf) prev_frame (Lisp_Object frame, Lisp_Object minibuf)
{ {
Lisp_Object tail; Lisp_Object f, tail, prev = Qnil;
Lisp_Object prev;
/* There must always be at least one frame in Vframe_list. */ /* There must always be at least one frame in Vframe_list. */
if (! CONSP (Vframe_list)) eassert (CONSP (Vframe_list));
emacs_abort ();
prev = Qnil; FOR_EACH_FRAME (tail, f)
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
{ {
Lisp_Object f;
f = XCAR (tail);
if (!FRAMEP (f))
emacs_abort ();
if (EQ (frame, f) && !NILP (prev)) if (EQ (frame, f) && !NILP (prev))
return prev; return prev;
...@@ -1100,11 +1087,10 @@ Otherwise, include all frames. */) ...@@ -1100,11 +1087,10 @@ Otherwise, include all frames. */)
static int static int
other_visible_frames (FRAME_PTR f) other_visible_frames (FRAME_PTR f)
{ {
Lisp_Object frames; Lisp_Object frames, this;
for (frames = Vframe_list; CONSP (frames); frames = XCDR (frames)) FOR_EACH_FRAME (frames, this)
{ {
Lisp_Object this = XCAR (frames);
if (f == XFRAME (this)) if (f == XFRAME (this))
continue; continue;
...@@ -1158,15 +1144,10 @@ delete_frame (Lisp_Object frame, Lisp_Object force) ...@@ -1158,15 +1144,10 @@ delete_frame (Lisp_Object frame, Lisp_Object force)
minibuffer for any other frame? */ minibuffer for any other frame? */
if (FRAME_HAS_MINIBUF_P (f)) if (FRAME_HAS_MINIBUF_P (f))
{ {
Lisp_Object frames; Lisp_Object frames, this;
for (frames = Vframe_list; FOR_EACH_FRAME (frames, this)
CONSP (frames);
frames = XCDR (frames))
{ {
Lisp_Object this;
this = XCAR (frames);
if (! EQ (this, frame) if (! EQ (this, frame)
&& EQ (frame, && EQ (frame,
WINDOW_FRAME (XWINDOW WINDOW_FRAME (XWINDOW
...@@ -1359,15 +1340,13 @@ delete_frame (Lisp_Object frame, Lisp_Object force) ...@@ -1359,15 +1340,13 @@ delete_frame (Lisp_Object frame, Lisp_Object force)
another one. */ another one. */
if (f == last_nonminibuf_frame) if (f == last_nonminibuf_frame)
{ {
Lisp_Object frames; Lisp_Object frames, this;
last_nonminibuf_frame = 0; last_nonminibuf_frame = 0;
for (frames = Vframe_list; FOR_EACH_FRAME (frames, this)
CONSP (frames);
frames = XCDR (frames))
{ {
f = XFRAME (XCAR (frames)); f = XFRAME (this);
if (!FRAME_MINIBUF_ONLY_P (f)) if (!FRAME_MINIBUF_ONLY_P (f))
{ {
last_nonminibuf_frame = f; last_nonminibuf_frame = f;
...@@ -1380,27 +1359,13 @@ delete_frame (Lisp_Object frame, Lisp_Object force) ...@@ -1380,27 +1359,13 @@ delete_frame (Lisp_Object frame, Lisp_Object force)
single-kboard state if we're in it for this kboard. */ single-kboard state if we're in it for this kboard. */
if (kb != NULL) if (kb != NULL)
{ {
Lisp_Object frames; Lisp_Object frames, this;
/* Some frame we found on the same kboard, or nil if there are none. */ /* Some frame we found on the same kboard, or nil if there are none. */
Lisp_Object frame_on_same_kboard; Lisp_Object frame_on_same_kboard = Qnil;
frame_on_same_kboard = Qnil;
for (frames = Vframe_list;
CONSP (frames);
frames = XCDR (frames))
{
Lisp_Object this;
struct frame *f1;
this = XCAR (frames);
if (!FRAMEP (this))
emacs_abort ();
f1 = XFRAME (this);
if (kb == FRAME_KBOARD (f1)) FOR_EACH_FRAME (frames, this)
frame_on_same_kboard = this; if (kb == FRAME_KBOARD (XFRAME (this)))
} frame_on_same_kboard = this;
if (NILP (frame_on_same_kboard)) if (NILP (frame_on_same_kboard))
not_single_kboard_state (kb); not_single_kboard_state (kb);
...@@ -1412,27 +1377,16 @@ delete_frame (Lisp_Object frame, Lisp_Object force) ...@@ -1412,27 +1377,16 @@ delete_frame (Lisp_Object frame, Lisp_Object force)
frames with other windows. */ frames with other windows. */
if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame))) if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
{ {
Lisp_Object frames; Lisp_Object frames, this;
/* The last frame we saw with a minibuffer, minibuffer-only or not. */ /* The last frame we saw with a minibuffer, minibuffer-only or not. */
Lisp_Object frame_with_minibuf; Lisp_Object frame_with_minibuf = Qnil;
/* Some frame we found on the same kboard, or nil if there are none. */ /* Some frame we found on the same kboard, or nil if there are none. */
Lisp_Object frame_on_same_kboard; Lisp_Object frame_on_same_kboard = Qnil;
frame_on_same_kboard = Qnil; FOR_EACH_FRAME (frames, this)
frame_with_minibuf = Qnil;
for (frames = Vframe_list;
CONSP (frames);
frames = XCDR (frames))
{ {
Lisp_Object this; struct frame *f1 = XFRAME (this);
struct frame *f1;
this = XCAR (frames);
if (!FRAMEP (this))
emacs_abort ();
f1 = XFRAME (this);
/* Consider only frames on the same kboard /* Consider only frames on the same kboard
and only those with minibuffers. */ and only those with minibuffers. */
...@@ -1816,20 +1770,12 @@ DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list, ...@@ -1816,20 +1770,12 @@ DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
doc: /* Return a list of all frames now \"visible\" (being updated). */) doc: /* Return a list of all frames now \"visible\" (being updated). */)
(void) (void)
{ {
Lisp_Object tail, frame; Lisp_Object tail, frame, value = Qnil;
struct frame *f;
Lisp_Object value; FOR_EACH_FRAME (tail, frame)
if (FRAME_VISIBLE_P (XFRAME (frame)))
value = Fcons (frame, value);
value = Qnil;
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
{
frame = XCAR (tail);
if (!FRAMEP (frame))
continue;
f = XFRAME (frame);
if (FRAME_VISIBLE_P (f))
value = Fcons (frame, value);
}
return value; return value;
} }
......
...@@ -304,19 +304,14 @@ check_x_display_info (Lisp_Object frame) ...@@ -304,19 +304,14 @@ check_x_display_info (Lisp_Object frame)
/* Return the Emacs frame-object corresponding to an w32 window. /* Return the Emacs frame-object corresponding to an w32 window.
It could be the frame's main window or an icon window. */ It could be the frame's main window or an icon window. */
/* This function can be called during GC, so use GC_xxx type test macros. */
struct frame * struct frame *
x_window_to_frame (struct w32_display_info *dpyinfo, HWND wdesc) x_window_to_frame (struct w32_display_info *dpyinfo, HWND wdesc)
{ {
Lisp_Object tail, frame; Lisp_Object tail, frame;
struct frame *f; struct frame *f;
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) FOR_EACH_FRAME (tail, frame)
{ {
frame = XCAR (tail);
if (!FRAMEP (frame))
continue;
f = XFRAME (frame); f = XFRAME (frame);
if (!FRAME_W32_P (f) || FRAME_W32_DISPLAY_INFO (f) != dpyinfo) if (!FRAME_W32_P (f) || FRAME_W32_DISPLAY_INFO (f) != dpyinfo)
continue; continue;
......
...@@ -3437,16 +3437,11 @@ w32_handle_tool_bar_click (struct frame *f, struct input_event *button_event) ...@@ -3437,16 +3437,11 @@ w32_handle_tool_bar_click (struct frame *f, struct input_event *button_event)
static struct scroll_bar * static struct scroll_bar *
x_window_to_scroll_bar (Window window_id) x_window_to_scroll_bar (Window window_id)
{ {
Lisp_Object tail; Lisp_Object tail, frame;
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) FOR_EACH_FRAME (tail, frame)
{ {
Lisp_Object frame, bar, condemned; Lisp_Object bar, condemned;
frame = XCAR (tail);
/* All elements of Vframe_list should be frames. */
if (! FRAMEP (frame))
emacs_abort ();
/* Scan this frame's scroll bar list for a scroll bar with the /* Scan this frame's scroll bar list for a scroll bar with the
right window ID. */ right window ID. */
......
...@@ -2133,10 +2133,10 @@ window_list (void) ...@@ -2133,10 +2133,10 @@ window_list (void)
{ {
if (!CONSP (Vwindow_list)) if (!CONSP (Vwindow_list))
{ {
Lisp_Object tail; Lisp_Object tail, frame;
Vwindow_list = Qnil; Vwindow_list = Qnil;
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) FOR_EACH_FRAME (tail, frame)
{ {
Lisp_Object args[2]; Lisp_Object args[2];
...@@ -2144,7 +2144,7 @@ window_list (void) ...@@ -2144,7 +2144,7 @@ window_list (void)
new windows at the front of args[1], which means we new windows at the front of args[1], which means we
have to reverse this list at the end. */ have to reverse this list at the end. */
args[1] = Qnil; args[1] = Qnil;
foreach_window (XFRAME (XCAR (tail)), add_window_to_list, &args[1]); foreach_window (XFRAME (frame), add_window_to_list, &args[1]);
args[0] = Vwindow_list; args[0] = Vwindow_list;
args[1] = Fnreverse (args[1]); args[1] = Fnreverse (args[1]);
Vwindow_list = Fnconc (2, args); Vwindow_list = Fnconc (2, args);
......
...@@ -11096,17 +11096,15 @@ x_consider_frame_title (Lisp_Object frame) ...@@ -11096,17 +11096,15 @@ x_consider_frame_title (Lisp_Object frame)
|| f->explicit_name) || f->explicit_name)
{ {
/* Do we have more than one visible frame on this X display? */ /* Do we have more than one visible frame on this X display? */
Lisp_Object tail; Lisp_Object tail, other_frame, fmt;
Lisp_Object fmt;
ptrdiff_t title_start; ptrdiff_t title_start;
char *title; char *title;
ptrdiff_t len; ptrdiff_t len;
struct it it; struct it it;
ptrdiff_t count = SPECPDL_INDEX (); ptrdiff_t count = SPECPDL_INDEX ();
   
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) FOR_EACH_FRAME (tail, other_frame)
{ {
Lisp_Object other_frame = XCAR (tail);
struct frame *tf = XFRAME (other_frame); struct frame *tf = XFRAME (other_frame);
   
if (tf != f if (tf != f
......
...@@ -5012,17 +5012,14 @@ face for italic. */) ...@@ -5012,17 +5012,14 @@ face for italic. */)
else else
{ {
/* Find any frame on DISPLAY. */ /* Find any frame on DISPLAY. */
Lisp_Object fl_tail; Lisp_Object tail;
frame = Qnil; frame = Qnil;
for (fl_tail = Vframe_list; CONSP (fl_tail); fl_tail = XCDR (fl_tail)) FOR_EACH_FRAME (tail, frame)
{ if (!NILP (Fequal (Fcdr (Fassq (Qdisplay,
frame = XCAR (fl_tail); XFRAME (frame)->param_alist)),
if (!NILP (Fequal (Fcdr (Fassq (Qdisplay, display)))
XFRAME (frame)->param_alist)), break;
display)))
break;
}
} }
CHECK_LIVE_FRAME (frame); CHECK_LIVE_FRAME (frame);
......
...@@ -224,13 +224,11 @@ x_window_to_frame (struct x_display_info *dpyinfo, int wdesc) ...@@ -224,13 +224,11 @@ x_window_to_frame (struct x_display_info *dpyinfo, int wdesc)
Lisp_Object tail, frame; Lisp_Object tail, frame;
struct frame *f; struct frame *f;
if (wdesc == None) return 0; if (wdesc == None)
return NULL;
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) FOR_EACH_FRAME (tail, frame)
{ {
frame = XCAR (tail);
if (!FRAMEP (frame))
continue;
f = XFRAME (frame); f = XFRAME (frame);
if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo) if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
continue; continue;
...@@ -270,18 +268,16 @@ struct frame * ...@@ -270,18 +268,16 @@ struct frame *
x_any_window_to_frame (struct x_display_info *dpyinfo, int wdesc) x_any_window_to_frame (struct x_display_info *dpyinfo, int wdesc)
{ {
Lisp_Object tail, frame; Lisp_Object tail, frame;
struct frame *f, *found; struct frame *f, *found = NULL;
struct x_output *x; struct x_output *x;
if (wdesc == None) return NULL; if (wdesc == None)
return NULL;
found = NULL; FOR_EACH_FRAME (tail, frame)
for (tail = Vframe_list; CONSP (tail) && !found; tail = XCDR (tail))
{ {
frame = XCAR (tail); if (found)
if (!FRAMEP (frame)) break;
continue;
f = XFRAME (frame); f = XFRAME (frame);
if (FRAME_X_P (f) && FRAME_X_DISPLAY_INFO (f) == dpyinfo) if (FRAME_X_P (f) && FRAME_X_DISPLAY_INFO (f) == dpyinfo)
{ {
...@@ -325,13 +321,11 @@ x_menubar_window_to_frame (struct x_display_info *dpyinfo, XEvent *event) ...@@ -325,13 +321,11 @@ x_menubar_window_to_frame (struct x_display_info *dpyinfo, XEvent *event)
struct frame *f; struct frame *f;
struct x_output *x; struct x_output *x;
if (wdesc == None) return 0; if (wdesc == None)
return NULL;
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) FOR_EACH_FRAME (tail, frame)
{ {
frame = XCAR (tail);
if (!FRAMEP (frame))
continue;
f = XFRAME (frame); f = XFRAME (frame);
if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo) if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
continue; continue;
...@@ -359,13 +353,11 @@ x_top_window_to_frame (struct x_display_info *dpyinfo, int wdesc) ...@@ -359,13 +353,11 @@ x_top_window_to_frame (struct x_display_info *dpyinfo, int wdesc)
struct frame *f; struct frame *f;
struct x_output *x; struct x_output *x;
if (wdesc == None) return 0; if (wdesc == None)
return NULL;
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) FOR_EACH_FRAME (tail, frame)
{ {
frame = XCAR (tail);
if (!FRAMEP (frame))
continue;
f = XFRAME (frame); f = XFRAME (frame);
if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo) if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
continue; continue;
......
...@@ -132,11 +132,8 @@ menubar_id_to_frame (LWLIB_ID id) ...@@ -132,11 +132,8 @@ menubar_id_to_frame (LWLIB_ID id)
Lisp_Object tail, frame; Lisp_Object tail, frame;
FRAME_PTR f; FRAME_PTR f;
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) FOR_EACH_FRAME (tail, frame)
{ {
frame = XCAR (tail);
if (!FRAMEP (frame))
continue;
f = XFRAME (frame); f = XFRAME (frame);
if (!FRAME_WINDOW_P (f)) if (!FRAME_WINDOW_P (f))
continue; continue;
......
...@@ -1940,7 +1940,7 @@ x_handle_selection_notify (XSelectionEvent *event) ...@@ -1940,7 +1940,7 @@ x_handle_selection_notify (XSelectionEvent *event)
static struct frame * static struct frame *
frame_for_x_selection (Lisp_Object object) frame_for_x_selection (Lisp_Object object)
{ {
Lisp_Object tail; Lisp_Object tail, frame;
struct frame *f; struct frame *f;
if (NILP (object)) if (NILP (object))
...@@ -1949,9 +1949,9 @@ frame_for_x_selection (Lisp_Object object) ...@@ -1949,9 +1949,9 @@ frame_for_x_selection (Lisp_Object object)
if (FRAME_X_P (f) && FRAME_LIVE_P (f)) if (FRAME_X_P (f) && FRAME_LIVE_P (f))
return f; return f;
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) FOR_EACH_FRAME (tail, frame)
{ {
f = XFRAME (XCAR (tail)); f = XFRAME (frame);
if (FRAME_X_P (f) && FRAME_LIVE_P (f)) if (FRAME_X_P (f) && FRAME_LIVE_P (f))
return f; return f;
} }
...@@ -1959,15 +1959,14 @@ frame_for_x_selection (Lisp_Object object) ...@@ -1959,15 +1959,14 @@ frame_for_x_selection (Lisp_Object object)
else if (TERMINALP (object)) else if (TERMINALP (object))
{ {
struct terminal *t = get_terminal (object, 1); struct terminal *t = get_terminal (object, 1);
if (t->type == output_x_window) if (t->type == output_x_window)
{ FOR_EACH_FRAME (tail, frame)
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) {
{ f = XFRAME (frame);
f = XFRAME (XCAR (tail)); if (FRAME_LIVE_P (f) && f->terminal == t)
if (FRAME_LIVE_P (f) && f->terminal == t) return f;
return f; }
}
}
} }
else if (FRAMEP (object)) else if (FRAMEP (object))
{ {
......
...@@ -1438,7 +1438,7 @@ static struct frame * ...@@ -1438,7 +1438,7 @@ static struct frame *
x_frame_of_widget (Widget widget) x_frame_of_widget (Widget widget)
{ {
struct x_display_info *dpyinfo; struct x_display_info *dpyinfo;
Lisp_Object tail; Lisp_Object tail, frame;
struct frame *f; struct frame *f;
dpyinfo = x_display_info_for_display (XtDisplay (widget)); dpyinfo = x_display_info_for_display (XtDisplay (widget));
...@@ -1452,15 +1452,15 @@ x_frame_of_widget (Widget widget) ...@@ -1452,15 +1452,15 @@ x_frame_of_widget (Widget widget)
/* Look for a frame with that top-level widget. Allocate the color /* Look for a frame with that top-level widget. Allocate the color
on that frame to get the right gamma correction value. */ on that frame to get the right gamma correction value. */
for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) FOR_EACH_FRAME (tail, frame)
if (FRAMEP (XCAR (tail)) {
&& (f = XFRAME (XCAR (tail)), f = XFRAME (frame);
(FRAME_X_P (f) if (FRAME_X_P (f)
&& f->output_data.nothing != 1 && f->output_data.nothing != 1
&& FRAME_X_DISPLAY_INFO (f) == dpyinfo)) && FRAME_X_DISPLAY_INFO (f) == dpyinfo
&& f->output_data.x->widget == widget) && f->output_data.x->widget == widget)
return f; return f;
}
emacs_abort (); emacs_abort ();
} }