[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

32.2 Examining Buffer Contents

This section describes 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.

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. Voir la section Text Properties. However, overlays (voir la section 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))
Function: buffer-substring-no-properties start end

This is like buffer-substring, except that it does not copy text properties, just the characters themselves. Voir la section Text Properties.

Function: filter-buffer-substring start end &optional delete noprops

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. If buffer-substring-filters is nil, the value is the unaltered text from the buffer, what buffer-substring would return.

If delete is non-nil, this function deletes the text between start and end after copying it, like delete-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, or delete-and-extract-region when copying into user-accessible data structures such as the kill-ring, X clipboard, and registers. Major and minor modes can add functions to buffer-substring-filters to alter such text as it is copied out of the buffer.

Variable: buffer-substring-filters

This variable should be a list of functions that accept a single argument, a string, and return a string. filter-buffer-substring passes 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 of filter-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.

Function: buffer-string

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"
Function: current-word &optional strict really-word

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 returns nil. Otherwise, a nearby symbol or word on the same line is acceptable.

Function: thing-at-point thing

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

[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

Ce document a été généré par Eric Reinbold le 13 Octobre 2007 en utilisant texi2html 1.78.