Next: , Previous: , Up: Text   [Contents][Index]


43.15 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).

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 Usual Display.

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.

Function: current-column &optional buffer

This function returns the horizontal position of point, measured in columns, counting from 0 at the left margin.

This is calculated by adding together the widths of all the displayed representations of the character between the start of the previous line and point. (e.g. control characters will have a width of 2 or 4, tabs will have a variable width.)

Ignores the finite width of frame displaying the buffer, which means that this function may return values greater than (frame-width).

Whether the line is visible (if selective-display is t) has no effect; however, ^M is treated as end of line when selective-display is t.

If buffer is nil, the current buffer is assumed.

For an example of using current-column, see the description of count-lines in Text Lines.

Function: move-to-column column &optional force buffer

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

If column column is beyond 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. Other multicolumn characters can cause anomalies despite force, since there is no way to split them.

The argument force also has an effect if the line isn’t long enough to reach column column; in that case, unless the value of force is the special value coerce, it says to add whitespace at the end of the line to reach that column.

If column is not a non-negative integer, an error is signaled.

The return value is the column number actually moved to.


Next: , Previous: , Up: Text   [Contents][Index]