Call an external editor


#1

I would like to open an external editor to edit string content (that would be written to temporary files).

What I need is a command to open the editor with a filename and get a notification whenever the file has been saved. The solution to this problem has to be platform specific. Starting with Mac OS, here are the three solutions that could work (preferred solutions first):

  1. kqueue with EVFILT_VNODE / NOTE_WRITE (BSD C interface)
  2. ODB Editor Suite (AppleEvents, compatible with BBEdit, TextMate, etc)
  3. file stat polling with a Timer (arrgggh)

Any advice ?


#2

I used the new “PlatformUtilities::openDocument” with File::createTempFile and then used kqueue to watch for file changes.

There was one major gotcha: most editors don’t “write” files, they “delete & create”. This means that if you watch for “NOTE_WRITE”, nothing happens and if you watch for “NOTE_DELETE”, you have to reset the notification or it will keep on triggering (a “delete & create” changes the unix file descriptor).

I post this here just in case someone needs the same kind of feature: http://github.com/rubyk/mimas/blob/master/src/utilities/osx/m_file_observer.cpp

Gaspard