Scite Other

lua-users home
wiki

The SciteOther library is a small DLL with a Lua driver, which allows you to control another instance of SciTE. For instance, OpenOther(file) will open file in another SciTE window; if there isn't any, SciTE will be launched again. In these notes, when I speak of another 'window' I will mean another instance of SciTE (what an Emacs person would call another 'frame')

You can find the DLL (compiled and as source) with the driver at http://home.mweb.co.za/sd/sdonovan/scite_other.zip. Put the DLL in the same directory as your SciTE executable (the 'default home') and load the Lua code from your Lua startup file.

The library uses the external SciTE Director interface to send commands to SciTE. A subset of these are given in the "Command line arguments" section of the SciTE help, but there are others available - the definitive reference is SciTEBase::PerformOne (SciTEBase.cxx, 4287) A general function PerformOther(verb,arg) is supplied, so OpenOther(file) is equivalent to PerformOther('open',file).

close
cwd            change working directory 
find           search text 
goto           line number[,column number] 
open           file name 
quit  
replaceall     search text\000replacement text 
saveas         file name 

loadsession    session file
extender       Lua expression
menucommand    menu id

These export commands apply to the currently shown file:

exportashtml   output file
exportasrtf    ''
exportaspdf    ''
exportaslatex  '' 
exportasxml    ''

Remember that the argument to these 'verbs' must be a C (or Lua) style string. The director interface was designed this way so that one could search for special characters, etc. For example, this will replace all tabs with spaces in the other window:

   PerformOther('replaceall','\t\000 ')

Here the octal constant \000 is used to separate the target from the replacement string.

Perhaps the verb with the most potential is 'extender', which allows you to execute Lua code in the other instance. For instance, this code will move to a position in the other window, and call a Lua function to mark that position.

   PerformOther('goto',line)
   PerformOther('extender','mark_current_line()')

The instance of SciTE which is running the show (so to speak) can also be driven by such commands, and this is suprisingly useful. The function Perform executes these commands in the current window. For example, Perform('close') will close the current buffer. A particularly useful verb is 'menucommand', since this allows you full access to any SciTE functionality available through menus. I've supplied Command(cmd) to take advantage of this, and extracted most of the useful menu ids from SciTE.h. e.g. Command 'IDM_BOOKMARK_TOGGLE' will set a bookmark at the cursor position.

Finally, the SciteOther library also supplies a 'quiet' replacement, Execute(cmd), for os.execute(), which doesn't do that nasty flashing black box.

Notes and Limitations

Currently scite_other will only work for Win32 platforms, but the equivalent Linux shared library would not be difficult to write. scite_other.c is in fact a good reference for people wishing to understand SciTE's Director interface.

Examples

This Lua function will close the current file and open it in another window.

  function open_in_other()
    local file = props['FilePath']
    Perform('close')
    OpenOther(file)
  end

Bookmarks are a very useful SciTE feature, but they do not force the line position to be in the middle of the screen. Here's a replacement for 'Next Bookmark' which forces the line to be in the middle.

  function next_bookmark()
    Command 'IDM_BOOKMARK_NEXT'
    local line = editor:LineFromPosition(editor.CurrentPos)
    local top = editor.FirstVisibleLine
    local middle = top + editor.LinesOnScreen/2
    editor:LineScroll(0,line - middle)
  end

This will find the supplied word in the other window and set a bookmark:

  function find_in_other(f)
     PerformOther('find',f)
     Command('IDM_BOOKMARK_TOGGLE','other')
  end


RecentChanges · preferences
edit · history
Last edited November 11, 2004 10:12 am GMT (diff)