有人知道编辑 JSON 的良好 Emacs 模式吗?我正在开发的一个应用程序使用基于 JSON 的通信协议(protocol),并且将数据很好地缩进和语法高亮将在我弄清楚它的过程中帮助我很多。
最佳答案
+1 乔希的 json-mode ——对我来说效果很好。我加了
(defun beautify-json ()
(interactive)
(let ((b (if mark-active (min (point) (mark)) (point-min)))
(e (if mark-active (max (point) (mark)) (point-max))))
(shell-command-on-region b e
"python -m json.tool" (current-buffer) t)))
和
(define-key json-mode-map (kbd "C-c C-f") 'beautify-json)
到 json-mode.el 以使 shell 命令调用更容易。
更新:对于那些需要/希望使用 unicode 执行此操作的人,请参阅我的问题 here .结果是而不是使用:
python -m json.tool
你会想要使用
python -c 'import sys,json; data=json.loads(sys.stdin.read()); print json.dumps(data,sort_keys=True,indent=4).decode("unicode_escape").encode("utf8","replace")'
这既美化了 JSON,又保留了原始的 Unicode 内容。
关于json - Emacs 模式编辑 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/435847/