From: Chong Yidong Date: Tue, 8 Nov 2011 07:25:56 +0000 (+0800) Subject: Move low-level window width/height functions to C, and high-level functions to Lisp. X-Git-Tag: emacs-pretest-24.0.92~121^2~26 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=105216ed03e65f32a7477ba3d27ab05c94bd3449;p=emacs.git Move low-level window width/height functions to C, and high-level functions to Lisp. * lisp/window.el (window-total-height, window-total-width): Doc fix. (window-body-size): Move from C. (window-body-height, window-body-width): Move to C. * src/window.c (Fwindow_left_column, Fwindow_top_line): Doc fix. (Fwindow_body_height, Fwindow_body_width): Move from Lisp. Signal an error if not a live window. (Fwindow_total_width, Fwindow_total_height): Move from Lisp. (Fwindow_total_size, Fwindow_body_size): Move to Lisp. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 28e3f79ba6e..394559563e9 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2011-11-08 Chong Yidong + + * window.el (window-total-height, window-total-width): Doc fix. + (window-body-size): Move from C. + (window-body-height, window-body-width): Move to C. + 2011-11-08 Stefan Monnier * window.el: Make special-display like display-buffer-alist (bug#9532). diff --git a/lisp/window.el b/lisp/window.el index 931d265ebab..2f1b2a99a41 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -920,17 +920,16 @@ doc-string of `window-resizable'." (<= (window-resizable window delta horizontal ignore trail noup nodown) delta))) -(defsubst window-total-height (&optional window) - "Return the total number of lines of WINDOW. -WINDOW can be any window and defaults to the selected one. The -return value includes WINDOW's mode line and header line, if any. -If WINDOW is internal the return value is the sum of the total -number of lines of WINDOW's child windows if these are vertically -combined and the height of WINDOW's first child otherwise. - -Note: This function does not take into account the value of -`line-spacing' when calculating the number of lines in WINDOW." - (window-total-size window)) +(defun window-total-size (&optional window horizontal) + "Return the total height or width of window WINDOW. +If WINDOW is omitted or nil, it defaults to the selected window. + +If HORIZONTAL is omitted or nil, return the total height of +WINDOW, in lines, like `window-total-height'. Otherwise return +the total width, in columns, like `window-total-width'." + (if horizontal + (window-total-width window) + (window-total-height window))) ;; Eventually we should make `window-height' obsolete. (defalias 'window-height 'window-total-height) @@ -946,16 +945,6 @@ one." (= (window-total-size window) (window-total-size (frame-root-window window)))) -(defsubst window-total-width (&optional window) - "Return the total number of columns of WINDOW. -WINDOW can be any window and defaults to the selected one. The -return value includes any vertical dividers or scrollbars of -WINDOW. If WINDOW is internal, the return value is the sum of -the total number of columns of WINDOW's child windows if these -are horizontally combined and the width of WINDOW's first child -otherwise." - (window-total-size window t)) - (defsubst window-full-width-p (&optional window) "Return t if WINDOW is as wide as the containing frame. More precisely, return t if and only if the total width of WINDOW @@ -965,40 +954,17 @@ WINDOW can be any window and defaults to the selected one." (= (window-total-size window t) (window-total-size (frame-root-window window) t))) -(defsubst window-body-height (&optional window) - "Return the number of lines of WINDOW's body. -WINDOW must be a live window and defaults to the selected one. - -The return value does not include WINDOW's mode line and header -line, if any. If a line at the bottom of the window is only -partially visible, that line is included in the return value. If -you do not want to include a partially visible bottom line in the -return value, use `window-text-height' instead. - -Note that the return value is measured in canonical units, i.e. for -the default frame's face. If the window shows some characters with -non-default face, e.g., if the font of some characters is larger or -smaller than the default font, the value returned by this function -will not match the actual number of lines shown in the window. To -get the actual number of lines, use `posn-at-point'." - (window-body-size window)) - -(defsubst window-body-width (&optional window) - "Return the number of columns of WINDOW's body. -WINDOW must be a live window and defaults to the selected one. +(defun window-body-size (&optional window horizontal) + "Return the height or width of WINDOW's text area. +If WINDOW is omitted or nil, it defaults to the selected window. +Signal an error if the window is not live. -The return value does not include any vertical dividers or scroll -bars owned by WINDOW. On a window-system the return value does -not include the number of columns used for WINDOW's fringes or -display margins either. - -Note that the return value is measured in canonical units, i.e. for -the default frame's face. If the window shows some characters with -non-default face, e.g., if the font of some characters is larger or -smaller than the default font, the value returned by this function -will not match the actual number of characters per line shown in the -window. To get the actual number of columns, use `posn-at-point'." - (window-body-size window t)) +If HORIZONTAL is omitted or nil, return the height of the text +area, like `window-body-height'. Otherwise, return the width of +the text area, like `window-body-width'." + (if horizontal + (window-body-width window) + (window-body-height window))) ;; Eventually we should make `window-height' obsolete. (defalias 'window-width 'window-body-width) diff --git a/src/ChangeLog b/src/ChangeLog index 54d8af7c708..8d413a21fa5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2011-11-08 Chong Yidong + + * window.c (Fwindow_left_column, Fwindow_top_line): Doc fix. + (Fwindow_body_height, Fwindow_body_width): Move from Lisp. Signal + an error if not a live window. + (Fwindow_total_width, Fwindow_total_height): Move from Lisp. + (Fwindow_total_size, Fwindow_body_size): Move to Lisp. + 2011-11-07 Juanma Barranquero * lisp.h (syms_of_abbrev): Remove declaration. diff --git a/src/window.c b/src/window.c index 162ae08a00f..00e887436d3 100644 --- a/src/window.c +++ b/src/window.c @@ -539,27 +539,34 @@ selected one. */) return decode_window (window)->use_time; } -DEFUN ("window-total-size", Fwindow_total_size, Swindow_total_size, 0, 2, 0, - doc: /* Return the total number of lines of window WINDOW. +DEFUN ("window-total-height", Fwindow_total_height, Swindow_total_height, 0, 1, 0, + doc: /* Return the total height, in lines, of window WINDOW. If WINDOW is omitted or nil, it defaults to the selected window. -The return value includes WINDOW's mode line and header line, if any. -If WINDOW is internal, the return value is the sum of the total number -of lines of WINDOW's child windows if these are vertically combined -and the height of WINDOW's first child otherwise. - -Optional argument HORIZONTAL non-nil means return the total number of -columns of WINDOW. In this case the return value includes any vertical -dividers or scrollbars of WINDOW. If WINDOW is internal, the return -value is the sum of the total number of columns of WINDOW's child -windows if they are horizontally combined and the width of WINDOW's -first child otherwise. */) - (Lisp_Object window, Lisp_Object horizontal) +The return value includes the mode line and header line, if any. +If WINDOW is an internal window, the total height is the height +of the screen areas spanned by its children. + +On a graphical display, this total height is reported as an +integer multiple of the default character height. */) + (Lisp_Object window) { - if (NILP (horizontal)) - return decode_any_window (window)->total_lines; - else - return decode_any_window (window)->total_cols; + return decode_any_window (window)->total_lines; +} + +DEFUN ("window-total-width", Fwindow_total_width, Swindow_total_width, 0, 1, 0, + doc: /* Return the total width, in columns, of window WINDOW. +If WINDOW is omitted or nil, it defaults to the selected window. + +The return value includes any vertical dividers or scroll bars +belonging to WINDOW. If WINDOW is an internal window, the total width +is the width of the screen areas spanned by its children. + +On a graphical display, this total width is reported as an +integer multiple of the default character width. */) + (Lisp_Object window) +{ + return decode_any_window (window)->total_cols; } DEFUN ("window-new-total", Fwindow_new_total, Swindow_new_total, 0, 1, 0, @@ -592,6 +599,10 @@ If WINDOW is omitted or nil, it defaults to the selected window. */) DEFUN ("window-left-column", Fwindow_left_column, Swindow_left_column, 0, 1, 0, doc: /* Return left column of window WINDOW. +This is the distance, in columns, between the left edge of WINDOW and +the left edge of the frame's window area. For instance, the return +value is 0 if there is no window to the left of WINDOW. + If WINDOW is omitted or nil, it defaults to the selected window. */) (Lisp_Object window) { @@ -600,6 +611,10 @@ If WINDOW is omitted or nil, it defaults to the selected window. */) DEFUN ("window-top-line", Fwindow_top_line, Swindow_top_line, 0, 1, 0, doc: /* Return top line of window WINDOW. +This is the distance, in lines, between the top of WINDOW and the top +of the frame's window area. For instance, the return value is 0 if +there is no window above WINDOW. + If WINDOW is omitted or nil, it defaults to the selected window. */) (Lisp_Object window) { @@ -655,34 +670,34 @@ window_body_cols (struct window *w) return width; } -DEFUN ("window-body-size", Fwindow_body_size, Swindow_body_size, 0, 2, 0, - doc: /* Return the number of lines or columns of WINDOW's body. -WINDOW must be a live window and defaults to the selected one. +DEFUN ("window-body-height", Fwindow_body_height, Swindow_body_height, 0, 1, 0, + doc: /* Return the height, in lines, of WINDOW's text area. +If WINDOW is omitted or nil, it defaults to the selected window. +Signal an error if the window is not live. -If the optional argument HORIZONTAL is omitted or nil, the function -returns the number of WINDOW's lines, excluding the mode line and -header line, if any. - -If HORIZONTAL is non-nil, the function returns the number of columns -excluding any vertical dividers or scroll bars owned by WINDOW. On a -window-system the return value also excludes the number of columns -used for WINDOW's fringes or display margins. - -Note that the return value is measured in canonical units, i.e. for -the default frame's face. If the window shows some characters with -non-default face, e.g., if the font of some characters is larger or -smaller than the default font, the value returned by this function -will not match the actual number of lines or characters per line -shown in the window. To get the actual number of columns and lines, -use `posn-at-point'. */) - (Lisp_Object window, Lisp_Object horizontal) +The returned height does not include the mode line or header line. +On a graphical display, the height is expressed as an integer multiple +of the default character height. If a line at the bottom of the text +area is only partially visible, that counts as a whole line; to +exclude partially-visible lines, use `window-text-height'. */) + (Lisp_Object window) { - struct window *w = decode_any_window (window); + struct window *w = decode_window (window); + return make_number (window_body_lines (w)); +} - if (NILP (horizontal)) - return make_number (window_body_lines (w)); - else - return make_number (window_body_cols (w)); +DEFUN ("window-body-width", Fwindow_body_width, Swindow_body_width, 0, 1, 0, + doc: /* Return the width, in columns, of WINDOW's text area. +If WINDOW is omitted or nil, it defaults to the selected window. +Signal an error if the window is not live. + +The return value does not include any vertical dividers, fringe or +marginal areas, or scroll bars. On a graphical display, the width is +expressed as an integer multiple of the default character width. */) + (Lisp_Object window) +{ + struct window *w = decode_window (window); + return make_number (window_body_cols (w)); } DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0, @@ -5218,10 +5233,10 @@ and redisplay normally--don't erase and redraw the frame. */) DEFUN ("window-text-height", Fwindow_text_height, Swindow_text_height, 0, 1, 0, doc: /* Return the height in lines of the text display area of WINDOW. -WINDOW defaults to the selected window. +If WINDOW is omitted or nil, it defaults to the selected window. -The return value does not include the mode line, any header line, nor -any partial-height lines in the text display area. */) +The returned height does not include the mode line, any header line, +nor any partial-height lines at the bottom of the text area. */) (Lisp_Object window) { struct window *w = decode_window (window); @@ -6583,14 +6598,16 @@ function `window-nest' and altered by the function `set-window-nest'. */); defsubr (&Swindow_use_time); defsubr (&Swindow_top_line); defsubr (&Swindow_left_column); - defsubr (&Swindow_total_size); + defsubr (&Swindow_total_height); + defsubr (&Swindow_total_width); defsubr (&Swindow_normal_size); defsubr (&Swindow_new_total); defsubr (&Swindow_new_normal); defsubr (&Sset_window_new_total); defsubr (&Sset_window_new_normal); defsubr (&Swindow_resize_apply); - defsubr (&Swindow_body_size); + defsubr (&Swindow_body_height); + defsubr (&Swindow_body_width); defsubr (&Swindow_hscroll); defsubr (&Sset_window_hscroll); defsubr (&Swindow_redisplay_end_trigger);