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


43.1 Examining Text Near Point

Many functions are provided to look at the characters around point. Several simple functions are described here. See also looking-at in Regexp Search.

Many of these functions take an optional buffer argument. In all such cases, the current buffer will be used if this argument is omitted. In FSF Emacs, and early versions of XEmacs, these functions usually did not have these optional buffer arguments and always operated on the current buffer.

Function: char-after &optional position buffer

This function returns the character in the buffer at (i.e., immediately after) position position. If position is out of range for this purpose, either before the beginning of the buffer, or at or beyond the end, then the value is nil. The default for position is point. If optional argument buffer is nil, the current buffer is assumed.

In the following example, assume that the first character in the buffer is ‘@’:

(char-to-string (char-after 1))
     ⇒ "@"
Function: char-before &optional position buffer

This function returns the character in the current buffer immediately before position position. If position is out of range for this purpose, either at or before the beginning of the buffer, or beyond the end, then the value is nil. The default for position is point. If optional argument buffer is nil, the current buffer is assumed.

Function: following-char &optional buffer

This function returns the character following point in the buffer. This is similar to (char-after (point)). However, if point is at the end of the buffer, then the result of following-char is 0. If optional argument buffer is nil, the current buffer is assumed.

Remember that point is always between characters, and the terminal cursor normally appears over the character following point. Therefore, the character returned by following-char is the character the cursor is over.

In this example, point is between the ‘a’ and the ‘c’.

---------- Buffer: foo ----------
Gentlemen may cry ``Pea∗ce! Peace!,''
but there is no peace.
---------- Buffer: foo ----------
(char-to-string (preceding-char))
     ⇒ "a"
(char-to-string (following-char))
     ⇒ "c"
Function: preceding-char &optional buffer

This function returns the character preceding point in the buffer. See above, under following-char, for an example. If point is at the beginning of the buffer, preceding-char returns 0. If optional argument buffer is nil, the current buffer is assumed.

Function: bobp &optional buffer

This function returns t if point is at the beginning of the buffer. If narrowing is in effect, this means the beginning of the accessible portion of the text. If optional argument buffer is nil, the current buffer is assumed. See also point-min in Point.

Function: eobp &optional buffer

This function returns t if point is at the end of the buffer. If narrowing is in effect, this means the end of accessible portion of the text. If optional argument buffer is nil, the current buffer is assumed. See also point-max in See Point.

Function: bolp &optional buffer

This function returns t if point is at the beginning of a line. If optional argument buffer is nil, the current buffer is assumed. See Text Lines. The beginning of the buffer (or its accessible portion) always counts as the beginning of a line.

Function: eolp &optional buffer

This function returns t if point is at the end of a line. The end of the buffer is always considered the end of a line. If optional argument buffer is nil, the current buffer is assumed. The end of the buffer (or of its accessible portion) is always considered the end of a line.


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