summaryrefslogtreecommitdiff
path: root/devdocs/elisp/text-props-and-strings.html
blob: 0a08f9df90b615e1e62ffac66a896a12d7caf9fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
 <h4 class="subsubsection">Text Properties in Strings</h4>   <p>A string can hold properties for the characters it contains, in addition to the characters themselves. This enables programs that copy text between strings and buffers to copy the text’s properties with no special effort. See <a href="text-properties">Text Properties</a>, for an explanation of what text properties mean. Strings with text properties use a special read and print syntax: </p> <div class="example"> <pre class="example">#("<var>characters</var>" <var>property-data</var>...)
</pre>
</div> <p>where <var>property-data</var> consists of zero or more elements, in groups of three as follows: </p> <div class="example"> <pre class="example"><var>beg</var> <var>end</var> <var>plist</var>
</pre>
</div> <p>The elements <var>beg</var> and <var>end</var> are integers, and together specify a range of indices in the string; <var>plist</var> is the property list for that range. For example, </p> <div class="example"> <pre class="example">#("foo bar" 0 3 (face bold) 3 4 nil 4 7 (face italic))
</pre>
</div> <p>represents a string whose textual contents are ‘<samp>foo bar</samp>’, in which the first three characters have a <code>face</code> property with value <code>bold</code>, and the last three have a <code>face</code> property with value <code>italic</code>. (The fourth character has no text properties, so its property list is <code>nil</code>. It is not actually necessary to mention ranges with <code>nil</code> as the property list, since any characters not mentioned in any range will default to having no properties.) </p><div class="_attribution">
  <p class="_attribution-p">
    Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
    <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Text-Props-and-Strings.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Text-Props-and-Strings.html</a>
  </p>
</div>