emacs-diffs
[Top][All Lists]
Advanced

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

master e4f323a: Add json-available-p


From: Lars Ingebrigtsen
Subject: master e4f323a: Add json-available-p
Date: Wed, 21 Jul 2021 06:49:30 -0400 (EDT)

branch: master
commit e4f323a82a6f92af391831b83e2ebd2b91250837
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add json-available-p
    
    * doc/lispref/text.texi (Parsing JSON): Document it.
    * lisp/subr.el (json-available-p): New function (bug#49660).
---
 doc/lispref/text.texi |  9 +++++++++
 etc/NEWS              | 35 +++++++++++++++++++++--------------
 lisp/subr.el          |  8 ++++++++
 3 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index 6fbb475..a3b537a 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -5301,11 +5301,20 @@ represents @code{@{@}}, the empty JSON object; not 
@code{null},
 @code{false}, or an empty array, all of which are different JSON
 values.
 
+@defun json-available-p
+This predicate returns non-@code{nil} is Emacs has been built with
+@acronym{JSON} support, and the library is available on the current
+system.
+@end defun
+
   If some Lisp object can't be represented in JSON, the serialization
 functions will signal an error of type @code{wrong-type-argument}.
 The parsing functions can also signal the following errors:
 
 @table @code
+@item json-unavailable
+Signaled when the parsing library isn't available.
+
 @item json-end-of-file
 Signaled when encountering a premature end of the input text.
 
diff --git a/etc/NEWS b/etc/NEWS
index 49396c3..b1db3b7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2024,6 +2024,27 @@ used instead.  Uses of 'json-encode-list' should be 
changed to call
 one of 'json-encode', 'json-encode-alist', 'json-encode-plist', or
 'json-encode-array' instead.
 
+** json.c
+
++++
+*** New function 'json-available-p'.
+This predicate returns non-nil if Emacs is built with libjansson
+support, and it is available on the current system.
+
++++
+*** Native JSON functions now signal an error if libjansson is unavailable.
+This affects 'json-serialize', 'json-insert', 'json-parse-srtring',
+and 'json-parse-buffer'.  This can happen if Emacs was compiled with
+libjansson, but the DLL cannot be found and/or loaded by Emacs at run
+time.  Previously, Emacs would display a message and return nil in
+these cases.
+
+*** The JSON functions 'json-serialize', 'json-insert',
+'json-parse-string', and 'json-parse-buffer' now implement some of the
+semantics of RFC 8259 instead of the earlier RFC 4627.  In particular,
+these functions now accept top-level JSON values that are neither
+arrays nor objects.
+
 ** xml.el
 
 *** XML serialization functions now reject invalid characters.
@@ -3473,12 +3494,6 @@ locales.  They are also available as aliases 
'ebcdic-cp-*' (e.g.,
 'cp278' for 'ibm278').  There are also new charsets 'ibm2xx' to
 support these coding-systems.
 
-** The JSON functions 'json-serialize', 'json-insert',
-'json-parse-string', and 'json-parse-buffer' now implement some of the
-semantics of RFC 8259 instead of the earlier RFC 4627.  In particular,
-these functions now accept top-level JSON values that are neither
-arrays nor objects.
-
 ---
 ** 'while-no-input-ignore-events' accepts more special events.
 The special events 'dbus-event' and 'file-notify' are now ignored in
@@ -3539,14 +3554,6 @@ non-nil value.  Please report any bugs you find while 
using the native
 image API via 'M-x report-emacs-bug'.
 
 ---
-** Native JSON functions now signal an error if libjansson is unavailable.
-This affects 'json-serialize', 'json-insert', 'json-parse-srtring',
-and 'json-parse-buffer'.  This can happen if Emacs was compiled with
-libjansson, but the DLL cannot be found and/or loaded by Emacs at run
-time.  Previously, Emacs would display a message and return nil in
-these cases.
-
----
 ** The user option 'make-pointer-invisible' is now honored on macOS.
 
 --
diff --git a/lisp/subr.el b/lisp/subr.el
index c7e1864..3d66928 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -6311,4 +6311,12 @@ of fill.el (for example `fill-region')."
 This is intended for internal use only."
   (internal--fill-string-single-line (apply #'format string objects)))
 
+(defun json-available-p ()
+  "Return non-nil if Emacs is has libjansson support."
+  (and (fboundp 'json-serialize)
+       (condition-case nil
+           (json-serialize t)
+         (:success t)
+         (json-unavailable nil))))
+
 ;;; subr.el ends here



reply via email to

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