summaryrefslogtreecommitdiff
path: root/devdocs/elisp/horizontal-scrolling.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/elisp/horizontal-scrolling.html
new repository
Diffstat (limited to 'devdocs/elisp/horizontal-scrolling.html')
-rw-r--r--devdocs/elisp/horizontal-scrolling.html38
1 files changed, 38 insertions, 0 deletions
diff --git a/devdocs/elisp/horizontal-scrolling.html b/devdocs/elisp/horizontal-scrolling.html
new file mode 100644
index 00000000..b07049ac
--- /dev/null
+++ b/devdocs/elisp/horizontal-scrolling.html
@@ -0,0 +1,38 @@
+ <h3 class="section">Horizontal Scrolling</h3> <p><em>Horizontal scrolling</em> means shifting the image in the window left or right by a specified multiple of the normal character width. Each window has a <em>horizontal scroll position</em>, which is a number, never less than zero. It specifies how far to shift the contents left. Shifting the window contents left generally makes all or part of some characters disappear off the left, and all or part of some other characters appear at the right. The usual value is zero. </p> <p>The horizontal scroll position is measured in units of the normal character width, which is the width of space in the default font. Thus, if the value is 5, that means the window contents are scrolled left by 5 times the normal character width. How many characters actually disappear off to the left depends on their width, and could vary from line to line. </p> <p>Because we read from side to side in the inner loop, and from top to bottom in the outer loop, the effect of horizontal scrolling is not like that of textual or vertical scrolling. Textual scrolling involves selection of a portion of text to display, and vertical scrolling moves the window contents contiguously; but horizontal scrolling causes part of <em>each line</em> to go off screen. </p> <p>Usually, no horizontal scrolling is in effect; then the leftmost column is at the left edge of the window. In this state, scrolling to the right is meaningless, since there is no data to the left of the edge to be revealed by it; so this is not allowed. Scrolling to the left is allowed; it scrolls the first columns of text off the edge of the window and can reveal additional columns on the right that were truncated before. Once a window has a nonzero amount of leftward horizontal scrolling, you can scroll it back to the right, but only so far as to reduce the net horizontal scroll to zero. There is no limit to how far left you can scroll, but eventually all the text will disappear off the left edge. </p> <p>If <code>auto-hscroll-mode</code> is set, redisplay automatically alters the horizontal scrolling of a window as necessary to ensure that point is always visible. However, you can still set the horizontal scrolling value explicitly. The value you specify serves as a lower bound for automatic scrolling, i.e., automatic scrolling will not scroll a window to a column less than the specified one. </p> <p>The default value of <code>auto-hscroll-mode</code> is <code>t</code>; setting it to <code>current-line</code> activates a variant of automatic horizontal scrolling whereby only the line showing the cursor is horizontally scrolled to make point visible, the rest of the window is left either unscrolled, or at the minimum scroll amount set by <code>scroll-left</code> and <code>scroll-right</code>, see below. </p> <dl> <dt id="scroll-left">Command: <strong>scroll-left</strong> <em>&amp;optional count set-minimum</em>
+</dt> <dd>
+<p>This function scrolls the selected window <var>count</var> columns to the left (or to the right if <var>count</var> is negative). The default for <var>count</var> is the window width, minus 2. </p> <p>The return value is the total amount of leftward horizontal scrolling in effect after the change—just like the value returned by <code>window-hscroll</code> (below). </p> <p>Note that text in paragraphs whose base direction is right-to-left (see <a href="bidirectional-display">Bidirectional Display</a>) moves in the opposite direction: e.g., it moves to the right when <code>scroll-left</code> is invoked with a positive value of <var>count</var>. </p> <p>Once you scroll a window as far right as it can go, back to its normal position where the total leftward scrolling is zero, attempts to scroll any farther right have no effect. </p> <p>If <var>set-minimum</var> is non-<code>nil</code>, the new scroll amount becomes the lower bound for automatic scrolling; that is, automatic scrolling will not scroll a window to a column less than the value returned by this function. Interactive calls pass non-<code>nil</code> for <var>set-minimum</var>. </p>
+</dd>
+</dl> <dl> <dt id="scroll-right">Command: <strong>scroll-right</strong> <em>&amp;optional count set-minimum</em>
+</dt> <dd><p>This function scrolls the selected window <var>count</var> columns to the right (or to the left if <var>count</var> is negative). The default for <var>count</var> is the window width, minus 2. Aside from the direction of scrolling, this works just like <code>scroll-left</code>. </p></dd>
+</dl> <dl> <dt id="window-hscroll">Function: <strong>window-hscroll</strong> <em>&amp;optional window</em>
+</dt> <dd>
+<p>This function returns the total leftward horizontal scrolling of <var>window</var>—the number of columns by which the text in <var>window</var> is scrolled left past the left margin. (In right-to-left paragraphs, the value is the total amount of the rightward scrolling instead.) The default for <var>window</var> is the selected window. </p> <p>The return value is never negative. It is zero when no horizontal scrolling has been done in <var>window</var> (which is usually the case). </p> <div class="example"> <pre class="example">(window-hscroll)
+ ⇒ 0
+</pre>
+<pre class="example">(scroll-left 5)
+ ⇒ 5
+</pre>
+<pre class="example">(window-hscroll)
+ ⇒ 5
+</pre>
+</div> </dd>
+</dl> <dl> <dt id="set-window-hscroll">Function: <strong>set-window-hscroll</strong> <em>window columns</em>
+</dt> <dd>
+<p>This function sets horizontal scrolling of <var>window</var>. The value of <var>columns</var> specifies the amount of scrolling, in terms of columns from the left margin (right margin in right-to-left paragraphs). The argument <var>columns</var> should be zero or positive; if not, it is taken as zero. Fractional values of <var>columns</var> are not supported at present. </p> <p>Note that <code>set-window-hscroll</code> may appear not to work if you test it by evaluating a call with <kbd>M-:</kbd> in a simple way. What happens is that the function sets the horizontal scroll value and returns, but then redisplay adjusts the horizontal scrolling to make point visible, and this overrides what the function did. You can observe the function’s effect if you call it while point is sufficiently far from the left margin that it will remain visible. </p> <p>The value returned is <var>columns</var>. </p> <div class="example"> <pre class="example">(set-window-hscroll (selected-window) 10)
+ ⇒ 10
+</pre>
+</div> </dd>
+</dl> <p>Here is how you can determine whether a given position <var>position</var> is off the screen due to horizontal scrolling: </p> <div class="example"> <pre class="example">(defun hscroll-on-screen (window position)
+ (save-excursion
+ (goto-char position)
+ (and
+ (&gt;= (- (current-column) (window-hscroll window)) 0)
+ (&lt; (- (current-column) (window-hscroll window))
+ (window-width window)))))
+</pre>
+</div><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/Horizontal-Scrolling.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Horizontal-Scrolling.html</a>
+ </p>
+</div>