diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2025-06-17 19:32:26 +0200 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2025-06-17 19:41:44 +0200 |
| commit | 11aeb1c292ffaf6abbd374ce23a0a8f1dcfb9952 (patch) | |
| tree | e809a693525afbf09829b0a9239c1e5b9052c9ec /compat-29.el | |
| parent | a9158a27e11c87c10620743a12a5f0c610b235bd (diff) | |
compat-31: New function remove-display-text-property
Diffstat (limited to 'compat-29.el')
| -rw-r--r-- | compat-29.el | 50 |
1 files changed, 9 insertions, 41 deletions
diff --git a/compat-29.el b/compat-29.el index a0831e6..b6ab5f0 100644 --- a/compat-29.el +++ b/compat-29.el @@ -584,47 +584,15 @@ be marked unmodified, effectively ignoring those changes." (equal ,hash (buffer-hash))) (restore-buffer-modified-p nil)))))))) -(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)))) +(compat-defun add-display-text-property (start end spec value &optional object) ;; <compat-tests:add-display-text-property> + "Add the display specification (SPEC VALUE) to the text from START to END. +If any text in the region has a non-nil `display' property, the existing +display specifications are retained. + +OBJECT is either a string or a buffer to add the specification to. +If omitted, OBJECT defaults to the current buffer." + (declare-function add-remove--display-text-property "compat-31") + (add-remove--display-text-property start end spec value object)) (compat-defmacro while-let (spec &rest body) ;; <compat-tests:while-let> "Bind variables according to SPEC and conditionally evaluate BODY. |
