Function: add-display-text-property

add-display-text-property is a byte-compiled function defined in compat-29.el.

Signature

(add-display-text-property START END PROP VALUE &optional OBJECT)

Documentation

[Compatibility function for add-display-text-property, defined in Emacs
29.1. See (compat) Emacs 29.1' for more details.]

Add display property PROP with VALUE to the text from START to END. If any text in the region has a non-nil display property, those properties are retained.

If OBJECT is non-nil, it should be a string or a buffer. If nil, this defaults to the current buffer.

Source Code

;; Defined in ~/.emacs.d/elpa/compat-30.1.0.1/compat-29.el
(compat-defun add-display-text-property (start end prop value ;; <compat-tests:add-display-text-property>
                                               &optional object)
  "Add display property PROP with VALUE to the text from START to END.
If any text in the region has a non-nil `display' property, those
properties are retained.

If OBJECT is non-nil, it should be a string or a buffer.  If nil,
this defaults to the current buffer."
  (let ((sub-start start)
        (sub-end 0)
        disp)
    (while (< sub-end end)
      (setq sub-end (next-single-property-change sub-start 'display object
                                                 (if (stringp object)
                                                     (min (length object) end)
                                                   (min end (point-max)))))
      (if (not (setq disp (get-text-property sub-start 'display object)))
          ;; No old properties in this range.
          (put-text-property sub-start sub-end 'display (list prop value)
                             object)
        ;; We have old properties.
        (let ((vector nil))
          ;; Make disp into a list.
          (setq disp
                (cond
                 ((vectorp disp)
                  (setq vector t)
                  (append disp nil))
                 ((not (consp (car disp)))
                  (list disp))
                 (t
                  disp)))
          ;; Remove any old instances.
          (when-let ((old (assoc prop disp)))
            (setq disp (delete old disp)))
          (setq disp (cons (list prop value) disp))
          (when vector
            (setq disp (vconcat disp)))
          ;; Finally update the range.
          (put-text-property sub-start sub-end 'display disp object)))
      (setq sub-start sub-end))))