emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 48daf77: Fix pretty-printing of multiple JSON objec


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 48daf77: Fix pretty-printing of multiple JSON objects
Date: Tue, 9 Jul 2019 14:49:46 -0400 (EDT)

branch: master
commit 48daf77a9d963c05ee198b3ab108c7f0b3686da6
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Fix pretty-printing of multiple JSON objects
    
    * lisp/json.el (json-pretty-print-max-secs): Make obsolete.
    (json-pretty-print): Pretty-print all JSON objects in the region
    instead of just the first one (and then deleting all other
    objects) (bug#34160).
---
 lisp/json.el | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/lisp/json.el b/lisp/json.el
index a36cff7..8dd96b0 100644
--- a/lisp/json.el
+++ b/lisp/json.el
@@ -758,10 +758,8 @@ With prefix argument MINIMIZE, minimize it instead."
   (json-pretty-print (point-min) (point-max) minimize))
 
 (defvar json-pretty-print-max-secs 2.0
-  "Maximum time for `json-pretty-print's comparison.
-The function `json-pretty-print' uses `replace-region-contents'
-(which see) passing the value of this variable as argument
-MAX-SECS.")
+  "Maximum time for `json-pretty-print's comparison.")
+(make-obsolete-variable json-pretty-print-max-secs nil "27.1")
 
 (defun json-pretty-print (begin end &optional minimize)
   "Pretty-print selected region.
@@ -771,14 +769,17 @@ With prefix argument MINIMIZE, minimize it instead."
         ;; Distinguish an empty objects from 'null'
         (json-null :json-null)
         ;; Ensure that ordering is maintained
-        (json-object-type 'alist))
-    (replace-region-contents
-     begin end
-     (lambda () (json-encode (json-read)))
-     json-pretty-print-max-secs
-     ;; FIXME: What's a good value here?  Can we use something better,
-     ;; e.g., by deriving a value from the size of the region?
-     64)))
+        (json-object-type 'alist)
+        json)
+    (save-restriction
+      (narrow-to-region begin end)
+      (goto-char begin)
+      (while (setq json (condition-case _
+                            (json-read)
+                          (json-error nil)))
+        (delete-region begin (point))
+        (insert (json-encode json))
+        (setq begin (point))))))
 
 (defun json-pretty-print-buffer-ordered (&optional minimize)
   "Pretty-print current buffer with object keys ordered.



reply via email to

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