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


43.2 Examining Buffer Contents

This section describes two functions that allow a Lisp program to convert any portion of the text in the buffer into a string.

Function: buffer-substring start end &optional buffer
Function: buffer-string start end &optional buffer

These functions are equivalent and return a string containing a copy of the text of the region defined by positions start and end in the buffer. If the arguments are not positions in the accessible portion of the buffer, buffer-substring signals an args-out-of-range error. If optional argument buffer is nil, the current buffer is assumed.

If the region delineated by start and end contains duplicable extents, they will be remembered in the string. See Duplicable Extents.

It is not necessary for start to be less than end; the arguments can be given in either order. But most often the smaller argument is written first.

---------- Buffer: foo ----------
This is the contents of buffer foo

---------- Buffer: foo ----------
(buffer-substring 1 10)
⇒ "This is t"
(buffer-substring (point-max) 10)
⇒ "he contents of buffer foo
"