conf-json.el 1.0 KB

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