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


Glyph Positions

Position objects are usually used to refer to the position of a character in a buffer, this position (sometimes called the character position may not be the same as the position of the sequence of glyphs printed to represent the character. When a position object is used to refer to the position of a glyph it is called a glyph position.

For example, consider a line in a buffer containing the string `a\tb' (where `\t' represents a tab character). When this is rendered in a buffer the glyphs which will actually be drawn are,

a       b

That is, an `a' glyph, followed by seven (assuming tab-size is set to 8) ` ' glyphs, and lastly a `b' glyph.

The character position of the `b' character in the buffer is #<pos 2 line>, where line is the line's number.

Now the confusing bit: the glyph position of the `b' glyph is #<pos 8 line> since it is actually the ninth glyph to be drawn.

The good news is that most of the time you can forget about glyph positions, they only need to be considered when you're thinking about how the buffer will look when rendered in the window. For example, Lisp programs which indent source code will definitely need to use glyph positions.

Two functions are provided for converting between character and glyph positions and vice versa.

Function: char-to-glyph-pos &optional pos buffer
Return a new position object containing the glyph position of the character at character position pos (or the cursor position) in the specified buffer.

Function: glyph-to-char-pos pos &optional buffer
This function returns a new position object containing the character position of the glyph printed at glyph position pos in the specified buffer.

If the glyph position pos is not the position of the first in a sequence of glyphs representing a single character the position of the next character will be returned.


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