diff options
| author | Chong Yidong | 2013-12-20 15:12:04 +0800 |
|---|---|---|
| committer | Chong Yidong | 2013-12-20 15:12:04 +0800 |
| commit | f5df4cebdb5e2edfddd8b8e16b1c237e2dd45855 (patch) | |
| tree | 1adb7cc9be1a1ba3ba7d0e90f5c3b59a2a414b1f | |
| parent | ca65efcc2ea7f6876fee2f7d2d929dffa4093f96 (diff) | |
| download | emacs-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/ChangeLog | 6 | ||||
| -rw-r--r-- | doc/lispref/text.texi | 43 | ||||
| -rw-r--r-- | etc/NEWS | 1 | ||||
| -rw-r--r-- | src/ChangeLog | 5 | ||||
| -rw-r--r-- | src/textprop.c | 25 |
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 @@ | |||
| 1 | 2013-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 | |||
| 1 | 2013-12-18 Chong Yidong <cyd@gnu.org> | 7 | 2013-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 | 2828 | This function acts on the text between @var{start} and @var{end}, |
| 2829 | section both italic and green, you can either define a new face that | 2829 | adding the face @var{face} to the @code{face} text property. |
| 2830 | have those attributes, or you can add both these attributes separately | 2830 | @var{face} should be a valid value for the @code{face} property |
| 2831 | to text: | 2831 | (@pxref{Special Properties}), such as a face name or an anonymous face |
| 2832 | (@pxref{Faces}). | ||
| 2833 | |||
| 2834 | If any text in the region already has a non-nil @code{face} property, | ||
| 2835 | those face(s) are retained. This function sets the @code{face} | ||
| 2836 | property to a list of faces, with @var{face} as the first element (by | ||
| 2837 | default) and the pre-existing faces as the remaining elements. If the | ||
| 2838 | optional argument @var{append} is non-@code{nil}, @var{face} is | ||
| 2839 | appended to the end of the list instead. Note that in a face list, | ||
| 2840 | the first occurring value for each attribute takes precedence. | ||
| 2841 | |||
| 2842 | For example, the following code would assign a italicized green face | ||
| 2843 | to 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 | ||
| 2838 | The attribute is (by default) prepended to the list of face | 2851 | The optional argument @var{object}, if non-@code{nil}, specifies a |
| 2839 | attributes, and the first attribute of the same type takes | 2852 | buffer or string to act on, rather than the current buffer. If |
| 2840 | precedence. So if you have two @code{:foreground} specifications, the | 2853 | @var{object} is a string, then @var{start} and @var{end} are |
| 2841 | first one will take effect. | 2854 | zero-based indices into the string. |
| 2842 | |||
| 2843 | If you pass in @var{appendp}, the attribute will be appended instead | ||
| 2844 | of prepended, which means that it will have no effect if there is | ||
| 2845 | already 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 |
| 2850 | is with @code{propertize}: | 2858 | @code{propertize}: |
| 2851 | 2859 | ||
| 2852 | @defun propertize string &rest properties | 2860 | @defun propertize string &rest properties |
| 2853 | This function returns a copy of @var{string} which has the text | 2861 | This 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 | |||
| 3081 | dynamically updating the @code{face} property of characters based on | 3089 | dynamically updating the @code{face} property of characters based on |
| 3082 | the context. | 3090 | the context. |
| 3083 | 3091 | ||
| 3092 | The @code{add-face-text-property} function provides a convenient way | ||
| 3093 | to 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)} |
| 3086 | This property specifies a value for the @code{face} property that Font | 3097 | This property specifies a value for the @code{face} property that Font |
| @@ -164,6 +164,7 @@ Available only on X, this option allows to control over-scrolling | |||
| 164 | using the scroll bar (i.e. dragging the thumb down even when the end | 164 | using the scroll bar (i.e. dragging the thumb down even when the end |
| 165 | of the buffer is visible). | 165 | of 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 |
| 168 | used to conveniently prepend/append new face attributes to text. | 169 | used 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 @@ | |||
| 1 | 2013-12-20 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * textprop.c (Fadd_face_text_property): Doc fix. Rename `appendp' | ||
| 4 | argument to `append'. | ||
| 5 | |||
| 1 | 2013-12-19 Eli Zaretskii <eliz@gnu.org> | 6 | 2013-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. */) | |||
| 1338 | DEFUN ("add-face-text-property", Fadd_face_text_property, | 1338 | DEFUN ("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. |
| 1341 | The third argument FACE specifies the face to add. | 1341 | FACE specifies the face to add. It should be a valid value of the |
| 1342 | If 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 |
| 1343 | face property will be added to the front of the face property list. | 1343 | and values). |
| 1344 | If the optional fourth argument APPENDP is non-nil, append to the end | 1344 | |
| 1345 | of the face property list instead. | 1345 | If any text in the region already has a non-nil `face' property, those |
| 1346 | If the optional fifth argument OBJECT is a buffer (or nil, which means | 1346 | face(s) are retained. This is done by setting the `face' property to |
| 1347 | the current buffer), START and END are buffer positions (integers or | 1347 | a list of faces, with FACE as the first element (by default) and the |
| 1348 | pre-existing faces as the remaining elements. | ||
| 1349 | |||
| 1350 | If optional fourth argument APPEND is non-nil, append FACE to the end | ||
| 1351 | of the face list instead. | ||
| 1352 | |||
| 1353 | If optional fifth argument OBJECT is a buffer (or nil, which means the | ||
| 1354 | current buffer), START and END are buffer positions (integers or | ||
| 1348 | markers). If OBJECT is a string, START and END are 0-based indices | 1355 | markers). If OBJECT is a string, START and END are 0-based indices |
| 1349 | into it. */) | 1356 | into 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; |