-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
json: tell prettier content is to be parsed as json #11364
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now I don't see any usage of the new functions. But anyway, I think these functions should be defined only when prettier
layer is enabled. Or maybe, they should be part of prettier
layer. WDYT?
layers/+lang/json/packages.el
Outdated
@@ -32,6 +32,9 @@ | |||
(use-package json-mode | |||
:defer t)) | |||
|
|||
(defun json/post-init-json-mode () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How this function is being called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it the same layer calling conventions magic that calls the {layer}/pre-init-{pkg}
and {layer}/init-{pkg}
packages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tko you're right. Sorry, I was confused. Then why this add-hook
call is not inside of json/init-json-mode
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this should be the other way around. This is the post-init-prettier
that setup the hook. Indeed json-init
does not know anything about prettier
being used or not but post-init-prettier
knows it implicitly as it is called only if prettier
is used (i.e. the prettier
layer is used).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly 😸 Just like web-beautify
is configured in the json
layer.
I see the options being
for prettier the latter would be more convenient sure, but then it'd be leaking into major modes/layers and seems like major mode layer is meant to own everything about major mode. Haven't thought about too much, just went this way as that's the way it was already being setup. I left the hook function always implemented and check for the |
@tko what you say makes sense to me. Let's leave these configurations in Also, I've just took a closer look at this layer and noticed that there are other handlers for (defun json/pre-init-web-beautify ()
(if (eq json-fmt-tool 'web-beautify)
(add-to-list 'spacemacs--web-beautify-modes
(cons 'json-mode 'web-beautify-js)))) To be honest, I like this approach a little bit more as it clearly/explicitly defines the dependencies. On the other hand, I like that your approach allows one to switch BTW, there are already configurations for |
In json-mode tell prettier the content is always to be parsed as json. Fixes formatting in orgmode `#+BEGIN_SRC json` blocks as prettier otherwise expects content as javascript. Fixes: syl20bnr#11343
Updated to do things in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you for updating this PR.
Thank you 👍 Cherry-picked into Resulting commit is 895308a. |
In json-mode tell prettier the content is always to be parsed as json.
Fixes formatting in orgmode
#+BEGIN_SRC json
blocks as prettierotherwise expects content as javascript.
Fixes: #11343