External Editor . . . on and on

Richard Gaskin ambassador at fourthworld.com
Tue Oct 22 15:58:02 EDT 2013


Looking at the most recent build of the MC IDE (v4.1), in the stack 
"Script Editor" there's an item named "Run External Editor..." in the 
Tools menu.

That menu button's script includes:

    on menuPick which
    ...
      case "Run External Editor..."
        if the selectedLine is empty
        then runexternal 0
        else runexternal word 2 of the selectedLine
        break


So looking in the card script I find:

    on runexternal whichline
      local ename, fname, dummy
      put mcGetPref("external editor") into ename
      put tempname() into fname
      open file fname for write
      write field "Editor Field" & cr to file fname
      close file fname
      put "See External Editor..." into field "Editor Field"
      set the cursor to watch
      if whichline is empty then put 1 into whichline
      put shell(ename && "+" & whichline && fname) into dummy
      open file fname for read
      read from file fname until eof
      if the last char of it is cr then delete last char of it
      put it into field "Editor Field"
      close file fname
      delete file fname
      select after line whichline of field "Editor Field"
      put setscript(true) into fname
    end runexternal


If I were implementing this today I'd do it differently:

1. Write the script to tmp
2. Launch editor with script as document
3. Poll for changes
4. set the script of the object to the contents of the changed file

There are probably many other ways to do it, but back when I was using 
MC I just made my own editor, and now with LC I find it's not bad so I 
just use it.

--
  Richard Gaskin
  Fourth World
  LiveCode training and consulting: http://www.fourthworld.com
  Webzine for LiveCode developers: http://www.LiveCodeJournal.com
  Follow me on Twitter:  http://twitter.com/FourthWorldSys




More information about the Use-livecode mailing list