To extend jed, it is necessary to become familiar with the S-Lang
programming language. S-Lang not a standalone programming language like
C, Pascal, etc. Rather it is meant to be embedded into a C program. The
S-Lang programming language itself provides only arithmetic, looping, and
branching constructs. In addition, it defines a few other primitive
operations on its data structures. It is up to the application to define
other built-in operations tailored to the application. That is what has
been done for the jed editor. See the document slang.txt for
S-Lang basics as well as the jed Programmer’s Manual for functions jed has
added to the language. In any case, look at the *.sl files for
explicit examples.
For the most part, the average user will simply want to rebind some keys and change some variables (e.g., tab width). Here I discuss setting keys and the predefined global variables.
Defining a key to invoke a certain function is accomplished using the
setkey function. This function takes two arguments: the function to
be executed and the key binding. For example, suppose that you want to
bind the key Ctrl-A to cause the cursor to go to the beginning of
the current line. The jed function that causes this is bol (See
the jed Programmer’s Manual for a complete list of functions). Putting
the line:
setkey ("bol", "^A");
in the startup file jed.rc (.jedrc) file will perform the
binding. Here ^A consists of the two characters ^ and
A which jed will interpret as the single character Ctrl-A.
For more examples, see either of the S-Lang files emacs.sl or
edt.sl.
The first argument to the setkey function may be any S-Langexpression. Well, almost any. The only restriction is that the newline
character cannot appear in the expression. For example, the line
setkey ("bol();skip_white ();", "^A");
defines the Ctrl-A key such that when it is pressed, the editing
point will move the beginning of the line and then skip whitespace up to
the first non-whitespace character on the line.
In addition to being able to define keys to execute functions, it is also possible to define a key to directly insert a string of characters. For example, suppose that you want to define a key to insert the string int main(int argc, char **argv) whenever you press the key Esc m. This may be accomplished as follows:
setkey (" int main(int argc, char **argv)", "\em");
Notice two things. First of all, the key sequence Esc m has
been written as "\em" where \e will be interpreted by jed as
Esc. The other salient feature is that the first argument to
setkey, the “function” argument, begins with a space. This tells
jed that it is not be interpreted as the name of a function; rather, the
characters following the space are to be inserted into the buffer.
Omitting the space character would cause jed to execute a function called
int main(int argc, char **argv) which would fail and generate an
error.
Finally, it is possible to define a key to execute a series of keystrokes similar to a keyboard macro. This is done by prefixing the “function” name with the @ character. This instructs jed to interpret the characters following the @ character as characters entered from the keyboard and execute any function that they are bound to. For example, consider the following key definition which will generate a C language comment to comment out the current line of text. In C, this may be achieved by inserting symbol "/*" at the beginning of the line and inserting "*/" at the end of the line. Hence, the sequence is clear (Emacs keybindings):
"\001".\005.To bind this sequence of steps to the key sequence Esc ;, simply use
setkey("@\001/*\005*/", "\e;");
Again, the prefix @ lets jed know that the remaining characters will
carry out the functions they are currently bound to. Also pay particular
attention to the way Ctrl-A and Ctrl-E have been written. Do
not attempt to use the ^ to represent “Ctrl”. It does not
have the same meaning in the first argument to the setkey function
as it does in the second argument. To have control characters in the
first argument, you must enter them as \xyz where xyz is
a three digit decimal number coinciding with the ASCII value of the
character. In this notation, the Esc character could have been
written as \027. See the S-Lang Programmer’s Reference Manual for
further discussion of this notation.
The setkey function sets a key in the global keymap from
which all others are derive