!7 sS snippetID = #1008122; sS editorCommand = "idea"; //"jedit"; static File tempFile; p { if (nempty(args)) snippetID = fsI(args[0]); tempFile = getProgramFile(parseSnippetID(snippetID) + ".javax"); S text = loadSnippet(snippetID); saveTextFile(tempFile, text); long lastMod = tempFile.lastModified(); nohup(editorCommand + " " + platformQuote(tempFile)); print("Launched editor. Watching file for changes..."); repeat with ms sleep 100 { long mod = tempFile.lastModified(); if (mod != lastMod) loading { long newMod = mod; int mods = 0; do { sleep(100); newMod = tempFile.lastModified(); ++mods; } while (newMod != mod); if (mods > 1) warn("Editor doesn't save atomically. Mod count: " + mods); JWindow box = infoBox("Uploading..."); S newText = loadTextFile(tempFile); try { lastMod = newMod; if (neq(text, newText)) { print("EDITING " + snippetID + " (" + l(text) + " -> " + l(newText) + " chars)"); text = newText; editSnippet(snippetID, text); infoBox("UPLOADED " + snippetWithTitle(snippetID)); } } catch e { infoBox(e); } finally { text = newText; disposeWindow(box); } } } }