emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/compat 0a84a7c219 48/84: Add add-display-text-property


From: ELPA Syncer
Subject: [elpa] externals/compat 0a84a7c219 48/84: Add add-display-text-property from Emacs 29
Date: Tue, 3 Jan 2023 08:57:35 -0500 (EST)

branch: externals/compat
commit 0a84a7c2195f5dee275072a74b4957fe2ac51774
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>

    Add add-display-text-property from Emacs 29
---
 compat-29.el | 43 +++++++++++++++++++++++++++++++++++++++++++
 compat.texi  | 10 ++++++++++
 2 files changed, 53 insertions(+)

diff --git a/compat-29.el b/compat-29.el
index 0fcd3ad0d6..34b21d6070 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -437,6 +437,49 @@ be marked unmodified, effectively ignoring those changes."
                         (equal ,hash (buffer-hash)))
                (restore-buffer-modified-p nil))))))))
 
+;;* UNTESTED
+(compat-defun add-display-text-property (start end prop value
+                                               &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."
+  :feature 'subr-x
+  (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))
+        ;; We have old properties.
+        (let ((vector nil))
+          ;; Make disp into a list.
+          (setq disp
+                (cond
+                 ((vectorp disp)
+                  (setq vector t)
+                  (seq-into disp 'list))
+                 ((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 (seq-into disp 'vector)))
+          ;; Finally update the range.
+          (put-text-property sub-start sub-end 'display disp)))
+      (setq sub-start sub-end))))
+
 ;;;; Defined in files.el
 
 (compat-defun file-parent-directory (filename)
diff --git a/compat.texi b/compat.texi
index 1c9f1fea94..cb89595c4f 100644
--- a/compat.texi
+++ b/compat.texi
@@ -2289,6 +2289,16 @@ Properties,Examining
 Properties,,elisp,}).
 @end defun
 
+@c copied from lisp/subr-x.el
+@defun add-display-text-property start end prop value &optional object
+Add display property @var{prop} with @var{value} to the text from
+@var{start} to @var{end}.  If any text in the region has a non-nil
+@code{display} property, those properties are retained.
+
+If @var{object} is non-@code{nil}, it should be a string or a buffer.
+If @code{nil}, this defaults to the current buffer.
+@end defun
+
 @c copied from lispref/lists.texi
 @defun take n list
 This function returns the @var{n} first elements of @var{list}.  Essentially,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]