[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat 9083cfc4f6 05/84: Add get-display-property
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat 9083cfc4f6 05/84: Add get-display-property |
Date: |
Tue, 3 Jan 2023 08:57:30 -0500 (EST) |
branch: externals/compat
commit 9083cfc4f65eea86b91cba9298fd3138f768ada1
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Add get-display-property
---
compat-29.1.el | 29 +++++++++++++++++++++++++++
compat-tests.el | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 90 insertions(+)
diff --git a/compat-29.1.el b/compat-29.1.el
index 507219b27b..3ff48f4f3c 100644
--- a/compat-29.1.el
+++ b/compat-29.1.el
@@ -30,6 +30,35 @@
(eval-when-compile (require 'compat-macs))
(declare-function compat-maxargs-/= "compat" (func n))
+;;;; Defined in xdisp.c
+
+(compat-defun get-display-property (position prop &optional object properties)
+ "Get the value of the `display' property PROP at POSITION.
+If OBJECT, this should be a buffer or string where the property is
+fetched from. If omitted, OBJECT defaults to the current buffer.
+
+If PROPERTIES, look for value of PROP in PROPERTIES instead of
+the properties at POSITION."
+ (if properties
+ (unless (listp properties)
+ (signal 'wrong-type-argument (list 'listp properties)))
+ (setq properties (get-text-property position 'display object)))
+ (cond
+ ((vectorp properties)
+ (catch 'found
+ (dotimes (i (length properties))
+ (let ((ent (aref properties i)))
+ (when (eq (car ent) prop)
+ (throw 'found (cadr ent )))))))
+ ((consp (car properties))
+ (condition-case nil
+ (cadr (assq prop properties))
+ ;; Silently handle improper lists:
+ (wrong-type-argument nil)))
+ ((and (consp (cdr properties))
+ (eq (car properties) prop))
+ (cadr properties))))
+
;;;; Defined in subr.el
(compat-defun function-alias-p (func &optional noerror)
diff --git a/compat-tests.el b/compat-tests.el
index 20dd733aad..ac2c5e411e 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -1383,5 +1383,66 @@ the compatibility function."
(compat--error cyclic-function-indirection a)
(compat--should (list b) a t))))
+(ert-deftest compat-get-display-property ()
+ "Check if `compat--function-alias-p' was implemented properly."
+ ;; Based on tests from xdisp-test.el
+ (with-temp-buffer
+ (insert (propertize "foo" 'face 'bold 'display '(height 2.0))
+ " bar")
+ (compat-test get-display-property
+ (compat--should 2.0 1 'height)
+ (compat--should 2.0 2 'height)
+ (compat--should nil 2 'width)
+ (compat--should nil 5 'height)
+ (compat--should nil 5 'height)
+ (compat--should nil 2 'bold)
+ (compat--should nil 5 'bold)))
+ (let ((str (concat
+ (propertize "foo" 'face 'bold 'display '(height 2.0))
+ " bar")))
+ (compat-test get-display-property
+ (compat--should 2.0 1 'height str)
+ (compat--should 2.0 2 'height str)
+ (compat--should nil 2 'width str)
+ (compat--should nil 5 'height str)
+ (compat--should nil 5 'height str)
+ (compat--should nil 2 'bold str)
+ (compat--should nil 5 'bold str)))
+ (with-temp-buffer
+ (insert (propertize "foo" 'face 'bold 'display '((height 2.0)
+ (space-width 4.0)))
+ " bar")
+ (compat-test get-display-property
+ (compat--should 2.0 1 'height)
+ (compat--should 2.0 2 'height)
+ (compat--should nil 5 'height)
+ (compat--should 4.0 1 'space-width)
+ (compat--should 4.0 2 'space-width)
+ (compat--should nil 5 'space-width)
+ (compat--should nil 2 'width)
+ (compat--should nil 5 'width)
+ (compat--should nil 2 'bold)
+ (compat--should nil 5 'bold)))
+ (with-temp-buffer
+ (insert (propertize "foo bar" 'face 'bold
+ 'display '[(height 2.0)
+ (space-width 20)])
+ " baz")
+ (compat-test get-display-property
+ (compat--should 2.0 1 'height)
+ (compat--should 2.0 2 'height)
+ (compat--should 2.0 5 'height)
+ (compat--should nil 8 'height)
+ (compat--should 20 1 'space-width)
+ (compat--should 20 2 'space-width)
+ (compat--should 20 5 'space-width)
+ (compat--should nil 8 'space-width)
+ (compat--should nil 2 'width)
+ (compat--should nil 5 'width)
+ (compat--should nil 8 'width)
+ (compat--should nil 2 'bold)
+ (compat--should nil 5 'bold)
+ (compat--should nil 8 'width))))
+
(provide 'compat-tests)
;;; compat-tests.el ends here
- [elpa] externals/compat 5a1f3bdc59 03/84: Merge branch 'master' into emacs-29.1, (continued)
- [elpa] externals/compat 5a1f3bdc59 03/84: Merge branch 'master' into emacs-29.1, ELPA Syncer, 2023/01/03
- [elpa] externals/compat ae2bf0aee5 08/84: Merge branch 'master' into emacs-29.1, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 5031a586a3 09/84: Add take and ntake defined in Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 71ddb93f75 10/84: Merge branch 'master' into emacs-29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 3104c89c2d 13/84: Test compat-string-trim instead of string-trim, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 29dd29609a 15/84: Prepare compat.el for testing functions from compat-29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 9b8799091c 16/84: Add @subsection headers for Emacs 29.1 node, ELPA Syncer, 2023/01/03
- [elpa] externals/compat db53afa3a7 18/84: Add buffer-text-pixel-size from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat a4036f9b1b 01/84: Prepare Emacs 29.1 compatibility, ELPA Syncer, 2023/01/03
- [elpa] externals/compat f21b114ec7 02/84: Add string-limit, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 9083cfc4f6 05/84: Add get-display-property,
ELPA Syncer <=
- [elpa] externals/compat 87da1d984d 11/84: Begin documenting Emacs 29 support, ELPA Syncer, 2023/01/03
- [elpa] externals/compat c81333a6b0 30/84: Merge branch 'master' into emacs-29.1, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 2ee63f46b2 07/84: Make compat-font-lock dependency on compat-macs explicit, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 22b2634ada 06/84: Compile compat-macs before anything else, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 2e206a8304 21/84: Add prefixed plist-get from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat e13ca90cd7 12/84: Rewrite legacy compat-test definitions, ELPA Syncer, 2023/01/03
- [elpa] externals/compat e370f9b7e7 25/84: Add match-buffers from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 4710da5fa7 28/84: Add file-parent-directory from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat bb86f3aa3b 37/84: Simplify compat--generate-testable, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 282f2dc6a7 41/84: Call install-fn in compat--generate-testable, ELPA Syncer, 2023/01/03