4 The MLWorks Interactive Environment Library

4.8 Editor support: The Editor structure

The MLWorks interface to editor facilities is provided by the Editor structure, along with the editor items in the structure Shell.Options.Preferences. MLWorks allows you to edit a named file or to specify that you would like to edit a particular declaration visible in the interactive context, in which case MLWorks searches its compilation records to find the file containing that declaration, then lets you edit it.

MLWorks supports two kinds of editor facility: an Emacs server based on emacsclient, and the power to invoke any editor by sending to the underlying operating system a command-line call to an editor program. You can define a set of the latter command-line calls and give them names for easy access: they are called custom editors.

The command-line strings can use the following codes:

%f
A filename.

%l and %sl
Starting line number.

%c and %sc
Starting character number.

%el
Ending line number.

%ec
Ending character number.

They can use %% for the literal %.

For example, the vi editor could be defined by:

Shell.Editor.Custom.addCommand("My vi",
                    "xterm -name VIsual -e vi +%l %f");

This command, sent to UNIX as a system call, would start vi in an xterm window. The %l code is for a line number to start vi at: when MLWorks invokes vi, it replaces %l with the number of a line at which to place the cursor. Similarly, the %f code is substituted with a file name, allowing MLWorks to start the editor on a particular file.

Custom editors are similar to external editors because they are defined with a command-line string. However, a custom editor also has:

You can use the custom editor's name in the Preferences > Editor dialog to specify that you want to use it. The connect dialog is not a window-system dialog, but a dialog in the sense of an episode of communication: a dialog consists of a list of commands to be sent to the editor when MLWorks establishes contact with it, and a protocol by which to send the commands. When MLWorks wants to connect to an (existing) remote editor, it first establishes contact and then sends the editor a sequence of commands down the channel that has been established, according to the. These commands typically direct the editor to load a source file at a specific position. Note that connect dialogs are not necessary for all custom editors you define; most editors cannot take commands in this way.

The Emacs server editor option itself uses the connect dialog mechanism to issue the startup commands it needs to make Emacs load in a source file and place the cursor at a specific line. It issues a sequence of Emacs commands including Find File and Goto Line to do so. The example in the entry for addConnectDialog, page 127, shows how this can be done.

MLWorks knows two connect dialog styles: one for UNIX, based on UNIX sockets and called Emacs (because it is used to implement the Emacs server); and one for Windows, based on the DDE (Dynamic Data Exchange) mechanism and called DDE.

The Shell.Editor.Custom.addConnectDialog function adds a series of dialog commands for a particular custom editor. When MLWorks tries to talk to the selected editor, this sequence of commands (after replacement of any % codes) is sent.

The Editor structure has the following skeletal signature:

structure Editor:
 sig
  structure Custom:
   sig
    val addCommand: (string * string) -> unit
    val addConnectDialog: (string * string * string list) -> unit
    val names: unit -> string list
    val remove: string -> (string * string * string list)
   end
  exception EditError of string
  val editDefinition: ('a -> 'b) -> unit
  val editFile: string -> unit
 end

addCommand
addConnectDialog
names
remove
EditError
editDefinition
editFile

MLWorks Reference Manual (version 1.0) - 3 DEC 1996

Generated with Harlequin WebMaker