From: Dmitry Antipov Date: Tue, 6 Nov 2012 13:26:20 +0000 (+0400) Subject: Widely used frame validity and checking functions. X-Git-Tag: emacs-24.3.90~173^2~18^2~191 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d9f07150fc320156377a172fd4a5ec23f13a15c0;p=emacs.git 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. --- diff --git a/src/ChangeLog b/src/ChangeLog index 1daeb7bc0b6..0a277a0d67b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,38 @@ +2012-11-06 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. + 2012-11-06 Dmitry Antipov * window.c (quad): New function. diff --git a/src/buffer.c b/src/buffer.c index 347f27edc3a..24286610570 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -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); diff --git a/src/dispnew.c b/src/dispnew.c index 907259a3e94..4758f4ad76f 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -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 diff --git a/src/font.c b/src/font.c index e960f9b3d13..41dbfd7a757 100644 --- a/src/font.c +++ b/src/font.c @@ -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)) { diff --git a/src/fontset.c b/src/fontset.c index da745b31ca1..b76a216bac2 100644 --- a/src/fontset.c +++ b/src/fontset.c @@ -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); diff --git a/src/frame.c b/src/frame.c index 1d375380d56..52be8be270e 100644 --- a/src/frame.c +++ b/src/frame.c @@ -131,7 +131,24 @@ fset_minibuffer_window (struct frame *f, Lisp_Object val) f->minibuffer_window = val; } - +struct frame * +decode_live_frame (register Lisp_Object frame) +{ + if (NILP (frame)) + frame = selected_frame; + CHECK_LIVE_FRAME (frame); + return XFRAME (frame); +} + +struct frame * +decode_any_frame (register Lisp_Object frame) +{ + if (NILP (frame)) + frame = selected_frame; + CHECK_FRAME (frame); + return XFRAME (frame); +} + static void set_menu_bar_lines_1 (Lisp_Object window, int n) { @@ -1118,23 +1135,12 @@ other_visible_frames (FRAME_PTR f) Lisp_Object delete_frame (Lisp_Object frame, Lisp_Object force) { - struct frame *f; + struct frame *f = decode_any_frame (frame); struct frame *sf = SELECTED_FRAME (); struct kboard *kb; int minibuffer_selected, is_tooltip_frame; - if (EQ (frame, Qnil)) - { - f = sf; - XSETFRAME (frame, f); - } - else - { - CHECK_FRAME (frame); - f = XFRAME (frame); - } - if (! FRAME_LIVE_P (f)) return Qnil; @@ -1146,9 +1152,11 @@ delete_frame (Lisp_Object frame, Lisp_Object force) if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp)) error ("Attempt to delete the only frame"); + XSETFRAME (frame, f); + /* Does this frame have a minibuffer, and is it the surrogate minibuffer for any other frame? */ - if (FRAME_HAS_MINIBUF_P (XFRAME (frame))) + if (FRAME_HAS_MINIBUF_P (f)) { Lisp_Object frames; @@ -1663,25 +1671,23 @@ DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible, If omitted, FRAME defaults to the currently selected frame. */) (Lisp_Object frame) { - if (NILP (frame)) - frame = selected_frame; - - CHECK_LIVE_FRAME (frame); + struct frame *f = decode_live_frame (frame); /* I think this should be done with a hook. */ #ifdef HAVE_WINDOW_SYSTEM - if (FRAME_WINDOW_P (XFRAME (frame))) + if (FRAME_WINDOW_P (f)) { - FRAME_SAMPLE_VISIBILITY (XFRAME (frame)); - x_make_frame_visible (XFRAME (frame)); + FRAME_SAMPLE_VISIBILITY (f); + x_make_frame_visible (f); } #endif - make_frame_visible_1 (XFRAME (frame)->root_window); + make_frame_visible_1 (f->root_window); /* Make menu bar update for the Buffers and Frames menus. */ windows_or_buffers_changed++; + XSETFRAME (frame, f); return frame; } @@ -1722,16 +1728,13 @@ always considered visible, whether or not they are currently being displayed in the terminal. */) (Lisp_Object frame, Lisp_Object force) { - if (NILP (frame)) - frame = selected_frame; + struct frame *f = decode_live_frame (frame); - CHECK_LIVE_FRAME (frame); - - if (NILP (force) && !other_visible_frames (XFRAME (frame))) + if (NILP (force) && !other_visible_frames (f)) error ("Attempt to make invisible the sole visible or iconified frame"); /* Don't allow minibuf_window to remain on a deleted frame. */ - if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window)) + if (EQ (f->minibuffer_window, minibuf_window)) { struct frame *sf = XFRAME (selected_frame); /* Use set_window_buffer instead of Fset_window_buffer (see @@ -1743,8 +1746,8 @@ displayed in the terminal. */) /* I think this should be done with a hook. */ #ifdef HAVE_WINDOW_SYSTEM - if (FRAME_WINDOW_P (XFRAME (frame))) - x_make_frame_invisible (XFRAME (frame)); + if (FRAME_WINDOW_P (f)) + x_make_frame_invisible (f); #endif /* Make menu bar update for the Buffers and Frames menus. */ @@ -1759,19 +1762,10 @@ DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame, If omitted, FRAME defaults to the currently selected frame. */) (Lisp_Object frame) { - if (NILP (frame)) - frame = selected_frame; - - CHECK_LIVE_FRAME (frame); - -#if 0 /* This isn't logically necessary, and it can do GC. */ - /* Don't let the frame remain selected. */ - if (EQ (frame, selected_frame)) - Fhandle_switch_frame (next_frame (frame, Qt)); -#endif + struct frame *f = decode_live_frame (frame); /* Don't allow minibuf_window to remain on an iconified frame. */ - if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window)) + if (EQ (f->minibuffer_window, minibuf_window)) { struct frame *sf = XFRAME (selected_frame); /* Use set_window_buffer instead of Fset_window_buffer (see @@ -1783,8 +1777,8 @@ If omitted, FRAME defaults to the currently selected frame. */) /* I think this should be done with a hook. */ #ifdef HAVE_WINDOW_SYSTEM - if (FRAME_WINDOW_P (XFRAME (frame))) - x_iconify_frame (XFRAME (frame)); + if (FRAME_WINDOW_P (f)) + x_iconify_frame (f); #endif /* Make menu bar update for the Buffers and Frames menus. */ @@ -1848,13 +1842,9 @@ If Emacs is displaying on an ordinary terminal or some other device which doesn't support multiple overlapping frames, this function selects FRAME. */) (Lisp_Object frame) { - struct frame *f; - if (NILP (frame)) - frame = selected_frame; + struct frame *f = decode_live_frame (frame); - CHECK_LIVE_FRAME (frame); - - f = XFRAME (frame); + XSETFRAME (frame, f); if (FRAME_TERMCAP_P (f)) /* On a text terminal select FRAME. */ @@ -1877,14 +1867,7 @@ If Emacs is displaying on an ordinary terminal or some other device which doesn't support multiple overlapping frames, this function does nothing. */) (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); if (FRAME_TERMINAL (f)->frame_raise_lower_hook) (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0); @@ -1920,18 +1903,14 @@ is affected by `select-frame', while the latter is not. The redirection lasts until `redirect-frame-focus' is called to change it. */) (Lisp_Object frame, Lisp_Object focus_frame) { - struct frame *f; - /* Note that we don't check for a live frame here. It's reasonable to redirect the focus of a frame you're about to delete, if you know what other frame should receive those keystrokes. */ - CHECK_FRAME (frame); + struct frame *f = decode_any_frame (frame); if (! NILP (focus_frame)) CHECK_LIVE_FRAME (focus_frame); - f = XFRAME (frame); - fset_focus_frame (f, focus_frame); if (FRAME_TERMINAL (f)->frame_rehighlight_hook) @@ -1941,15 +1920,14 @@ The redirection lasts until `redirect-frame-focus' is called to change it. */) } -DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0, +DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0, doc: /* Return the frame to which FRAME's keystrokes are currently being sent. -This returns nil if FRAME's focus is not redirected. +If FRAME is omitted or nil, the selected frame is used. +Return nil if FRAME's focus is not redirected. See `redirect-frame-focus'. */) (Lisp_Object frame) { - CHECK_LIVE_FRAME (frame); - - return FRAME_FOCUS_FRAME (XFRAME (frame)); + return FRAME_FOCUS_FRAME (decode_live_frame (frame)); } @@ -1972,22 +1950,6 @@ get_frame_param (register struct frame *frame, Lisp_Object prop) } #endif -/* Return the buffer-predicate of the selected frame. */ - -Lisp_Object -frame_buffer_predicate (Lisp_Object frame) -{ - return XFRAME (frame)->buffer_predicate; -} - -/* Return the buffer-list of the selected frame. */ - -static Lisp_Object -frame_buffer_list (Lisp_Object frame) -{ - return XFRAME (frame)->buffer_list; -} - /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */ void @@ -2166,20 +2128,14 @@ DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0, doc: /* Return the parameters-alist of frame FRAME. It is a list of elements of the form (PARM . VALUE), where PARM is a symbol. The meaningful PARMs depend on the kind of frame. -If FRAME is omitted, return information on the currently selected frame. */) +If FRAME is omitted or nil, return information on the currently selected frame. */) (Lisp_Object frame) { Lisp_Object alist; - FRAME_PTR f; + struct frame *f = decode_any_frame (frame); int height, width; struct gcpro gcpro1; - if (NILP (frame)) - frame = selected_frame; - - CHECK_FRAME (frame); - f = XFRAME (frame); - if (!FRAME_LIVE_P (f)) return Qnil; @@ -2240,9 +2196,8 @@ If FRAME is omitted, return information on the currently selected frame. */) : FRAME_MINIBUF_ONLY_P (f) ? Qonly : FRAME_MINIBUF_WINDOW (f))); store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil)); - store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame)); - store_in_alist (&alist, Qburied_buffer_list, - XFRAME (frame)->buried_buffer_list); + store_in_alist (&alist, Qbuffer_list, f->buffer_list); + store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list); /* I think this should be done with a hook. */ #ifdef HAVE_WINDOW_SYSTEM @@ -2267,17 +2222,12 @@ DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0, If FRAME is nil, describe the currently selected frame. */) (Lisp_Object frame, Lisp_Object parameter) { - struct frame *f; - Lisp_Object value; + struct frame *f = decode_any_frame (frame); + Lisp_Object value = Qnil; - if (NILP (frame)) - frame = selected_frame; - else - CHECK_FRAME (frame); CHECK_SYMBOL (parameter); - f = XFRAME (frame); - value = Qnil; + XSETFRAME (frame, f); if (FRAME_LIVE_P (f)) { @@ -2357,14 +2307,9 @@ Note that this functionality is obsolete as of Emacs 22.2, and its use is not recommended. Explicitly check for a frame-parameter instead. */) (Lisp_Object frame, Lisp_Object alist) { - FRAME_PTR f; + struct frame *f = decode_live_frame (frame); register Lisp_Object tail, prop, val; - if (EQ (frame, Qnil)) - frame = selected_frame; - CHECK_LIVE_FRAME (frame); - f = XFRAME (frame); - /* I think this should be done with a hook. */ #ifdef HAVE_WINDOW_SYSTEM if (FRAME_WINDOW_P (f)) @@ -2419,18 +2364,13 @@ use is not recommended. Explicitly check for a frame-parameter instead. */) DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height, 0, 1, 0, doc: /* Height in pixels of a line in the font in frame FRAME. -If FRAME is omitted, the selected frame is used. +If FRAME is omitted or nil, the selected frame is used. For a terminal frame, the value is always 1. */) (Lisp_Object frame) { - struct frame *f; - - if (NILP (frame)) - frame = selected_frame; - CHECK_FRAME (frame); - f = XFRAME (frame); - #ifdef HAVE_WINDOW_SYSTEM + struct frame *f = decode_any_frame (frame); + if (FRAME_WINDOW_P (f)) return make_number (x_char_height (f)); else @@ -2442,19 +2382,14 @@ For a terminal frame, the value is always 1. */) DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width, 0, 1, 0, doc: /* Width in pixels of characters in the font in frame FRAME. -If FRAME is omitted, the selected frame is used. +If FRAME is omitted or nil, the selected frame is used. On a graphical screen, the width is the standard width of the default font. For a terminal screen, the value is always 1. */) (Lisp_Object frame) { - struct frame *f; - - if (NILP (frame)) - frame = selected_frame; - CHECK_FRAME (frame); - f = XFRAME (frame); - #ifdef HAVE_WINDOW_SYSTEM + struct frame *f = decode_any_frame (frame); + if (FRAME_WINDOW_P (f)) return make_number (x_char_width (f)); else @@ -2465,7 +2400,7 @@ For a terminal screen, the value is always 1. */) DEFUN ("frame-pixel-height", Fframe_pixel_height, Sframe_pixel_height, 0, 1, 0, doc: /* Return a FRAME's height in pixels. -If FRAME is omitted, the selected frame is used. The exact value +If FRAME is omitted or nil, the selected frame is used. The exact value of the result depends on the window-system and toolkit in use: In the Gtk+ version of Emacs, it includes only any window (including @@ -2480,12 +2415,7 @@ result is really in characters rather than pixels (i.e., is identical to `frame-height'). */) (Lisp_Object frame) { - struct frame *f; - - if (NILP (frame)) - frame = selected_frame; - CHECK_FRAME (frame); - f = XFRAME (frame); + struct frame *f = decode_any_frame (frame); #ifdef HAVE_WINDOW_SYSTEM if (FRAME_WINDOW_P (f)) @@ -2499,15 +2429,10 @@ DEFUN ("frame-pixel-width", Fframe_pixel_width, Sframe_pixel_width, 0, 1, 0, doc: /* Return FRAME's width in pixels. For a terminal frame, the result really gives the width in characters. -If FRAME is omitted, the selected frame is used. */) +If FRAME is omitted or nil, the selected frame is used. */) (Lisp_Object frame) { - struct frame *f; - - if (NILP (frame)) - frame = selected_frame; - CHECK_FRAME (frame); - f = XFRAME (frame); + struct frame *f = decode_any_frame (frame); #ifdef HAVE_WINDOW_SYSTEM if (FRAME_WINDOW_P (f)) @@ -2521,17 +2446,15 @@ DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width, Stool_bar_pixel_width, 0, 1, 0, doc: /* Return width in pixels of FRAME's tool bar. The result is greater than zero only when the tool bar is on the left -or right side of FRAME. If FRAME is omitted, the selected frame is -used. */) +or right side of FRAME. If FRAME is omitted or nil, the selected frame +is used. */) (Lisp_Object frame) { - if (NILP (frame)) - frame = selected_frame; - CHECK_FRAME (frame); - #ifdef FRAME_TOOLBAR_WIDTH - if (FRAME_WINDOW_P (XFRAME (frame))) - return make_number (FRAME_TOOLBAR_WIDTH (XFRAME (frame))); + struct frame *f = decode_any_frame (frame); + + if (FRAME_WINDOW_P (f)) + return make_number (FRAME_TOOLBAR_WIDTH (f)); #endif return make_number (0); } @@ -2542,13 +2465,9 @@ Optional third arg non-nil means that redisplay should use LINES lines but that the idea of the actual height of the frame should not be changed. */) (Lisp_Object frame, Lisp_Object lines, Lisp_Object pretend) { - register struct frame *f; + register struct frame *f = decode_live_frame (frame); CHECK_TYPE_RANGED_INTEGER (int, lines); - if (NILP (frame)) - frame = selected_frame; - CHECK_LIVE_FRAME (frame); - f = XFRAME (frame); /* I think this should be done with a hook. */ #ifdef HAVE_WINDOW_SYSTEM @@ -2570,12 +2489,9 @@ Optional third arg non-nil means that redisplay should use COLS columns but that the idea of the actual width of the frame should not be changed. */) (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend) { - register struct frame *f; + register struct frame *f = decode_live_frame (frame); + CHECK_TYPE_RANGED_INTEGER (int, cols); - if (NILP (frame)) - frame = selected_frame; - CHECK_LIVE_FRAME (frame); - f = XFRAME (frame); /* I think this should be done with a hook. */ #ifdef HAVE_WINDOW_SYSTEM @@ -4292,12 +4208,7 @@ Otherwise it returns nil. FRAME omitted or nil means the selected frame. This is useful when `make-pointer-invisible' is set. */) (Lisp_Object frame) { - if (NILP (frame)) - frame = selected_frame; - - CHECK_FRAME (frame); - - return (XFRAME (frame)->pointer_invisible ? Qnil : Qt); + return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt; } diff --git a/src/frame.h b/src/frame.h index eea618df797..1dc3ebbaf13 100644 --- a/src/frame.h +++ b/src/frame.h @@ -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 diff --git a/src/lisp.h b/src/lisp.h index e9f47f4ed27..1a76a502ca0 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -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); diff --git a/src/terminal.c b/src/terminal.c index 2c0c60e7345..854ca61f19c 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -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; diff --git a/src/w32fns.c b/src/w32fns.c index 18e29ecaaf5..24760054523 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -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; diff --git a/src/window.c b/src/window.c index 75a8d42d8d1..c32234b5fcd 100644 --- a/src/window.c +++ b/src/window.c @@ -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, diff --git a/src/xdisp.c b/src/xdisp.c index 1ff7819f34d..c01f5deab83 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -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)) diff --git a/src/xfaces.c b/src/xfaces.c index 221387c4b6d..41c618612ac 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -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); diff --git a/src/xfns.c b/src/xfns.c index aca227385bf..9c99902b93d 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -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;