conf-json.el 967 B

1234567891011121314151617181920212223242526272829303132
  1. (require 'json)
  2. ;;(defun beautify-json ()
  3. ;; (interactive)
  4. ;; (let ((b (if mark-active (min (point) (mark)) (point-min)))
  5. ;; (e (if mark-active (max (point) (mark)) (point-max))))
  6. ;; (shell-command-on-region b e
  7. ;; "python -mjson.tool" (current-buffer) t)))
  8. ;;(define-key json-mode-map (kbd "C-c C-j") 'beautify-json)
  9. (defun json-pretty-print-buffer ()
  10. (interactive)
  11. (let ((json-encoding-pretty-print t))
  12. (let ((json-string (json-encode (json-read-from-string (buffer-string))))
  13. (buf (current-buffer)))
  14. (with-current-buffer buf
  15. (erase-buffer)
  16. (insert json-string)))))
  17. (defun json-pretty-print ()
  18. (interactive)
  19. (unless mark-active
  20. (error "No region selected."))
  21. (let ((begin (region-beginning))
  22. (end (region-end)))
  23. (kill-region begin end)
  24. (let ((json-encoding-pretty-print t))
  25. (insert (json-encode (json-read-from-string (current-kill 0)))))))
  26. (provide 'conf-json)