Pretty print the buffer when opening long single line JSON file #48
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When opening long single line JSON file, ask the user if they want to pretty print the buffer. This makes opening and editing the file faster since, as you know, Emacs cannot handle long line well.
Opening 30 MiB file (made with
jq -c . test-assets/large-json-file.json
) took 4 seconds with pretty printing rather than 13 seconds without pretty printing. Our implementation is faster thanjson-pretty-print-buffer
, which took 10 seconds.Why we are faster than
json-pretty-print-buffer
:json-pretty-print-buffer
is generic while ourjsonian--pretty-print-long-line
assumes the buffer is single line.json-pretty-print-buffer
parse the buffer, pretty print it in a temporary buffer, and replace the buffer content withreplace-region-contents
. It keeps existing markers and properties intact but slow. We alternatively scan the buffer and insert line breaks and indentations. We also utilizejsonian--huge-edit
to optimizes the undo list; Emacs normally records one undo entry for each basic modifications such as inserting a line break or indenting a line. When applyingjson-pretty-print-buffer
to a large file, this floods the undo list and it will be truncated by Emacs. Even without truncation, it makes undo slower.jsonian--huge-edit
creates a few undo entries that delete whole region and replace it with a new content. It also takes care of existing markers.This is ported from my JSON Par mode.