Commit d9f07150 authored by Dmitry Antipov's avatar Dmitry Antipov

Widely used frame validity and checking functions.

* frame.h (decode_live_frame, decode_any_frame): Add prototypes.
* frame.c (decode_live_frame, decode_any_frame): New functions.
(delete_frame, Fredirect_frame_focus, Fframe_parameters)
(Fframe_parameter, Fframe_char_height, Fframe_char_width)
(Fframe_pixel_height, Fframe_pixel_width, Ftool_bar_pixel_width)
(Fframe_pointer_visible_p): Use decode_any_frame.
(Fmake_frame_visible, Fmake_frame_invisible, Ficonify_frame)
(Fraise_frame, Flower_frame, Fmodify_frame_parameters)
(Fset_frame_height, Fset_frame_width): Use decode_live_frame.
(Fframe_focus): Likewise.  Allow zero number of arguments.
Adjust docstring.
(frame_buffer_list, frame_buffer_predicate): Remove.
* lisp.h (frame_buffer_predicate): Remove prototype.
* buffer.c (Fother_buffer): Use decode_any_frame.
* xdisp.c (Ftool_bar_lines_needed): Likewise.
* xfaces.c (Fcolor_gray_p, Fcolor_supported_p): Likewise.
* font.c (Ffont_face_attributes, Ffont_family_list, Fopen_font)
(Fclose_font, Ffont_info): Use decode_live_frame.
* fontset.c (check_fontset_name): Likewise.
* terminal.c (Fframe_terminal): Likewise.
* w32fns.c (check_x_frame): Likewise.
* window.c (Fminibuffer_window, Fwindow_at)
(Fcurrent_window_configuration): Likewise.
(Frun_window_configuration_change_hook, Fwindow_resize_apply):
Likewise.  Allow zero number of arguments.  Adjust docstring.
* dispnew.c (Fredraw_frame): Likewise.
* xfaces.c (frame_or_selected_frame): Remove.
(Fx_list_fonts, Finternal_get_lisp_face_attribute, Fface_font)
(Finternal_lisp_face_equal_p, Finternal_lisp_face_empty_p)
(Fframe_face_alist): Use decode_live_frame.
* xfns.c (check_x_frame): Likewise.
parent 8e6a67b7
2012-11-06 Dmitry Antipov <dmantipov@yandex.ru>
Widely used frame validity and checking functions.
* frame.h (decode_live_frame, decode_any_frame): Add prototypes.
* frame.c (decode_live_frame, decode_any_frame): New functions.
(delete_frame, Fredirect_frame_focus, Fframe_parameters)
(Fframe_parameter, Fframe_char_height, Fframe_char_width)
(Fframe_pixel_height, Fframe_pixel_width, Ftool_bar_pixel_width)
(Fframe_pointer_visible_p): Use decode_any_frame.
(Fmake_frame_visible, Fmake_frame_invisible, Ficonify_frame)
(Fraise_frame, Flower_frame, Fmodify_frame_parameters)
(Fset_frame_height, Fset_frame_width): Use decode_live_frame.
(Fframe_focus): Likewise. Allow zero number of arguments.
Adjust docstring.
(frame_buffer_list, frame_buffer_predicate): Remove.
* lisp.h (frame_buffer_predicate): Remove prototype.
* buffer.c (Fother_buffer): Use decode_any_frame.
* xdisp.c (Ftool_bar_lines_needed): Likewise.
* xfaces.c (Fcolor_gray_p, Fcolor_supported_p): Likewise.
* font.c (Ffont_face_attributes, Ffont_family_list, Fopen_font)
(Fclose_font, Ffont_info): Use decode_live_frame.
* fontset.c (check_fontset_name): Likewise.
* terminal.c (Fframe_terminal): Likewise.
* w32fns.c (check_x_frame): Likewise.
* window.c (Fminibuffer_window, Fwindow_at)
(Fcurrent_window_configuration): Likewise.
(Frun_window_configuration_change_hook, Fwindow_resize_apply):
Likewise. Allow zero number of arguments. Adjust docstring.
* dispnew.c (Fredraw_frame): Likewise.
* xfaces.c (frame_or_selected_frame): Remove.
(Fx_list_fonts, Finternal_get_lisp_face_attribute, Fface_font)
(Finternal_lisp_face_equal_p, Finternal_lisp_face_empty_p)
(Fframe_face_alist): Use decode_live_frame.
* xfns.c (check_x_frame): Likewise.
2012-11-06 Dmitry Antipov <dmantipov@yandex.ru>
* window.c (quad): New function.
......
......@@ -1543,17 +1543,11 @@ list first, followed by the list of all buffers. If no other buffer
exists, return the buffer `*scratch*' (creating it if necessary). */)
(register Lisp_Object buffer, Lisp_Object visible_ok, Lisp_Object frame)
{
Lisp_Object tail, buf, pred;
Lisp_Object notsogood = Qnil;
struct frame *f = decode_any_frame (frame);
Lisp_Object tail = f->buffer_list, pred = f->buffer_predicate;
Lisp_Object buf, notsogood = Qnil;
if (NILP (frame))
frame = selected_frame;
CHECK_FRAME (frame);
pred = frame_buffer_predicate (frame);
/* Consider buffers that have been seen in the frame first. */
tail = XFRAME (frame)->buffer_list;
for (; CONSP (tail); tail = XCDR (tail))
{
buf = XCAR (tail);
......
......@@ -3071,14 +3071,12 @@ window_to_frame_hpos (struct window *w, int hpos)
Redrawing Frames
**********************************************************************/
DEFUN ("redraw-frame", Fredraw_frame, Sredraw_frame, 1, 1, 0,
doc: /* Clear frame FRAME and output again what is supposed to appear on it. */)
DEFUN ("redraw-frame", Fredraw_frame, Sredraw_frame, 0, 1, 0,
doc: /* Clear frame FRAME and output again what is supposed to appear on it.
If FRAME is omitted or nil, the selected frame is used. */)
(Lisp_Object frame)
{
struct frame *f;
CHECK_LIVE_FRAME (frame);
f = XFRAME (frame);
struct frame *f = decode_live_frame (frame);
/* Ignore redraw requests, if frame has no glyphs yet.
(Implementation note: It still has to be checked why we are
......
......@@ -3993,16 +3993,11 @@ The optional argument FRAME specifies the frame that the face attributes
are to be displayed on. If omitted, the selected frame is used. */)
(Lisp_Object font, Lisp_Object frame)
{
struct frame *f;
struct frame *f = decode_live_frame (frame);
Lisp_Object plist[10];
Lisp_Object val;
int n = 0;
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
f = XFRAME (frame);
if (STRINGP (font))
{
int fontset = fs_query_fontset (font, 0);
......@@ -4152,18 +4147,15 @@ how close they are to PREFER. */)
DEFUN ("font-family-list", Ffont_family_list, Sfont_family_list, 0, 1, 0,
doc: /* List available font families on the current frame.
Optional argument FRAME, if non-nil, specifies the target frame. */)
If FRAME is omitted or nil, the selected frame is used. */)
(Lisp_Object frame)
{
FRAME_PTR f;
struct frame *f = decode_live_frame (frame);
struct font_driver_list *driver_list;
Lisp_Object list;
Lisp_Object list = Qnil;
XSETFRAME (frame, f);
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
f = XFRAME (frame);
list = Qnil;
for (driver_list = f->font_driver_list; driver_list;
driver_list = driver_list->next)
if (driver_list->driver->list_family)
......@@ -4531,11 +4523,9 @@ DEFUN ("open-font", Fopen_font, Sopen_font, 1, 3, 0,
(Lisp_Object font_entity, Lisp_Object size, Lisp_Object frame)
{
EMACS_INT isize;
struct frame *f = decode_live_frame (frame);
CHECK_FONT_ENTITY (font_entity);
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
if (NILP (size))
isize = XINT (AREF (font_entity, FONT_SIZE_INDEX));
......@@ -4543,7 +4533,7 @@ DEFUN ("open-font", Fopen_font, Sopen_font, 1, 3, 0,
{
CHECK_NUMBER_OR_FLOAT (size);
if (FLOATP (size))
isize = POINT_TO_PIXEL (XFLOAT_DATA (size), XFRAME (frame)->resy);
isize = POINT_TO_PIXEL (XFLOAT_DATA (size), f->resy);
else
isize = XINT (size);
if (! (INT_MIN <= isize && isize <= INT_MAX))
......@@ -4551,7 +4541,7 @@ DEFUN ("open-font", Fopen_font, Sopen_font, 1, 3, 0,
if (isize == 0)
isize = 120;
}
return font_open_entity (XFRAME (frame), font_entity, isize);
return font_open_entity (f, font_entity, isize);
}
DEFUN ("close-font", Fclose_font, Sclose_font, 1, 2, 0,
......@@ -4559,10 +4549,7 @@ DEFUN ("close-font", Fclose_font, Sclose_font, 1, 2, 0,
(Lisp_Object font_object, Lisp_Object frame)
{
CHECK_FONT_OBJECT (font_object);
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
font_close_object (XFRAME (frame), font_object);
font_close_object (decode_live_frame (frame), font_object);
return Qnil;
}
......@@ -4847,7 +4834,7 @@ where
If the named font is not yet loaded, return nil. */)
(Lisp_Object name, Lisp_Object frame)
{
FRAME_PTR f;
struct frame *f;
struct font *font;
Lisp_Object info;
Lisp_Object font_object;
......@@ -4856,10 +4843,7 @@ If the named font is not yet loaded, return nil. */)
if (! FONTP (name))
CHECK_STRING (name);
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
f = XFRAME (frame);
f = decode_live_frame (frame);
if (STRINGP (name))
{
......
......@@ -1326,17 +1326,14 @@ static Lisp_Object
check_fontset_name (Lisp_Object name, Lisp_Object *frame)
{
int id;
struct frame *f = decode_live_frame (*frame);
if (NILP (*frame))
*frame = selected_frame;
CHECK_LIVE_FRAME (*frame);
XSETFRAME (*frame, f);
if (EQ (name, Qt))
return Vdefault_fontset;
if (NILP (name))
{
id = FRAME_FONTSET (XFRAME (*frame));
}
id = FRAME_FONTSET (f);
else
{
CHECK_STRING (name);
......
This diff is collapsed.
......@@ -943,6 +943,8 @@ extern Lisp_Object Qnoelisp;
extern struct frame *last_nonminibuf_frame;
extern void set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
extern struct frame *decode_live_frame (Lisp_Object);
extern struct frame *decode_any_frame (Lisp_Object);
extern struct frame *make_initial_frame (void);
extern struct frame *make_frame (int);
#ifdef HAVE_WINDOW_SYSTEM
......
......@@ -3298,7 +3298,6 @@ extern Lisp_Object do_switch_frame (Lisp_Object, int, int, Lisp_Object);
#if HAVE_NS
extern Lisp_Object get_frame_param (struct frame *, Lisp_Object);
#endif
extern Lisp_Object frame_buffer_predicate (Lisp_Object);
extern void frames_discard_buffer (Lisp_Object);
extern void syms_of_frame (void);
......
......@@ -360,14 +360,7 @@ If FRAME is nil, the selected frame is used.
The terminal device is represented by its integer identifier. */)
(Lisp_Object frame)
{
struct terminal *t;
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
t = FRAME_TERMINAL (XFRAME (frame));
struct terminal *t = FRAME_TERMINAL (decode_live_frame (frame));
if (!t)
return Qnil;
......
......@@ -264,12 +264,8 @@ have_menus_p (void)
FRAME_PTR
check_x_frame (Lisp_Object frame)
{
FRAME_PTR f;
struct frame *f = decode_live_frame (frame);
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
f = XFRAME (frame);
if (! FRAME_W32_P (f))
error ("Non-W32 frame used");
return f;
......
......@@ -340,10 +340,7 @@ DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0,
If FRAME is omitted or nil, it defaults to the selected frame. */)
(Lisp_Object frame)
{
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
return FRAME_MINIBUF_WINDOW (XFRAME (frame));
return FRAME_MINIBUF_WINDOW (decode_live_frame (frame));
}
DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p,
......@@ -1371,12 +1368,7 @@ The top left corner of the frame is considered to be row 0,
column 0. */)
(Lisp_Object x, Lisp_Object y, Lisp_Object frame)
{
struct frame *f;
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
f = XFRAME (frame);
struct frame *f = decode_live_frame (frame);
/* Check that arguments are integers or floats. */
CHECK_NUMBER_OR_FLOAT (x);
......@@ -3109,12 +3101,12 @@ 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. */)
Srun_window_configuration_change_hook, 0, 1, 0,
doc: /* Run `window-configuration-change-hook' for FRAME.
If FRAME is omitted or nil, it defaults to the selected frame. */)
(Lisp_Object frame)
{
CHECK_LIVE_FRAME (frame);
run_window_configuration_change_hook (XFRAME (frame));
run_window_configuration_change_hook (decode_live_frame (frame));
return Qnil;
}
......@@ -3641,10 +3633,12 @@ window_resize_apply (struct window *w, int horflag)
}
DEFUN ("window-resize-apply", Fwindow_resize_apply, Swindow_resize_apply, 1, 2, 0,
DEFUN ("window-resize-apply", Fwindow_resize_apply, Swindow_resize_apply, 0, 2, 0,
doc: /* Apply requested size values for window-tree of FRAME.
Optional argument HORIZONTAL omitted or nil means apply requested height
values. HORIZONTAL non-nil means apply requested width values.
If FRAME is omitted or nil, it defaults to the selected frame.
Optional argument HORIZONTAL omitted or nil means apply requested
height values. HORIZONTAL non-nil means apply requested width values.
This function checks whether the requested values sum up to a valid
window layout, recursively assigns the new sizes of all child windows
......@@ -3655,17 +3649,10 @@ Note: This function does not check any of `window-fixed-size-p',
be applied on the Elisp level. */)
(Lisp_Object frame, Lisp_Object horizontal)
{
struct frame *f;
struct window *r;
struct frame *f = decode_live_frame (frame);
struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
int horflag = !NILP (horizontal);
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
f = XFRAME (frame);
r = XWINDOW (FRAME_ROOT_WINDOW (f));
if (!window_resize_check (r, horflag)
|| ! EQ (r->new_total,
(horflag ? r->total_cols : r->total_lines)))
......@@ -6148,12 +6135,7 @@ saved by this function. */)
register int n_windows;
register struct save_window_data *data;
register int i;
FRAME_PTR f;
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
f = XFRAME (frame);
struct frame *f = decode_live_frame (frame);
n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
data = ALLOCATE_PSEUDOVECTOR (struct save_window_data, frame_cols,
......
......@@ -11916,19 +11916,14 @@ tool_bar_lines_needed (struct frame *f, int *n_rows)
DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed, Stool_bar_lines_needed,
0, 1, 0,
doc: /* Return the number of lines occupied by the tool bar of FRAME. */)
doc: /* Return the number of lines occupied by the tool bar of FRAME.
If FRAME is nil or omitted, use the selected frame. */)
(Lisp_Object frame)
{
struct frame *f;
struct frame *f = decode_any_frame (frame);
struct window *w;
int nlines = 0;
if (NILP (frame))
frame = selected_frame;
else
CHECK_FRAME (frame);
f = XFRAME (frame);
if (WINDOWP (f->tool_bar_window)
&& (w = XWINDOW (f->tool_bar_window),
WINDOW_TOTAL_LINES (w) > 0))
......
......@@ -669,23 +669,6 @@ x_free_gc (struct frame *f, GC gc)
}
#endif /* HAVE_NS */
/* If FRAME is nil, return a pointer to the selected frame.
Otherwise, check that FRAME is a live frame, and return a pointer
to it. NPARAM is the parameter number of FRAME, for
CHECK_LIVE_FRAME. This is here because it's a frequent pattern in
Lisp function definitions. */
static struct frame *
frame_or_selected_frame (Lisp_Object frame, int nparam)
{
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
return XFRAME (frame);
}
/***********************************************************************
Frames and faces
***********************************************************************/
......@@ -1204,15 +1187,9 @@ FRAME specifies the frame and thus the display for interpreting COLOR.
If FRAME is nil or omitted, use the selected frame. */)
(Lisp_Object color, Lisp_Object frame)
{
struct frame *f;
CHECK_STRING (color);
if (NILP (frame))
frame = selected_frame;
else
CHECK_FRAME (frame);
f = XFRAME (frame);
return face_color_gray_p (f, SSDATA (color)) ? Qt : Qnil;
return (face_color_gray_p (decode_any_frame (frame), SSDATA (color))
? Qt : Qnil);
}
......@@ -1225,17 +1202,10 @@ If FRAME is nil or omitted, use the selected frame.
COLOR must be a valid color name. */)
(Lisp_Object color, Lisp_Object frame, Lisp_Object background_p)
{
struct frame *f;
CHECK_STRING (color);
if (NILP (frame))
frame = selected_frame;
else
CHECK_FRAME (frame);
f = XFRAME (frame);
if (face_color_supported_p (f, SSDATA (color), !NILP (background_p)))
return Qt;
return Qnil;
return (face_color_supported_p (decode_any_frame (frame),
SSDATA (color), !NILP (background_p))
? Qt : Qnil);
}
......@@ -1683,9 +1653,7 @@ the WIDTH times as wide as FACE on FRAME. */)
/* We can't simply call check_x_frame because this function may be
called before any frame is created. */
if (NILP (frame))
frame = selected_frame;
f = frame_or_selected_frame (frame, 2);
f = decode_live_frame (frame);
if (! FRAME_WINDOW_P (f))
{
/* Perhaps we have not yet created any frame. */
......@@ -1693,6 +1661,8 @@ the WIDTH times as wide as FACE on FRAME. */)
frame = Qnil;
face = Qnil;
}
else
XSETFRAME (frame, f);
/* Determine the width standard for comparison with the fonts we find. */
......@@ -3679,21 +3649,12 @@ frame. If FRAME is t, report on the defaults for face SYMBOL (for new
frames). If FRAME is omitted or nil, use the selected frame. */)
(Lisp_Object symbol, Lisp_Object keyword, Lisp_Object frame)
{
Lisp_Object lface, value = Qnil;
struct frame *f = EQ (frame, Qt) ? NULL : decode_live_frame (frame);
Lisp_Object lface = lface_from_face_name (f, symbol, 1), value = Qnil;
CHECK_SYMBOL (symbol);
CHECK_SYMBOL (keyword);
if (EQ (frame, Qt))
lface = lface_from_face_name (NULL, symbol, 1);
else
{
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
lface = lface_from_face_name (XFRAME (frame), symbol, 1);
}
if (EQ (keyword, QCfamily))
value = LFACE_FAMILY (lface);
else if (EQ (keyword, QCfoundry))
......@@ -3876,7 +3837,7 @@ return the font name used for CHARACTER. */)
}
else
{
struct frame *f = frame_or_selected_frame (frame, 1);
struct frame *f = decode_live_frame (frame);
int face_id = lookup_named_face (f, face, 1);
struct face *fface = FACE_FROM_ID (f, face_id);
......@@ -3963,14 +3924,11 @@ If FRAME is omitted or nil, use the selected frame. */)
struct frame *f;
Lisp_Object lface1, lface2;
if (EQ (frame, Qt))
f = NULL;
else
/* Don't use check_x_frame here because this function is called
before X frames exist. At that time, if FRAME is nil,
selected_frame will be used which is the frame dumped with
Emacs. That frame is not an X frame. */
f = frame_or_selected_frame (frame, 2);
/* Don't use check_x_frame here because this function is called
before X frames exist. At that time, if FRAME is nil,
selected_frame will be used which is the frame dumped with
Emacs. That frame is not an X frame. */
f = EQ (frame, Qt) ? NULL : decode_live_frame (frame);
lface1 = lface_from_face_name (f, face1, 1);
lface2 = lface_from_face_name (f, face2, 1);
......@@ -3988,20 +3946,10 @@ If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame. */)
(Lisp_Object face, Lisp_Object frame)
{
struct frame *f;
Lisp_Object lface;
struct frame *f = EQ (frame, Qt) ? NULL : decode_live_frame (frame);
Lisp_Object lface = lface_from_face_name (f, face, 1);
int i;
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
f = XFRAME (frame);
if (EQ (frame, Qt))
lface = lface_from_face_name (NULL, face, 1);
else
lface = lface_from_face_name (f, face, 1);
for (i = 1; i < LFACE_VECTOR_SIZE; ++i)
if (!UNSPECIFIEDP (AREF (lface, i)))
break;
......@@ -4016,8 +3964,7 @@ DEFUN ("frame-face-alist", Fframe_face_alist, Sframe_face_alist,
For internal use only. */)
(Lisp_Object frame)
{
struct frame *f = frame_or_selected_frame (frame, 0);
return f->face_alist;
return decode_live_frame (frame)->face_alist;
}
......@@ -4205,14 +4152,9 @@ or lists of the form (RED GREEN BLUE).
If FRAME is unspecified or nil, the current frame is used. */)
(Lisp_Object color1, Lisp_Object color2, Lisp_Object frame)
{
struct frame *f;
struct frame *f = decode_live_frame (frame);
XColor cdef1, cdef2;
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
f = XFRAME (frame);
if (!(CONSP (color1) && parse_rgb_list (color1, &cdef1))
&& !(STRINGP (color1) && defined_color (f, SSDATA (color1), &cdef1, 0)))
signal_error ("Invalid color", color1);
......
......@@ -164,12 +164,8 @@ have_menus_p (void)
FRAME_PTR
check_x_frame (Lisp_Object frame)
{
FRAME_PTR f;
struct frame *f = decode_live_frame (frame);
if (NILP (frame))
frame = selected_frame;
CHECK_LIVE_FRAME (frame);
f = XFRAME (frame);
if (! FRAME_X_P (f))
error ("Non-X frame used");
return f;
......
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