Skip to content

Use built-in json-pretty-print instead of defunct json-reformat package #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions json-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: Josh Johnston
;; URL: https://github.com/joshwnj/json-mode
;; Version: 1.6.0
;; Package-Requires: ((json-reformat "0.0.5") (json-snatcher "1.0.0"))
;; Package-Requires: ((json-snatcher "1.0.0") (emacs "24.4"))

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand All @@ -29,7 +29,6 @@
(require 'js)
(require 'rx)
(require 'json-snatcher)
(require 'json-reformat)

(defgroup json-mode '()
"Major mode for editing JSON files."
Expand Down Expand Up @@ -140,14 +139,13 @@ This function calls `json-mode--update-auto-mode' to change the
(define-key json-mode-map (kbd "C-c P") 'json-mode-kill-path)

;;;###autoload
(defun json-mode-beautify ()
(defun json-mode-beautify (begin end)
"Beautify / pretty-print the active region (or the entire buffer if no active region)."
(interactive)
(let ((json-reformat:indent-width js-indent-level)
(json-reformat:pretty-string? t))
(if (use-region-p)
(json-reformat-region (region-beginning) (region-end))
(json-reformat-region (buffer-end -1) (buffer-end 1)))))
(interactive "r")
(unless (use-region-p)
(setq begin (point-min)
end (point-max)))
(json-pretty-print begin end))

(define-key json-mode-map (kbd "C-c C-f") 'json-mode-beautify)

Expand Down