To support a programming language for macro definitions
(p.
) stedi is equipped with the possibility to
define and use variables. The syntax that is connected to the use of
these variables resembles the syntax of the UNIX c-shell csh very much.
When variables are used their name is preceded by a dollar ($) sign.
The name of the variable should consist of alphanumeric characters of
which the first should be alphabetic. In addition the underscore may be
used at any position (also the first). There may be no more than 10
characters (the dollar sign doesn't count). If the use of the variable
makes it necessary that the contents of the variable are immediately
followed by an alphanumeric character the name may be enclosed in curly
brackets: ${name}
. The use of names is case sensitive as this
doesn't interfere with the file system. There is a number of reserved
names with a special meaning. These are given later in this chapter.
When a variable is defined or a value is assigned to it its occurrence
at the left hand side of the statement shouldn't be preceded by the
dollar sign. The syntax of such a statement is:
set variable = expression
If the variable exists already its old `value' is replaced by its new
`value'. If the variable didn't exist a new entry in the list of
variables is made. If this is originated from inside a macro, the
variable is removed from the list again when the macro is terminated.
There are two options for the set command. The global option makes that
for an already existing value the editor looks also among the variables
of the parents (and these can be changed) This is done with
set -G variable = expression
The local mode makes that the editor will not look among the variables
of the parents and won't change these. If there is no variable yet by
this name among the variables of the macro a new one will be made, even
if this means that there is now more than one variable with that name.
If a child process looks for a variable with this name it will run into
the closest variable. The local mode (the default mode) is forced with
the command:
set -L variable = expression
The L and the G are case insensitive.
The effect of this is that a macro has full control over the variables
of its parents, but all variables of its children are hidden from it. The
syntax of the expression at the right hand side is explained in the
chapter on macros (p.
). If just a simple string
is needed it can be provided, enclosed by double quotes:
set quotation = "Eureka!"
If a dollar sign is needed inside the string this can be done by
`escaping' it with a backslash character. The other character that
should be escaped this way is the double quote. In addition linefeeds
can be put in the string by an escape character (or a backslash for
systems that don't use the backslash in the file system) at the end of
the line. In this last case a linefeed is put in the string and the next
statement is seen as a continuation. The matching double quote should
then be on this next line. In the command line a linefeed or carriage
return can always be inserted after typing an escape character, or with
the Ctrl-H command (p.
)
The `value' of a variable is always a character string. For some
purposes stedi will try to interpret this string as a number. If
this turns out to be impossible an error message may be the result. Some
operations can give different results, depending on whether the
variables involved can be interpreted numerically
(p.
.
The contents of a variable can be inspected with the show command. This
command has the syntax:
show variable
In this command the dollar sign should not be used in front of the
variable. You can try this out with the statements:
show date
and
show $date
In the second case the date is substituted before the show command is
executed. This means that there is a rather funny name that doesn't obey
the rules for names, so an error message will be given.
There are names that have a special meaning. Most of these
give the user access to internal information so that he may use it
inside macro's. Others are meant to control some settings of stedi.
In addition the variables in the environment can be inspected.
The reserved names concerning the internal information are:
- buffer
- The number of the current buffer.
- byte
- The number of bytes in the file before the cursor position.
- char
- The current character. An empty string when the cursor
is in virtual space.
- column
- The number of the column of the cursor in the current buffer.
- cwd
- The name of the current working directory. This is usually the name
of the directory from which the editor was started.
- date
- The date.
- direction
- Either '<', '<<', '0', '>>' or '>' for the search/replace direction
modes.
- filename
- The name of the file in the current buffer. Only its local name is
considered.
- fold
- The name of the current fold if the current fold would be closed.
- fullname
- The full name of the file in the current buffer. This name includes
the path name.
- insertmode
- Either an 'I' or an 'O' for the insert or overstrike modes.
- isfold
- This variable indicates whether the cursor is in a closed fold line.
- ismark
- The value ON indicates that there is a mark. If there is no mark the
value is OFF.
- key
- The use of this variable causes stedi to wait for a character
from the keyboard. The character is presented as a string of 8
hexadecimal digits in the same notation as the key that is entered
in the text after a ctrl-K.
- lastmess
- The last message that was displayed in the message line.
This could be used for analysis to make the editor jump to an error
message of the macro processor.
- line
- The number of the current line in the current buffer.
- linechars
- The number of characters in the current line.
- maxcol
- The number of the column if the cursor were to be moved to the end
of the current line.
- nextatt
- The file attribute of the file that was obtained
after $nextfile has returned the value true. See also
p.
.
- nextdate
- Gives the date and time of the last file that was found with
$nextfile. The format is yyyy/mm/dd-hh:mm:ss to allow for
lexicographic sorting of dates. See also
p.
.
- nextfile
- When this variable is read it returns true (the digit 1) if in the
file search that was initiated with a `first' command a new file was
found. Each use of $nextfile tries to find a new file. If no new
file is found the value false (a digit 0) is returned. The
information about the file can be obtained with the variables
nextatt, nextdate, nextname and nextsize. See also
p.
.
- nextfname
- Gives the name of the last file that was found with $nextfile. If
the pattern given the the `first' statement contained any path
information it is included in the name. See also
p.
.
- nextname
- Gives the name of the last file that was found with $nextfile.
There is no path information in this name. See also
p.
.
- nextsize
- Gives the size of the last file that was found with $nextfile.
See also p.
.
- numchar
- The number of characters left of the cursor.
- range
- This variable contains the characters of the current line that are
between the column of the mark and the column of the cursor. It
doesn't matter whether the mark is in the same line as the cursor.
Only its column position is relevant.
- returncode
- The string that was set in the last return statement that the editor
encountered. If a return statement doesn't mention a return code or
when there is no return code the string is empty.
- screenline
- The number of the line on the screen in which the cursor is.
- searchmode
- Either an 'S' or an 'N' for the case sensitive or case non
sensitive search mode.
- shell
- Indicates whether there is a command shell present that can
accept commands via the ! command. On the PC-like computers this
means that the environment variable COMSPEC has been set.
- totlines
- The total number of lines in the current buffer.
- word
- The current word.
- wordwrap
- The size of the word wrap. This will be an empty string when the
word wrap is either off or in the fortran mode.
- writemode
- The character that indicates in which mode stedi would write
the contents of the current buffer it it would be written (A, P, R
or U).
- wword
- The current word in the wordwrap sense. This means a word that is
enclosed by the white space characters blank, tab or ASCII zero,
rather than the more sophisticated definition for the variable
`word'.
- yankbuf
- Indicates the current yank buffer with either 'Y' or 'y'.
The above variables should not be used in the left side of a `set'
command. If the user tries to set such a variable a new variable with
this name is made and the old meaning of it is lost until the variable
is removed again. One can experiment with the above variables by using
the show command as in
show cwd
to see what the current directory is.
The variables that are meant to control some of the settings of stedi
are:
- autoclose
- Value is "on" or "off". determines whether the autoclose
facility is used when files are read or written.
- backup
- The character of the current backup mode (b, B, V or a !
indicating that no backup is made).
- color
- Indicating whether the colors of the text screen and the message
line should be exchanged. Values are "on" or "off". See also the
Alt-C command (p.
).
- dirty
- Value is "on" or "off", depending on whether the dirty flag is on or
off. The dirty flag indicates whether the file has been modified. It
is displayed as one of the status characters.
- hstep
- The stepsize for horizontal scrolling in the text buffers.
- maxhist
- The maximum number of lines in the command line history.
- menuspaced
- Determines whether only every odd position in the menu bar
is sensitive to clicks.
- mstep
- The stepsize for scrolling in the command/message line.
- numbers
- Sets the updating of the line number in the status line "on" or
"off". This is mainly for terminal connections. For those the
regular updates of the line number can mean a significant slowdown.
- pagedelay
- This variable has a numeric value which is the number of
milliseconds that stedi will take at least for drawing one
screen when scrolling with shift-up or shift-down (page-up or
page-down).
- waitflag
- Sets the wait flag on or off. This flags determines whether after the
execution of an external program or a call to shell stedi will
wait for a key to be pressed. This waiting avoids disturbing the
screen before the user has read it. See also the chapter on
executing an external command p.
.
- <char>
- The character can be any single character. The value assigned
is "on", "off" or "single". When "on" it forces the indicated
character to be interpreted as belonging to words. If the value
is "off" it will never be seen as part of a word and the value
"single" makes the character into a single character word. See also
the chapter on Word-oriented commands p.
.
These variables can be set and their settings can be stored in the
default file (with the exception of `dirty').
If a variable is used which has not been defined by the user, and whose
name isn't one of the reserved names stedi will inspect the
environment (p.
). If there is an
environment variable of which the name matches the name of the searched
for variable in a case insensitive way the return value will be the
contents of the environment variable. This way one can for instance test
for the setting of the environment variable STEDIMAC etc.
The number of variables that can be used in stedi is limited only by
the size of the available memory. The same mechanism that is used to
store the lines in the text is also used to store the variables. This
has an advantage and a disadvantage: The advantage is that no fixed size
buffers for names have to be allocated at startup (so that space isn't
lost). The disadvantage is that it is impossible to do a binary or
hashed search for a name, so that when there are very many variables
searching for a name may become slow (everything is relative).