Function: propertize

propertize is a function defined in editfns.c.

Signature

(propertize STRING &rest PROPERTIES)

Documentation

Return a copy of STRING with text properties added.

First argument is the string to copy. Remaining arguments form a sequence of PROPERTY VALUE pairs for text properties to add to the result.

See Info node (elisp) Text Properties for more information.

Other relevant functions are documented in the text-properties group.

Probably introduced at or before Emacs version 21.1.

Shortdoc

;; text-properties
(propertize "foo" 'face 'italic 'mouse-face 'bold-italic)
    => #("foo" 0 3 (mouse-face bold-italic face italic))

Aliases

org-propertize (obsolete since 9.0) erc-propertize (obsolete since 28.1) dd-propertize (obsolete since 28.1)

Source Code

// Defined in /usr/src/emacs/src/editfns.c
{
  Lisp_Object properties, string;
  ptrdiff_t i;

  /* Number of args must be odd.  */
  if ((nargs & 1) == 0)
    xsignal2 (Qwrong_number_of_arguments, Qpropertize, make_fixnum (nargs));

  properties = string = Qnil;

  /* First argument must be a string.  */
  CHECK_STRING (args[0]);
  string = Fcopy_sequence (args[0]);

  for (i = 1; i < nargs; i += 2)
    properties = Fcons (args[i], Fcons (args[i + 1], properties));

  Fadd_text_properties (make_fixnum (0),
			make_fixnum (SCHARS (string)),
			properties, string);
  return string;
}