aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-01-17 20:01:40 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2023-01-17 20:04:07 +0100
commit43041cba01617164750b5bbdd343b3c8ce1b2008 (patch)
tree90449786d8f2e10e4fef6e95f46c737207575cbd
parent157e5c13d558bb6d21f6ecd6e17c16453d673732 (diff)
compat-29: Add compiled-function-p
-rw-r--r--NEWS.org1
-rw-r--r--compat-29.el6
-rw-r--r--compat-tests.el5
-rw-r--r--compat.texi11
4 files changed, 23 insertions, 0 deletions
diff --git a/NEWS.org b/NEWS.org
index 055ff21..bc43a7d 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -8,6 +8,7 @@
- compat-28: Add ~color-dark-p~.
- compat-28: Add ~with-window-non-dedicated~.
- compat-29: Add ~plist-get~ generalized variable.
+- compat-29: Add ~compiled-function-p~.
* Release of "Compat" Version 29.1.2.0
diff --git a/compat-29.el b/compat-29.el
index 27edaaa..bae8f07 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -185,6 +185,12 @@ and return the value found in PLACE instead."
(compat-defalias string-split split-string) ;; <compat-tests:string-split>
+(compat-defun compiled-function-p (object) ;; <compat-tests:compiled-function-p>
+ "Return non-nil if OBJECT is a function that has been compiled.
+Does not distinguish between functions implemented in machine code
+or byte-code."
+ (or (subrp object) (byte-code-function-p object)))
+
(compat-defun function-alias-p (func &optional noerror) ;; <compat-tests:function-alias-p>
"Return nil if FUNC is not a function alias.
If FUNC is a function alias, return the function alias chain.
diff --git a/compat-tests.el b/compat-tests.el
index e315e2c..4f75887 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -1157,6 +1157,11 @@
(should-equal 'l (cddadr xxxx))
(should-equal 'h (cdddar xxxx))))
+(ert-deftest compiled-function-p ()
+ (should-not (compiled-function-p '(lambda (x) x)))
+ (should (compiled-function-p (symbol-function 'assq)))
+ (should (compiled-function-p (symbol-function 'identity))))
+
(ert-deftest subr-native-elisp-p ()
(should-not (subr-native-elisp-p (symbol-function 'identity))))
diff --git a/compat.texi b/compat.texi
index 1280fe6..5471851 100644
--- a/compat.texi
+++ b/compat.texi
@@ -2121,6 +2121,17 @@ positive.
@end defun
@c copied from lispref/functions.texi
+@defun compiled-function-p object
+This function returns @code{t} if @var{object} is a function object
+that is not in the form of ELisp source code but something like
+machine code or byte code instead. More specifically it returns
+@code{t} if the function is built-in (a.k.a.@: ``primitive'',
+@pxref{What Is a Function}), or byte-compiled (@pxref{Byte
+Compilation}), or natively-compiled (@pxref{Native Compilation}), or
+a function loaded from a dynamic module (@pxref{Dynamic Modules}).
+@end defun
+
+@c copied from lispref/functions.texi
@defun function-alias-p object &optional noerror
Checks whether @var{object} is a function alias. If it is, it returns
a list of symbols representing the function alias chain, else