[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/devdocs 544051311c 4/4: Use libjansson JSON parser if a
From: |
ELPA Syncer |
Subject: |
[elpa] externals/devdocs 544051311c 4/4: Use libjansson JSON parser if available |
Date: |
Mon, 27 Nov 2023 12:57:59 -0500 (EST) |
branch: externals/devdocs
commit 544051311c53e72444faf130086b39ae9bf68b71
Author: Augusto Stoffel <arstoffel@gmail.com>
Commit: Augusto Stoffel <arstoffel@gmail.com>
Use libjansson JSON parser if available
---
devdocs.el | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/devdocs.el b/devdocs.el
index c18bb1287b..9520e4ca3f 100644
--- a/devdocs.el
+++ b/devdocs.el
@@ -130,6 +130,12 @@ its return value; take the necessary precautions."
;;; Documentation management
+(defalias 'devdocs--json-parse-buffer
+ (if (json-available-p)
+ (lambda () (json-parse-buffer :object-type 'alist))
+ (require 'json)
+ #'json-read))
+
(defun devdocs--doc-metadata (slug)
"Return the metadata of an installed document named SLUG."
(let ((file (expand-file-name (concat slug "/metadata") devdocs-data-dir)))
@@ -157,7 +163,7 @@ If necessary, download data from `devdocs-site-url'."
(with-temp-buffer
(url-insert-file-contents
(format "%s/docs.json" devdocs-site-url))
- (json-read))))
+ (devdocs--json-parse-buffer))))
(defun devdocs--doc-title (doc)
"Title of document DOC.
@@ -215,16 +221,15 @@ already installed, reinstall it."
(with-temp-buffer
(url-insert-file-contents (format "%s/%s/db.json?%s" devdocs-cdn-url
slug mtime))
(dolist-with-progress-reporter
- (entry (let ((json-key-type 'string))
- (json-read)))
+ (entry (devdocs--json-parse-buffer))
"Installing documentation..."
(with-temp-file (expand-file-name
(url-hexify-string (format "%s.html" (car entry)))
temp)
- (push (car entry) pages)
+ (push (symbol-name (car entry)) pages)
(insert (cdr entry)))))
(with-temp-buffer
(url-insert-file-contents (format "%s/%s/index.json?%s" devdocs-cdn-url
slug mtime))
- (let ((index (json-read)))
+ (let ((index (devdocs--json-parse-buffer)))
(push `(pages . ,(vconcat (nreverse pages))) index)
(with-temp-file (expand-file-name "index" temp)
(prin1 index (current-buffer)))))