2

I tried exporting several org files to HTML without success. That came as a surprise, since I've done that tons of times. The message I was getting on the minibuffer shed some light.

End of file while parsing JSON

After some debugging (a combination of running emacs -q and binary search on my config file) I concluded that the reason boils down to the following line on my config file.

(add-hook 'js-mode-hook 'json-pretty-print-buffer-ordered)

I was able to solve my problem, yes, but I do not get what's going on.

Why is a js hook connected with exporting an org file to html?

How to reproduce the problem:

run emacs -q

run (add-hook 'js-mode-hook 'json-pretty-print-buffer-ordered)

M-x org-html-export-to-html

Tyler
  • 21,719
  • 1
  • 52
  • 92
aadcg
  • 1,203
  • 6
  • 13
  • The question seems incomplete. How can we guess what parsing error occurred? How can we guess the connection, if any, between that error and your attempt to export org to HTML? – Drew May 13 '19 at 18:18
  • This looks as if you're trying to post the question and answer it immediately. Normally, you have an option to answer the question as you're posting it. Is this what you were going for? Your question is quite vague. –  May 13 '19 at 19:26
  • I have made several tests (running emacs -q etc) and concluded that I was able to export org files to html if I commented out that pretty print hook on my config file. That makes no sense to me. It does solve my problem, but I don't get what's going on. Doesn't that quality it as a question? How could I be more precise and give more details? Thanks. – aadcg May 13 '19 at 21:11
  • I'm trying to figure out if this is a bug with the help of people who are more knowledgeable than me. Please try it yourselves. Run emacs -q, run the hook and try to export... – aadcg May 13 '19 at 21:26
  • 1
    I can reproduce the problem from `emacs -Q` when trying to export an empty org file. I think this is likely a bug. – Tyler May 13 '19 at 21:37
  • 2
    I changed my mind, I think your configuration is incorrect. `json-pretty-print-buffer-ordered` assumes your file contains a complete, correct `json` object. That's not always the case for a javascript file, and when it's not, the the function will fail. So the solution is probably to remove the hook, and find another way to call the function only when it is actually useful. – Tyler May 13 '19 at 21:51
  • But if I'm not in js-mode, the function shouldn't be called... right? Sorry, I'm confused with your explanation. Maybe you could post it as an answer. Thanks. – aadcg May 14 '19 at 12:12

1 Answers1

1

Your configuration,

(add-hook 'js-mode-hook 'json-pretty-print-buffer-ordered)

means the function json-pretty-print-buffer-ordered will run anytime js-mode is started. This is probably not what you intend, as json-pretty-print-buffer-ordered will fail when the buffer it is called from doesn't contain a complete, correct JSON object. That's not necessarily true for any particular javascript file. A better approach would be to remove this particular hook, and find a different way to call the function when it's actually useful.

However, as you point out this problem comes up when you're in orgmode, not js-mode. I can't fully explain this. It appears that the html exporter that org uses invokes js-mode at some point in the process. Whether or not it should do that, and if it might be a bug, I can't say.

Tyler
  • 21,719
  • 1
  • 52
  • 92