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

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

[elpa] externals/compat 43041cba01: compat-29: Add compiled-function-p


From: ELPA Syncer
Subject: [elpa] externals/compat 43041cba01: compat-29: Add compiled-function-p
Date: Tue, 17 Jan 2023 14:57:26 -0500 (EST)

branch: externals/compat
commit 43041cba01617164750b5bbdd343b3c8ce1b2008
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    compat-29: Add compiled-function-p
---
 NEWS.org        |  1 +
 compat-29.el    |  6 ++++++
 compat-tests.el |  5 +++++
 compat.texi     | 11 +++++++++++
 4 files changed, 23 insertions(+)

diff --git a/NEWS.org b/NEWS.org
index 055ff211a9..bc43a7dece 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 27edaaa0b2..bae8f07fca 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 e315e2ca90..4f758870b8 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 1280fe6d8a..54718518e1 100644
--- a/compat.texi
+++ b/compat.texi
@@ -2120,6 +2120,17 @@ not just rely on the truncation effect unless @var{n} is 
known to be
 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



reply via email to

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