ErgoEmacsEmacsLispBlogEmacsLispBuy Tutorial
Web Hosting by 1&1

28.15 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 (by default the selected window), including any mode line and header line. The result is almost always less than the value of frame-height for the associated frame, because the latter also includes any echo area. Depending on the toolkit in use, the frame height can also include the menu bar and tool bar (see Size and Position). Therefore in general it is not straightforward to compare window and frame heights (see window-full-height-p below).

          (window-height)
               ⇒ 23
          (split-window-vertically)
               ⇒ #<window 4 on windows.texi>
          (window-height)
               ⇒ 11
— Function: window-body-height &optional window

Like window-height but the value does not include the mode line (if any) or the header line (if any).

— Function: window-full-height-p &optional window

This function returns non-nil if window is as tall as the frame that contains it. The default for window is the selected window.

— Function: window-width &optional window

This function returns the number of columns in window. The default for window is the selected window.

The return value does not include the window's scroll bar or the column of ‘|’ characters that separates side-by-side windows. Moreover, the return value does not include the space used for displaying fringes and margins. Hence you cannot, in general, compare the return values of window-width and frame-width for equality to determine whether a window is a wide as the containing frame. Use the function window-full-width-p, see below, instead.

          (window-width)
               ⇒ 80
— Function: window-full-width-p &optional window

This function returns non-nil if window is as wide as the frame that contains it; otherwise nil. The default for window is the selected window.

— Function: window-edges &optional window

This function returns a list of the edge coordinates of window. The default for window is the selected window.

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.

The edges include the space used by the window's scroll bar, display margins, fringes, header line, and mode line, if it has them. Also, 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.

— Function: window-inside-edges &optional window

This is similar to window-edges, but the edge values it returns include only the text area of the window. They do not include the header line, mode line, scroll bar or vertical separator, fringes, or display margins.

Here are the results obtained on a typical 24-line terminal with just one window, with menu bar enabled:

     (window-edges (selected-window))
          ⇒ (0 1 80 23)
     (window-inside-edges (selected-window))
          ⇒ (0 1 80 22)

The bottom edge is at line 23 because the last line is the echo area. The bottom inside edge is at line 22, which is the window's mode line.

If window is at the upper left corner of its frame, and there is no menu bar, then bottom returned by window-edges 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 7 3. The inside edges of the left window are ‘0 0 3 2, and the inside edges of the right window are ‘4 0 7 2,

                ___ ___
               |   |   |
               |   |   |
               xxxxxxxxx
     
                0  34  7
— Function: window-pixel-edges &optional window

This function is like window-edges except that, on a graphical display, the edge values are measured in pixels instead of in character lines and columns.

— Function: window-inside-pixel-edges &optional window

This function is like window-inside-edges except that, on a graphical display, the edge values are measured in pixels instead of in character lines and columns.

blog comments powered by Disqus