[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat dd334e5616 04/84: Add function-alias-p
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat dd334e5616 04/84: Add function-alias-p |
Date: |
Tue, 3 Jan 2023 08:57:30 -0500 (EST) |
branch: externals/compat
commit dd334e5616d794f9c761402fa77686d342ef790f
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Add function-alias-p
---
compat-29.1.el | 26 +++++++++++++++++++++++++-
compat-tests.el | 21 +++++++++++++++++++++
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/compat-29.1.el b/compat-29.1.el
index 3564270d81..507219b27b 100644
--- a/compat-29.1.el
+++ b/compat-29.1.el
@@ -30,6 +30,30 @@
(eval-when-compile (require 'compat-macs))
(declare-function compat-maxargs-/= "compat" (func n))
+;;;; Defined in subr.el
+
+(compat-defun function-alias-p (func &optional noerror)
+ "Return nil if FUNC is not a function alias.
+If FUNC is a function alias, return the function alias chain.
+
+If the function alias chain contains loops, an error will be
+signalled. If NOERROR, the non-loop parts of the chain is returned."
+ (declare (side-effect-free t))
+ (let ((chain nil)
+ (orig-func func))
+ (nreverse
+ (catch 'loop
+ (while (and (symbolp func)
+ (setq func (symbol-function func))
+ (symbolp func))
+ (when (or (memq func chain)
+ (eq func orig-func))
+ (if noerror
+ (throw 'loop chain)
+ (signal 'cyclic-function-indirection (list orig-func))))
+ (push func chain))
+ chain))))
+
;;;; Defined in subr-x.el
(compat-defun string-limit (string length &optional end coding-system)
@@ -51,7 +75,7 @@ character.
When shortening strings for display purposes,
`truncate-string-to-width' is almost always a better alternative
than this function."
- :feature subr-x
+ :feature 'subr-x
(unless (natnump length)
(signal 'wrong-type-argument (list 'natnump length)))
(if coding-system
diff --git a/compat-tests.el b/compat-tests.el
index 4a4ab25a27..20dd733aad 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -1361,6 +1361,27 @@ the compatibility function."
(compat--error wrong-type-argument 'a 2)
(compat--error wrong-type-argument 'a 'b)))
+(ert-deftest compat-function-alias-p ()
+ "Check if `compat--function-alias-p' was implemented properly."
+ (let* ((f (gensym))
+ (g (gensym)) (h (gensym))
+ (a (gensym)) (b (gensym)))
+ (defalias f #'ignore)
+ (defalias g f)
+ (defalias h g)
+ (defalias a b)
+ (defalias b a)
+
+ (compat-test function-alias-p
+ (compat--should nil nil)
+ (compat--should nil "")
+ (compat--should nil #'ignore)
+ (compat--should nil #'ignore)
+ (compat--should (list #'ignore) f)
+ (compat--should (list f #'ignore) g)
+ (compat--should (list g f #'ignore) h)
+ (compat--error cyclic-function-indirection a)
+ (compat--should (list b) a t))))
(provide 'compat-tests)
;;; compat-tests.el ends here
- [elpa] externals/compat updated (1573aa2e6d -> be4595fec8), ELPA Syncer, 2023/01/03
- [elpa] externals/compat dd334e5616 04/84: Add function-alias-p,
ELPA Syncer <=
- [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