[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat db218d0 79/99: Handle top-level JSON objects in
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat db218d0 79/99: Handle top-level JSON objects in Emacs 27.x |
Date: |
Sun, 17 Oct 2021 05:58:01 -0400 (EDT) |
branch: externals/compat
commit db218d00bf6b682eecca8a88ee47d61a910a7320
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Handle top-level JSON objects in Emacs 27.x
---
compat-28.1.el | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
compat-tests.el | 10 +++++++--
2 files changed, 77 insertions(+), 2 deletions(-)
diff --git a/compat-28.1.el b/compat-28.1.el
index d9b8534..38d31fa 100644
--- a/compat-28.1.el
+++ b/compat-28.1.el
@@ -150,6 +150,75 @@ If COUNT is non-nil and a natural number, the function will
(setf (nthcdr count files) nil))
files))
+;;;; Defined in json.c
+
+(compat-advise json-serialize (object &rest args)
+ "Handle top-level JSON values."
+ :cond (condition-case err
+ ;; Use `random' to prevent byte compiler from optimising
+ ;; the "pure" `json-serialize' call.
+ (ignore (json-serialize (if (random) 0 0)))
+ (wrong-type-argument (eq (cadr err) 'json-value-p)))
+ :realname compat--json-serialize-handle-tlo
+ :min-version "27"
+ (if (or (listp object) (vectorp object))
+ (apply oldfun object args)
+ (substring (json-serialize (list object)) 1 -1)))
+
+(compat-advise json-insert (object &rest args)
+ "Handle top-level JSON values."
+ :cond (condition-case err
+ ;; Use `random' to prevent byte compiler from optimising
+ ;; the "pure" `json-serialize' call.
+ (ignore (json-serialize (if (random) 0 0)))
+ (wrong-type-argument (eq (cadr err) 'json-value-p)))
+ :realname compat--json-insert-handle-tlo
+ :min-version "27"
+ (if (or (listp object) (vectorp object))
+ (apply oldfun object args)
+ (insert (apply #'compat--json-serialize-handle-tlo oldfun object args))))
+
+(compat-advise json-parse-string (string &rest args)
+ "Handle top-level JSON values."
+ :cond (condition-case nil
+ ;; Use `random' to prevent byte compiler from optimising
+ ;; the "pure" `json-serialize' call.
+ (ignore (json-parse-string (if (random) "0" "0")))
+ (json-parse-error t))
+ :realname compat--json-parse-string-handle-tlo
+ :min-version "27"
+ (if (string-match-p "\\`[[:space:]]*[[{]" string)
+ (apply oldfun string args)
+ ;; Wrap the string in an array, and extract the value back using
+ ;; `elt', to ensure that no matter what the value of `:array-type'
+ ;; is we can access the first element.
+ (elt (apply oldfun (concat "[" string "]") args) 0)))
+
+(compat-advise json-parse-buffer (&rest args)
+ "Handle top-level JSON values."
+ :cond (condition-case nil
+ ;; Use `random' to prevent byte compiler from optimising
+ ;; the "pure" `json-serialize' call.
+ (ignore (json-parse-string (if (random) "0" "0")))
+ (json-parse-error t))
+ :realname compat--json-parse-buffer-handle-tlo
+ :min-version "27"
+ (if (looking-at-p "[[:space:]]*[[{]")
+ (apply oldfun args)
+ (catch 'escape
+ (atomic-change-group
+ (with-syntax-table
+ (let ((st (make-syntax-table)))
+ (modify-syntax-entry ?\" "\"" st)
+ (modify-syntax-entry ?. "_" st)
+ st)
+ (let ((inhibit-read-only t))
+ (save-excursion
+ (insert "[")
+ (forward-sexp 1)
+ (insert "]"))))
+ (throw 'escape (elt (apply oldfun args) 0))))))
+
;;;; Defined in subr.el
(compat-defun string-replace (fromstring tostring instring)
diff --git a/compat-tests.el b/compat-tests.el
index a42c5cf..f8c0591 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -138,7 +138,10 @@ the compatibility function."
(car fn)
;; Handle expressions
(eval (car fn) t))
- compat--compat-fn (cadr fn))
+ compat--compat-fn (if (symbolp (cadr fn))
+ (cadr fn)
+ ;; Handle expressions
+ (eval (cadr fn) t)))
(setq compat--current-fn fn
compat--compat-fn nil))
(macroexp-progn body))
@@ -1265,7 +1268,10 @@ the compatibility function."
(ert-deftest compat-json-parse-string ()
"Check if `compat--json-parse-string' was implemented properly."
- (compat-test json-parse-string
+ (compat-test (json-parse-string (if (version<= "28" emacs-version)
+ (apply-partially
#'compat--json-parse-string-handle-tlo
+ #'json-parse-string)
+ #'compat--json-parse-string))
(compat--should 0 "0")
(compat--should 1 "1")
(compat--should 0.5 "0.5")
- [elpa] externals/compat c37e1d1 80/99: Fix quoting in compat-macs' legacy advice installation, (continued)
- [elpa] externals/compat c37e1d1 80/99: Fix quoting in compat-macs' legacy advice installation, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 18c2bf9 83/99: Autoload advised functions is necessary, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 50767a8 90/99: Load deferred code even if file doesn't exist, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 2bb6c10 91/99: Check if function is bound before extracting documentation, ELPA Syncer, 2021/10/17
- [elpa] externals/compat f4c0979 92/99: Prevent shadowing declarations in functional compatibility code, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 3257cf6 93/99: Implement TCO for named-let, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 347f5a8 94/99: Change version suffix to -rc, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 25879c7 95/99: Require instead of loading compat-*.el files, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 5506770 99/99: Update .elpaignore, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 084f18c 73/99: Declare compat functions used in file-name-with-extension, ELPA Syncer, 2021/10/17
- [elpa] externals/compat db218d0 79/99: Handle top-level JSON objects in Emacs 27.x,
ELPA Syncer <=
- [elpa] externals/compat 8981d4b 85/99: Handle multiple signals in string-replace test case, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 8ea6272 86/99: Add define-error compatibility function, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 5d5b215 87/99: Factor out issue with should-error in Emacs 24.3, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 93cee71 88/99: Generate a docstring for manual compatibility advice, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 0a72e60 97/99: Fix the number of expected argument in count-windows :cond check, ELPA Syncer, 2021/10/17