; Improve documentation of text-property-search-* functions
* doc/lispref/text.texi (Property Search): Improve wording and markup. * lisp/emacs-lisp/text-property-search.el (text-property-search-forward) (text-property-search-backward): Doc fixes. (Bug#64367)
This commit is contained in:
parent
cc660bd265
commit
fc6099bf04
2 changed files with 47 additions and 39 deletions
|
@ -3398,37 +3398,43 @@ for @var{object} is the current buffer.
|
||||||
@end defun
|
@end defun
|
||||||
|
|
||||||
@defun text-property-search-forward prop &optional value predicate not-current
|
@defun text-property-search-forward prop &optional value predicate not-current
|
||||||
Search for the next region that has text property @var{prop} set to
|
Search for the next region of text whose property @var{prop} is a
|
||||||
@var{value} according to @var{predicate}.
|
match for @var{value} (which defaults to @code{nil}), according to
|
||||||
|
@var{predicate}.
|
||||||
|
|
||||||
This function is modeled after @code{search-forward} and friends in
|
This function is modeled after @code{search-forward} (@pxref{String
|
||||||
that it moves point, but it returns a structure that describes the
|
Search}) and friends, in that it moves point, but it also returns a
|
||||||
match instead of returning it in @code{match-beginning} and friends.
|
structure that describes the match instead of returning it in
|
||||||
|
@code{match-beginning} and friends.
|
||||||
|
|
||||||
If the text property can't be found, the function returns @code{nil}.
|
If the text property whose value is a match can't be found, the
|
||||||
If it's found, point is placed at the end of the region that has this
|
function returns @code{nil}. If it's found, point is placed at the
|
||||||
text property match, and a @code{prop-match} structure is returned.
|
end of the region that has this matching text property, and the
|
||||||
|
function returns a @code{prop-match} structure with information about
|
||||||
|
the match.
|
||||||
|
|
||||||
@var{predicate} can either be @code{t} (which is a synonym for
|
@var{predicate} can either be @code{t} (which is a synonym for
|
||||||
@code{equal}), @code{nil} (which means ``not equal''), or a predicate
|
@code{equal}), @code{nil} (which means ``not equal''), or a predicate
|
||||||
that will be called with two parameters: The first is @var{value}, and
|
that will be called with two arguments: @var{value} and the value of
|
||||||
the second is the value of the text property we're inspecting.
|
the text property @var{prop} at the buffer position that is a
|
||||||
|
candidate for a match. The function should return non-@code{nil} if
|
||||||
|
there's a match, @code{nil} otherwise.
|
||||||
|
|
||||||
If @var{not-current}, if point is in a region where we have a match,
|
If @var{not-current} is non-@code{nil}, then if point is already in a
|
||||||
then skip past that and find the next instance instead.
|
region where we have a property match, skip past that region and find
|
||||||
|
the next region instead.
|
||||||
|
|
||||||
The @code{prop-match} structure has the following accessors:
|
The @code{prop-match} structure has the following accessor functionss:
|
||||||
@code{prop-match-beginning} (the start of the match),
|
@code{prop-match-beginning} (the start of the match),
|
||||||
@code{prop-match-end} (the end of the match), and
|
@code{prop-match-end} (the end of the match), and
|
||||||
@code{prop-match-value} (the value of @var{property} at the start of
|
@code{prop-match-value} (the value of @var{property} at the start of
|
||||||
the match).
|
the match).
|
||||||
|
|
||||||
In the examples below, imagine that you're in a buffer that looks like
|
In the examples below, we use a buffer whose contents is:
|
||||||
this:
|
|
||||||
|
|
||||||
@example
|
@display
|
||||||
This is a bold and here's bolditalic and this is the end.
|
This is a @b{bold} and here's @b{@i{bolditalic}} and this is the end.
|
||||||
@end example
|
@end display
|
||||||
|
|
||||||
That is, the ``bold'' words are the @code{bold} face, and the
|
That is, the ``bold'' words are the @code{bold} face, and the
|
||||||
``italic'' word is in the @code{italic} face.
|
``italic'' word is in the @code{italic} face.
|
||||||
|
@ -3452,8 +3458,9 @@ This will pick out all the words that use the @code{bold} face.
|
||||||
@end lisp
|
@end lisp
|
||||||
|
|
||||||
This will pick out all the bits that have no face properties, which
|
This will pick out all the bits that have no face properties, which
|
||||||
will result in the list @samp{("This is a " "and here's " "and this is
|
will result in the list @samp{(@w{"This is a "} @w{"and here's "}
|
||||||
the end")} (only reversed, since we used @code{push}).
|
@w{"and this is the end"})} (only in reverse order, since we used
|
||||||
|
@code{push}, @pxref{List Variables}).
|
||||||
|
|
||||||
@lisp
|
@lisp
|
||||||
(while (setq match (text-property-search-forward 'face nil nil))
|
(while (setq match (text-property-search-forward 'face nil nil))
|
||||||
|
@ -3481,8 +3488,8 @@ This will give you a list of all those URLs.
|
||||||
|
|
||||||
@defun text-property-search-backward prop &optional value predicate not-current
|
@defun text-property-search-backward prop &optional value predicate not-current
|
||||||
This is just like @code{text-property-search-forward}, but searches
|
This is just like @code{text-property-search-forward}, but searches
|
||||||
backward instead. Point is placed at the beginning of the matched
|
backward instead, and if a match is found, point is placed at the
|
||||||
region instead of the end, though.
|
beginning of the matched region instead of the end.
|
||||||
@end defun
|
@end defun
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,40 +31,41 @@
|
||||||
|
|
||||||
(defun text-property-search-forward (property &optional value predicate
|
(defun text-property-search-forward (property &optional value predicate
|
||||||
not-current)
|
not-current)
|
||||||
"Search for the next region of text where PREDICATE is true.
|
"Search for next region of text where PREDICATE returns non-nil for PROPERTY.
|
||||||
PREDICATE is used to decide whether a value of PROPERTY should be
|
PREDICATE is used to decide whether the value of PROPERTY at a given
|
||||||
considered as matching VALUE.
|
buffer position should be considered as a match for VALUE.
|
||||||
|
VALUE defaults to nil if omitted.
|
||||||
|
|
||||||
If PREDICATE is a function, it will be called with two arguments:
|
If PREDICATE is a function, it will be called with two arguments:
|
||||||
VALUE and the value of PROPERTY. The function should return
|
VALUE and the value of PROPERTY at some buffer position. The function
|
||||||
non-nil if these two values are to be considered a match.
|
should return non-nil if these two values are to be considered a match.
|
||||||
|
|
||||||
Two special values of PREDICATE can also be used:
|
Two special values of PREDICATE can also be used:
|
||||||
If PREDICATE is t, that means a value must `equal' VALUE to be
|
If PREDICATE is t, that means the value of PROPERTY must `equal' VALUE
|
||||||
considered a match.
|
to be considered a match.
|
||||||
If PREDICATE is nil (which is the default value), a value will
|
If PREDICATE is nil (which is the default), the value of PROPERTY will
|
||||||
match if is not `equal' to VALUE. Furthermore, a nil PREDICATE
|
match if it is not `equal' to VALUE. Furthermore, a nil PREDICATE
|
||||||
means that the match region is ended if the value changes. For
|
means that the match region ends where the value changes. For
|
||||||
instance, this means that if you loop with
|
instance, this means that if you loop with
|
||||||
|
|
||||||
(while (setq prop (text-property-search-forward \\='face))
|
(while (setq prop (text-property-search-forward \\='face))
|
||||||
...)
|
...)
|
||||||
|
|
||||||
you will get all distinct regions with non-nil `face' values in
|
you will get all the distinct regions with non-nil `face' values in
|
||||||
the buffer, and the `prop' object will have the details about the
|
the buffer, and the `prop' object will have the details about the
|
||||||
match. See the manual for more details and examples about how
|
match. See the manual for more details and examples about how
|
||||||
VALUE and PREDICATE interact.
|
VALUE and PREDICATE interact.
|
||||||
|
|
||||||
If NOT-CURRENT is non-nil, the function will search for the first
|
If NOT-CURRENT is non-nil, current buffer position is not examined for
|
||||||
region that doesn't include point and has a value of PROPERTY
|
matches: the function will search for the first region that doesn't
|
||||||
that matches VALUE.
|
include point and has a value of PROPERTY that matches VALUE.
|
||||||
|
|
||||||
If no matches can be found, return nil and don't move point.
|
If no matches can be found, return nil and don't move point.
|
||||||
If found, move point to the end of the region and return a
|
If found, move point to the end of the region and return a
|
||||||
`prop-match' object describing the match. To access the details
|
`prop-match' object describing the match. To access the details
|
||||||
of the match, use `prop-match-beginning' and `prop-match-end' for
|
of the match, use `prop-match-beginning' and `prop-match-end' for
|
||||||
the buffer positions that limit the region, and
|
the buffer positions that limit the region, and `prop-match-value'
|
||||||
`prop-match-value' for the value of PROPERTY in the region."
|
for the value of PROPERTY in the region."
|
||||||
(interactive
|
(interactive
|
||||||
(list
|
(list
|
||||||
(let ((string (completing-read "Search for property: " obarray)))
|
(let ((string (completing-read "Search for property: " obarray)))
|
||||||
|
@ -134,7 +135,7 @@ the buffer positions that limit the region, and
|
||||||
|
|
||||||
(defun text-property-search-backward (property &optional value predicate
|
(defun text-property-search-backward (property &optional value predicate
|
||||||
not-current)
|
not-current)
|
||||||
"Search for the previous region of text whose PROPERTY matches VALUE.
|
"Search for previous region of text where PREDICATE returns non-nil for PROPERTY.
|
||||||
|
|
||||||
Like `text-property-search-forward', which see, but searches backward,
|
Like `text-property-search-forward', which see, but searches backward,
|
||||||
and if a matching region is found, place point at the start of the region."
|
and if a matching region is found, place point at the start of the region."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue