Go to the first, previous, next, last section, table of contents.


Horizontal Scrolling

Because we read English from left to right in the "inner loop", and from top to bottom in the "outer loop", horizontal scrolling is not like vertical scrolling. Vertical scrolling involves selection of a contiguous portion of text to display, but horizontal scrolling causes part of each line to go off screen. The amount of horizontal scrolling is therefore specified as a number of columns rather than as a position in the buffer. It has nothing to do with the display-start position returned by window-start.

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 screen 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.

Command: scroll-left count
This function scrolls the selected window count columns to the left (or to the right if count is negative). The return value is the total amount of leftward horizontal scrolling in effect after the change--just like the value returned by window-hscroll (below).

Command: scroll-right count
This function scrolls the selected window count columns to the right (or to the left if count is negative). The return value is the total amount of leftward horizontal scrolling in effect after the change--just like the value returned by window-hscroll (below).

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.

Function: window-hscroll &optional window
This function returns the total leftward horizontal scrolling of window---the number of columns by which the text in window is scrolled left past the left margin.

The value is never negative. It is zero when no horizontal scrolling has been done in window (which is usually the case).

If window is nil, the selected window is used.

(window-hscroll)
     => 0
(scroll-left 5)
     => 5
(window-hscroll)
     => 5

Function: set-window-hscroll window columns
This function sets the number of columns from the left margin that window is scrolled from the value of columns. The argument columns should be zero or positive; if not, it is taken as zero.

The value returned is columns.

(set-window-hscroll (selected-window) 10)
     => 10

Here is how you can determine whether a given position position is off the screen due to horizontal scrolling:

(defun hscroll-on-screen (window position)
  (save-excursion
    (goto-char position)
    (and
     (>= (- (current-column) (window-hscroll window)) 0)
     (< (- (current-column) (window-hscroll window))
        (window-width window)))))


Go to the first, previous, next, last section, table of contents.