aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2013-12-20 15:12:04 +0800
committerChong Yidong2013-12-20 15:12:04 +0800
commitf5df4cebdb5e2edfddd8b8e16b1c237e2dd45855 (patch)
tree1adb7cc9be1a1ba3ba7d0e90f5c3b59a2a414b1f
parentca65efcc2ea7f6876fee2f7d2d929dffa4093f96 (diff)
downloademacs-f5df4cebdb5e2edfddd8b8e16b1c237e2dd45855.tar.gz
emacs-f5df4cebdb5e2edfddd8b8e16b1c237e2dd45855.zip
Add/fix docs for add-face-text-property
* doc/lispref/text.texi (Changing Properties): Improve documentation for add-face-text-property. (Special Properties): Mention add-face-text-property. * src/textprop.c (Fadd_face_text_property): Doc fix. Rename `appendp' argument to `append'.
-rw-r--r--doc/lispref/ChangeLog6
-rw-r--r--doc/lispref/text.texi43
-rw-r--r--etc/NEWS1
-rw-r--r--src/ChangeLog5
-rw-r--r--src/textprop.c25
5 files changed, 55 insertions, 25 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index af09f4371f9..3ae7e0040cc 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,9 @@
12013-12-20 Chong Yidong <cyd@gnu.org>
2
3 * text.texi (Changing Properties): Improve documentation for
4 add-face-text-property.
5 (Special Properties): Mention add-face-text-property.
6
12013-12-18 Chong Yidong <cyd@gnu.org> 72013-12-18 Chong Yidong <cyd@gnu.org>
2 8
3 * customize.texi (Custom Themes): Document custom-known-themes 9 * customize.texi (Custom Themes): Document custom-known-themes
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index aa19338ddaf..b814d553296 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -2825,29 +2825,37 @@ Do not rely on the return value of this function.
2825@end defun 2825@end defun
2826 2826
2827@defun add-face-text-property start end face &optional appendp object 2827@defun add-face-text-property start end face &optional appendp object
2828@code{face} text attributes can be combined. If you want to make a 2828This function acts on the text between @var{start} and @var{end},
2829section both italic and green, you can either define a new face that 2829adding the face @var{face} to the @code{face} text property.
2830have those attributes, or you can add both these attributes separately 2830@var{face} should be a valid value for the @code{face} property
2831to text: 2831(@pxref{Special Properties}), such as a face name or an anonymous face
2832(@pxref{Faces}).
2833
2834If any text in the region already has a non-nil @code{face} property,
2835those face(s) are retained. This function sets the @code{face}
2836property to a list of faces, with @var{face} as the first element (by
2837default) and the pre-existing faces as the remaining elements. If the
2838optional argument @var{append} is non-@code{nil}, @var{face} is
2839appended to the end of the list instead. Note that in a face list,
2840the first occurring value for each attribute takes precedence.
2841
2842For example, the following code would assign a italicized green face
2843to the text between @var{start} and @var{end}:
2832 2844
2833@example 2845@example
2834(add-face-text-property @var{start} @var{end} 'italic) 2846(add-face-text-property @var{start} @var{end} 'italic)
2835(add-face-text-property @var{start} @var{end} '(:foreground "#00ff00")) 2847(add-face-text-property @var{start} @var{end} '(:foreground "red"))
2848(add-face-text-property @var{start} @var{end} '(:foreground "green"))
2836@end example 2849@end example
2837 2850
2838The attribute is (by default) prepended to the list of face 2851The optional argument @var{object}, if non-@code{nil}, specifies a
2839attributes, and the first attribute of the same type takes 2852buffer or string to act on, rather than the current buffer. If
2840precedence. So if you have two @code{:foreground} specifications, the 2853@var{object} is a string, then @var{start} and @var{end} are
2841first one will take effect. 2854zero-based indices into the string.
2842
2843If you pass in @var{appendp}, the attribute will be appended instead
2844of prepended, which means that it will have no effect if there is
2845already an attribute of the same type.
2846
2847@end defun 2855@end defun
2848 2856
2849 The easiest way to make a string with text properties 2857 The easiest way to make a string with text properties is with
2850is with @code{propertize}: 2858@code{propertize}:
2851 2859
2852@defun propertize string &rest properties 2860@defun propertize string &rest properties
2853This function returns a copy of @var{string} which has the text 2861This function returns a copy of @var{string} which has the text
@@ -3081,6 +3089,9 @@ Font Lock mode (@pxref{Font Lock Mode}) works in most buffers by
3081dynamically updating the @code{face} property of characters based on 3089dynamically updating the @code{face} property of characters based on
3082the context. 3090the context.
3083 3091
3092The @code{add-face-text-property} function provides a convenient way
3093to set this text property. @xref{Changing Properties}.
3094
3084@item font-lock-face 3095@item font-lock-face
3085@kindex font-lock-face @r{(text property)} 3096@kindex font-lock-face @r{(text property)}
3086This property specifies a value for the @code{face} property that Font 3097This property specifies a value for the @code{face} property that Font
diff --git a/etc/NEWS b/etc/NEWS
index 9177cec64a7..58cc6c61344 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -164,6 +164,7 @@ Available only on X, this option allows to control over-scrolling
164using the scroll bar (i.e. dragging the thumb down even when the end 164using the scroll bar (i.e. dragging the thumb down even when the end
165of the buffer is visible). 165of the buffer is visible).
166 166
167+++
167** New function `add-face-text-property' has been added, which can be 168** New function `add-face-text-property' has been added, which can be
168used to conveniently prepend/append new face attributes to text. 169used to conveniently prepend/append new face attributes to text.
169 170
diff --git a/src/ChangeLog b/src/ChangeLog
index 74ae25327ab..23857e33a6d 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
12013-12-20 Chong Yidong <cyd@gnu.org>
2
3 * textprop.c (Fadd_face_text_property): Doc fix. Rename `appendp'
4 argument to `append'.
5
12013-12-19 Eli Zaretskii <eliz@gnu.org> 62013-12-19 Eli Zaretskii <eliz@gnu.org>
2 7
3 * xdisp.c (extend_face_to_end_of_line): Use default face, not the 8 * xdisp.c (extend_face_to_end_of_line): Use default face, not the
diff --git a/src/textprop.c b/src/textprop.c
index 5597a781a61..d5f86922ade 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -1338,20 +1338,27 @@ the designated part of OBJECT. */)
1338DEFUN ("add-face-text-property", Fadd_face_text_property, 1338DEFUN ("add-face-text-property", Fadd_face_text_property,
1339 Sadd_face_text_property, 3, 5, 0, 1339 Sadd_face_text_property, 3, 5, 0,
1340 doc: /* Add the face property to the text from START to END. 1340 doc: /* Add the face property to the text from START to END.
1341The third argument FACE specifies the face to add. 1341FACE specifies the face to add. It should be a valid value of the
1342If any text in the region already has any face properties, this new 1342`face' property (typically a face name or a plist of face attributes
1343face property will be added to the front of the face property list. 1343and values).
1344If the optional fourth argument APPENDP is non-nil, append to the end 1344
1345of the face property list instead. 1345If any text in the region already has a non-nil `face' property, those
1346If the optional fifth argument OBJECT is a buffer (or nil, which means 1346face(s) are retained. This is done by setting the `face' property to
1347the current buffer), START and END are buffer positions (integers or 1347a list of faces, with FACE as the first element (by default) and the
1348pre-existing faces as the remaining elements.
1349
1350If optional fourth argument APPEND is non-nil, append FACE to the end
1351of the face list instead.
1352
1353If optional fifth argument OBJECT is a buffer (or nil, which means the
1354current buffer), START and END are buffer positions (integers or
1348markers). If OBJECT is a string, START and END are 0-based indices 1355markers). If OBJECT is a string, START and END are 0-based indices
1349into it. */) 1356into it. */)
1350 (Lisp_Object start, Lisp_Object end, Lisp_Object face, 1357 (Lisp_Object start, Lisp_Object end, Lisp_Object face,
1351 Lisp_Object appendp, Lisp_Object object) 1358 Lisp_Object append, Lisp_Object object)
1352{ 1359{
1353 add_text_properties_1 (start, end, list2 (Qface, face), object, 1360 add_text_properties_1 (start, end, list2 (Qface, face), object,
1354 (NILP (appendp) 1361 (NILP (append)
1355 ? TEXT_PROPERTY_PREPEND 1362 ? TEXT_PROPERTY_PREPEND
1356 : TEXT_PROPERTY_APPEND)); 1363 : TEXT_PROPERTY_APPEND));
1357 return Qnil; 1364 return Qnil;