@@ -232,6 +232,71 @@ METADATA should be an alist of completion metadata. See
232232
233233; ;;; Defined in subr-x.el
234234
235+ (compat-defun add-remove--display-text-property (start end spec value &optional object remove) ; ; <compat-tests:add-display-text-property>
236+ " Helper function for `add-display-text-property' and `remove-display-text-property' ."
237+ (let ((sub-start start)
238+ (sub-end 0 )
239+ (limit (if (stringp object)
240+ (min (length object) end)
241+ (min end (point-max ))))
242+ disp)
243+ (while (< sub-end end)
244+ (setq sub-end (next-single-property-change sub-start 'display object
245+ limit))
246+ (if (not (setq disp (get-text-property sub-start 'display object)))
247+ ; ; No old properties in this range.
248+ (unless remove
249+ (put-text-property sub-start sub-end 'display (list spec value)
250+ object))
251+ ; ; We have old properties.
252+ (let ((changed nil )
253+ type)
254+ ; ; Make disp into a list.
255+ (setq disp
256+ (cond
257+ ((vectorp disp)
258+ (setq type 'vector )
259+ (seq-into disp 'list ))
260+ ((or (not (consp (car-safe disp)))
261+ ; ; If disp looks like ((margin ...) ...), that's
262+ ; ; still a single display specification.
263+ (eq (caar disp) 'margin ))
264+ (setq type 'scalar )
265+ (list disp))
266+ (t
267+ (setq type 'list )
268+ disp)))
269+ ; ; Remove any old instances.
270+ (when-let* ((old (assoc spec disp)))
271+ ; ; If the property value was a list, don't modify the
272+ ; ; original value in place; it could be used by other
273+ ; ; regions of text.
274+ (setq disp (if (eq type 'list )
275+ (remove old disp)
276+ (delete old disp))
277+ changed t ))
278+ (unless remove
279+ (setq disp (cons (list spec value) disp)
280+ changed t ))
281+ (when changed
282+ (if (not disp)
283+ (remove-text-properties sub-start sub-end '(display nil ) object)
284+ (when (eq type 'vector )
285+ (setq disp (seq-into disp 'vector )))
286+ ; ; Finally update the range.
287+ (put-text-property sub-start sub-end 'display disp object)))))
288+ (setq sub-start sub-end))))
289+
290+ (compat-defun remove-display-text-property (start end spec &optional object) ; ; <compat-tests:remove-display-text-property>
291+ " Remove the display specification SPEC from the text from START to END.
292+ SPEC is the car of the display specification to remove, e.g. `height' .
293+ If any text in the region has other display specifications, those specs
294+ are retained.
295+
296+ OBJECT is either a string or a buffer to remove the specification from.
297+ If omitted, OBJECT defaults to the current buffer."
298+ (add-remove--display-text-property start end spec nil object 'remove ))
299+
235300(compat-defvar work-buffer--list nil ; ; <compat-tests:with-work-buffer>
236301 " List of work buffers." )
237302
0 commit comments