Next: Comparing Text, Previous: Near Point, Up: Text
This section describes functions that allow a Lisp program to convert any portion of the text in the buffer into a string.
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-substringsignals anargs-out-of-rangeerror.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.
Here's an example which assumes Font-Lock mode is not enabled:
---------- 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\n"If the text being copied has any text properties, these are copied into the string along with the characters they belong to. See Text Properties. However, overlays (see Overlays) in the buffer and their properties are ignored, not copied.
For example, if Font-Lock mode is enabled, you might get results like these:
(buffer-substring 1 10) ⇒ #("This is t" 0 1 (fontified t) 1 9 (fontified t))
This is like
buffer-substring, except that it does not copy text properties, just the characters themselves. See Text Properties.
This function passes the buffer text between start and end through the filter functions specified by the variable
buffer-substring-filters, and returns the value from the last filter function. Ifbuffer-substring-filtersisnil, the value is the unaltered text from the buffer, whatbuffer-substringwould return.If delete is non-
nil, this function deletes the text between start and end after copying it, likedelete-and-extract-region.If noprops is non-
nil, the final string returned does not include text properties, while the string passed through the filters still includes text properties from the buffer text.Lisp code should use this function instead of
buffer-substring,buffer-substring-no-properties, ordelete-and-extract-regionwhen copying into user-accessible data structures such as the kill-ring, X clipboard, and registers. Major and minor modes can add functions tobuffer-substring-filtersto alter such text as it is copied out of the buffer.
This variable should be a list of functions that accept a single argument, a string, and return a string.
filter-buffer-substringpasses the buffer substring to the first function in this list, and the return value of each function is passed to the next function. The return value of the last function is used as the return value offilter-buffer-substring.As a special convention, point is set to the start of the buffer text being operated on (i.e., the start argument for
filter-buffer-substring) before these functions are called.If this variable is
nil, no filtering is performed.
This function returns the contents of the entire accessible portion of the current buffer as a string. It is equivalent to
(buffer-substring (point-min) (point-max))---------- Buffer: foo ---------- This is the contents of buffer foo ---------- Buffer: foo ---------- (buffer-string) ⇒ "This is the contents of buffer foo\n"
This function returns the symbol (or word) at or near point, as a string. The return value includes no text properties.
If the optional argument really-word is non-
nil, it finds a word; otherwise, it finds a symbol (which includes both word characters and symbol constituent characters).If the optional argument strict is non-
nil, then point must be in or next to the symbol or word—if no symbol or word is there, the function returnsnil. Otherwise, a nearby symbol or word on the same line is acceptable.
Return the thing around or next to point, as a string.
The argument thing is a symbol which specifies a kind of syntactic entity. Possibilities include
symbol,list,sexp,defun,filename,url,word,sentence,whitespace,line,page, and others.---------- Buffer: foo ---------- Gentlemen may cry ``Pea-!-ce! Peace!,'' but there is no peace. ---------- Buffer: foo ---------- (thing-at-point 'word) ⇒ "Peace" (thing-at-point 'line) ⇒ "Gentlemen may cry ``Peace! Peace!,''\n" (thing-at-point 'whitespace) ⇒ nil
