Tagged: ,

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #20769

    LifeTimer
    Participant

    The brand new EmEditor 15.9 regexp features are very welcome and extremely helpful for making the macro engine lots more powerful!

    One more such feature set that is nowadays commonplace and much used in modern “normal Javascript” (in browsers etc) is JSON support. Contrary to what might be the initial reaction, JSON support is extremely well-suited to macros in a text editor like EmEditor, since it very efficiently bridges the gap between textual data and internal-typed data possible to process efficiently with Javascript.

    According to this previous thread (https://www.emeditor.com/forums/topic/does-javascript-macros-in-emeditor-only-support-a-subset-of-javascript-standard/), EmEditor does not currently expose the JSON features of modern Javascript versions, but according to this information (https://blogs.msdn.microsoft.com/jscript/2009/04/16/versioning-language-features-in-jscript/) from Microsoft, maybe this would be quite easy to do after all, without even having to use any non-Javascript library for it (which there absolutely exists good ones for too by the way, just like the ones you used for the regular expressions support!)?

    Either way, the two core functions of the Javascript JSON capabilities that would be extremely useful to have in EmEditor macros are the JSON.parse() and JSON.stringify() methods, which, respectively, imports textual-only data to internal-type Javascript data, and exports it back to textual form once ready-processed.

    I really hope that you would consider adding support for these JSON methods in the EmEditor macro engine, just like you just added regexp support in 15.9!

    If the recently added regexp support in EmEditor 15.9 just doubled the usefulness of EmEditor macros, adding JSON support would (at least) double it again, I’d say!

    #20777

    LifeTimer
    Participant

    I just noticed that you had replied recently in the referenced thread above, about ongoing attempts to activate the full JScript 5.8 feature-set in the EmEditor macro engine (according to the details in my other MSDN link here above), and I’m now awaiting a reply about the status of this work in that thread. Sorry for the confusion!

    #20778

    Yutaka Emura
    Keymaster

    Hello,

    Actually, the JSON object is already defined on EmEditor v15.9.0.

    Can you try on your computer, and see if there any issues?

    Thanks!

    #20781

    LifeTimer
    Participant

    I’ve tried it now and it works great!

    Here is the full source code of my new JSON beautifier macro:

    document.selection.Text = JSON.stringify(JSON.parse(document.selection.Text), null, '\t');

    🙂

    By the way, you should really mention the new JSON / Javascript 5.8 support in the releasenotes for EmEditor 15.9 I think (if I’m not blind and you already did?), since it’s a very big deal I think!

    Thanks a lot!

    PS.
    The email notifications from your forums started working for me again yesterday, did you do something about them, or did they just fix themselves in a very well-timed fashion?

    #20787

    Yutaka Emura
    Keymaster

    I added information about JSON to the History page of the Help, the latest feature page of the website, and I posted a new blog about the feature.

    As for email notifications, I didn’t change anything, but we constantly update WordPress, so it is possible that there might have been glitches in some version of WordPress.

    Thanks!

    #20993

    Scott Beeson
    Participant

    document.selection.Text = JSON.stringify(JSON.parse(document.selection.Text), null, ‘\t’);

    I tried this macro and it just says “Syntax Error”. Are there prerequisites I’m missing?

    #20994

    Scott Beeson
    Participant

    Nevermind, I wasn’t thinking…

    I added document.selection.SelectAll(); before your code and now it does what I was expecting (I’m using this for entire documents).

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.