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


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
This function returns a string containing a copy of the text of the region defined by positions start and end in the current buffer. If the arguments are not positions in the accessible portion of the buffer, buffer-substring signals an args-out-of-range error.

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.

If the text being copied has any text properties, these are copied into the string along with the characters they belong to. See section Text Properties. However, overlays (see section Overlays) in the buffer and their properties are ignored, not copied.

---------- 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
"

Function: buffer-substring-no-properties start end
This is like buffer-substring, except that it does not copy text properties, just the characters themselves. See section Text Properties. Here's an example of using this function to get a word to look up in an alist:

(setq flammable
      (assoc (buffer-substring start end)
             '(("wood" . t) ("paper" . t)
               ("steel" . nil) ("asbestos" . nil))))

If this were written using buffer-substring instead, it would not work reliably; any text properties that happened to be in the word copied from the buffer would make the comparisons fail.

Function: buffer-string
This function returns the contents of the accessible portion of the current buffer as a string. This is the portion between (point-min) and (point-max) (see section Narrowing).

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

---------- Buffer: foo ----------

(buffer-string)
     => "This is the contents of buffer foo
"


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