I'm using spacemacs
but presumably it's emacs knowledge that's required here.
I have a JSON file with a single long line, let's say this JSON from json.org/example:
{"menu": {"id": "file", "value": "File", "popup": {"menuitem": [{"value": "New", "onclick": "CreateNewDoc()"}, {"value": "Open", "onclick": "OpenDoc()"}, {"value": "Close", "onclick": "CloseDoc()"}]}}}
I would like emacs to reindent this, which means to me not change the leftmost character of line to the proper indentation level, but break the line in several lines.
If I use spacemacs/indent-region-or-buffer
(SPC j =
) then the text is not changed at all.
How could I ask from emacs to actually break this long line and reindent to get something like this:
{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}
I'm not interested in a JSON-specific answer, for instance I believe that intelliJ does that for any language it supports (java, json...). I would think it's achievable for any language emacs has a major mode for, or let's say the most popular ones.
EDIT I discovered M-x json-reformat-region
that spacemacs
ships with and works, but yes, I would like that for any language and with always the same shortcut, based on the major mode...
EDIT2 Ok so my conclusion is that it's implemented for various languages, JSON & lisp at least, presumably others, and it would be easy for yet more (XML/XHTML, go which has go-fmt and also using clang). However there's no generic function name that would do it for all the languages. There is space here to implement it in spacemacs
layers for the various languages... I didn't find a X/HTML implementation though, which surprises me a bit.
web-beautiful.el
. This is the best I've found, but it depends on node.js.web-beautify.el