[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

28.14 The Size of a Window

An Emacs window is rectangular, and its size information consists of the height (the number of lines) and the width (the number of character positions in each line). The mode line is included in the height. But the width does not count the scroll bar or the column of `|' characters that separates side-by-side windows.

The following three functions return size information about a window:

Function: window-height &optional window
This function returns the number of lines in window, including its mode line. If window fills its entire frame, this is typically one less than the value of frame-height on that frame (since the last line is always reserved for the minibuffer).

If window is nil, the function uses the selected window.

 
(window-height)
     => 23
(split-window-vertically)
     => #<window 4 on windows.texi>
(window-height)
     => 11

Function: window-width &optional window
This function returns the number of columns in window. If window fills its entire frame, this is the same as the value of frame-width on that frame. The width does not include the window's scroll bar or the column of `|' characters that separates side-by-side windows.

If window is nil, the function uses the selected window.

 
(window-width)
     => 80

Function: window-edges &optional window
This function returns a list of the edge coordinates of window. If window is nil, the selected window is used.

The order of the list is (left top right bottom), all elements relative to 0, 0 at the top left corner of the frame. The element right of the value is one more than the rightmost column used by window, and bottom is one more than the bottommost row used by window and its mode-line.

If a window has a scroll bar, the right edge value includes the width of the scroll bar. Otherwise, if the window has a neighbor on the right, its right edge value includes the width of the separator line between the window and that neighbor. Since the width of the window does not include this separator, the width does not usually equal the difference between the right and left edges.

Here is the result obtained on a typical 24-line terminal with just one window:

 
(window-edges (selected-window))
     => (0 0 80 23)

The bottom edge is at line 23 because the last line is the echo area.

If window is at the upper left corner of its frame, then bottom is the same as the value of (window-height), right is almost the same as the value of (window-width), and top and left are zero. For example, the edges of the following window are `0 0 8 5'. Assuming that the frame has more than 8 columns, the last column of the window (column 7) holds a border rather than text. The last row (row 4) holds the mode line, shown here with `xxxxxxxxx'.

 
           0
           _______
        0 |       |
          |       |
          |       |
          |       |
          xxxxxxxxx  4

                  7

In the following example, let's suppose that the frame is 7 columns wide. Then the edges of the left window are `0 0 4 3' and the edges of the right window are `4 0 8 3'.

 
           ___ ___
          |   |   |
          |   |   |
          xxxxxxxxx

           0  34  7


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on May 2, 2002 using texi2html