Go to the previous, next section.

Counting Columns

The column functions convert between a character position (counting characters from the beginning of the buffer) and a column position (counting screen characters from the beginning of a line).

Column number computations ignore the width of the window and the amount of horizontal scrolling. Consequently, a column value can be arbitrarily high. The first (or leftmost) column is numbered 0.

A character counts according to the number of columns it occupies on the screen. This means control characters count as occupying 2 or 4 columns, depending upon the value of ctl-arrow, and tabs count as occupying a number of columns that depends on the value of tab-width and on the column where the tab begins. See section Usual Display Conventions.

Function: current-column

This function returns the horizontal position of point, measured in columns, counting from 0 at the left margin. The column count is calculated by adding together the widths of all the displayed representations of the characters between the start of the current line and point.

For a more complicated example of the use of current-column, see the description of count-lines in section Motion by Text Lines.

Function: move-to-column column &optional force

This function moves point to column in the current line. The calculation of column takes into account the widths of all the displayed representations of the characters between the start of the line and point.

If the argument column is greater than the column position of the end of the line, point moves to the end of the line. If column is negative, point moves to the beginning of the line.

If it is impossible to move to column column because that is in the middle of a multicolumn character such as a tab, point moves to the end of that character. However, if force is non-nil, and column is in the middle of a tab, then move-to-column converts the tab into spaces so that it can move precisely to column column.

The argument force also has an effect if the line isn't long enough to reach column column; in that case, it says to indent at the end of the line to reach that column.

If column is not an integer, an error is signaled.

The return value is the column number actually moved to.

Go to the previous, next section.