Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

tko
Copy link
Contributor

@tko tko commented Sep 23, 2018

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: #11343

Copy link
Collaborator

@d12frosted d12frosted left a 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?

@@ -32,6 +32,9 @@
(use-package json-mode
:defer t))

(defun json/post-init-json-mode ()
Copy link
Collaborator

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?

Copy link
Contributor Author

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?

Copy link
Collaborator

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?

Copy link
Owner

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).

Copy link
Collaborator

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.

@tko
Copy link
Contributor Author

tko commented Oct 9, 2018

I see the options being

  1. each major mode layer knows about prettier
  2. prettier layer knows about each major mode / layer

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 json-fmt-tool there so the variable can be change on runtime and change the behavior dynamically without requiring restart. No strong feelings though.

@d12frosted
Copy link
Collaborator

@tko what you say makes sense to me. Let's leave these configurations in json layer.

Also, I've just took a closer look at this layer and noticed that there are other handlers for json-fmt-tool. But they are implemented differently. For example,

(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 json-fmt-tool on the fly 😸

BTW, there are already configurations for prettier. Should not you just move your add-hook call to json/pre-init-prettier-js?

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
@tko
Copy link
Contributor Author

tko commented Nov 4, 2018

Updated to do things in pre-init-prettier-js within the scope of the existing conditional. The finer points between using package :toggles, pre-init (like web-beautify) or post-init (like add-node-modules-path) escape me.

Copy link
Collaborator

@d12frosted d12frosted left a 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.

@d12frosted
Copy link
Collaborator

Thank you 👍 Cherry-picked into develop, you can safely delete your branch.

Resulting commit is 895308a.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants