summaryrefslogtreecommitdiff
path: root/devdocs/elisp/preserving-window-sizes.html
blob: daa2e6fafa27e0910987226e6d2fd0464f2c2d59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 <h3 class="section">Preserving Window Sizes</h3>  <p>A window can get resized explicitly by using one of the functions from the preceding section or implicitly, for example, when resizing an adjacent window, when splitting or deleting a window (see <a href="splitting-windows">Splitting Windows</a>, see <a href="deleting-windows">Deleting Windows</a>) or when resizing the window’s frame (see <a href="frame-size">Frame Size</a>). </p> <p>It is possible to avoid implicit resizing of a specific window when there are one or more other resizable windows on the same frame. For this purpose, Emacs must be advised to <em>preserve</em> the size of that window. There are two basic ways to do that. </p> <dl> <dt id="window-size-fixed">Variable: <strong>window-size-fixed</strong>
</dt> <dd>
<p>If this buffer-local variable is non-<code>nil</code>, the size of any window displaying the buffer cannot normally be changed. Deleting a window or changing the frame’s size may still change the window’s size, if there is no choice. </p> <p>If the value is <code>height</code>, then only the window’s height is fixed; if the value is <code>width</code>, then only the window’s width is fixed. Any other non-<code>nil</code> value fixes both the width and the height. </p> <p>If this variable is <code>nil</code>, this does not necessarily mean that any window showing the buffer can be resized in the desired direction. To determine that, use the function <code>window-resizable</code>. See <a href="resizing-windows">Resizing Windows</a>. </p>
</dd>
</dl> <p>Often <code>window-size-fixed</code> is overly aggressive because it inhibits any attempt to explicitly resize or split an affected window as well. This may even happen after the window has been resized implicitly, for example, when deleting an adjacent window or resizing the window’s frame. The following function tries hard to never disallow resizing such a window explicitly: </p> <dl> <dt id="window-preserve-size">Function: <strong>window-preserve-size</strong> <em>&amp;optional window horizontal preserve</em>
</dt> <dd>
<p>This function (un-)marks the height of window <var>window</var> as preserved for future resize operations. <var>window</var> must be a live window and defaults to the selected one. If the optional argument <var>horizontal</var> is non-<code>nil</code>, it (un-)marks the width of <var>window</var> as preserved. </p> <p>If the optional argument <var>preserve</var> is <code>t</code>, this means to preserve the current height/width of <var>window</var>’s body. The height/width of <var>window</var> will change only if Emacs has no better choice. Resizing a window whose height/width is preserved by this function never throws an error. </p> <p>If <var>preserve</var> is <code>nil</code>, this means to stop preserving the height/width of <var>window</var>, lifting any respective restraint induced by a previous call of this function for <var>window</var>. Calling <code>enlarge-window</code>, <code>shrink-window</code> or <code>fit-window-to-buffer</code> with <var>window</var> as argument may also remove the respective restraint. </p>
</dd>
</dl> <p><code>window-preserve-size</code> is currently invoked by the following functions: </p> <dl compact> <dt><code>fit-window-to-buffer</code></dt> <dd>
<p>If the optional argument <var>preserve-size</var> of that function (see <a href="resizing-windows">Resizing Windows</a>) is non-<code>nil</code>, the size established by that function is preserved. </p> </dd> <dt><code>display-buffer</code></dt> <dd><p>If the <var>alist</var> argument of that function (see <a href="choosing-window">Choosing Window</a>) contains a <code>preserve-size</code> entry, the size of the window produced by that function is preserved. </p></dd> </dl> <p><code>window-preserve-size</code> installs a window parameter (see <a href="window-parameters">Window Parameters</a>) called <code>window-preserved-size</code> which is consulted by the window resizing functions. This parameter will not prevent resizing the window when the window shows another buffer than the one when <code>window-preserve-size</code> was invoked or if its size has changed since then. </p> <p>The following function can be used to check whether the height of a particular window is preserved: </p> <dl> <dt id="window-preserved-size">Function: <strong>window-preserved-size</strong> <em>&amp;optional window horizontal</em>
</dt> <dd><p>This function returns the preserved height of window <var>window</var> in pixels. <var>window</var> must be a live window and defaults to the selected one. If the optional argument <var>horizontal</var> is non-<code>nil</code>, it returns the preserved width of <var>window</var>. It returns <code>nil</code> if the size of <var>window</var> is not preserved. </p></dd>
</dl><div class="_attribution">
  <p class="_attribution-p">
    Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
    <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Preserving-Window-Sizes.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Preserving-Window-Sizes.html</a>
  </p>
</div>