Go to the previous, next section.

Command History

It is often very useful to be able to repeat a command, or perhaps correct a mistake in what you have just typed. Ways of doing this are usually referred to as `history', and SM has two distinct mechanisms. One is very similar to that of the Unix C-Shell, and the other allows you to edit commands using a syntax similar to the popular editor `emacs', or a generalisation of the DCL history under VMS. If you are not familiar with Unix, emacs, or VMS don't despair; a description of the commands and how to invoke them follows in this document. Both of these mechanisms are implemented by the routine which reads input lines. As each line is sent to the parser, it is copied onto a history list. This list may be printed with HISTORY, and the commands may be re-used by referring to them by number, as ^nn, or by a unique abbreviation, as ^abbrev. In addition, the last command may be repeated by using ^^ and the last word of the last command by ^$.@footnote #{ ^^ and ^$ really do get back the last command typed, even if it isn't on the history list. If you want the last remembered command, use up-arrow or ^P} These symbols are expanded as soon as they are recognised (see examples, or experiment), and are then available for modification by the editor. Sometimes a ^string will retrieve a command beginning string, but not the one that you want. Version 2.1.1 no longer supports the use of ^TAB to search for the next-most-recent command beginning string, but you can use the search commands (^R and ^S) instead. Some people really don't want ^ to be their history character, either because they're used to something else (such as !), or because they want to type lots of real ^s (e.g. you are using TeX-style strings); if this describes you, rebind them -- see the next section. If you are considering the history list as a sort of programme to be repeated you may think that HISTORY lists the commands in the wrong order; if so use HISTORY -.

For example, if I type:

echo I like SM
SM will set the prompt to be @, replace the macro echo by its value WRITE STANDARD and print
I like SM
and then
2   echo I like SM
1   PROMPT @
(The actual numbers will be different, depending on what other commands you have executed, and also because SM may have read a history file. In that case there'll be many more commands on the list, but no matter.) If I then type
^2 <CR>
(that is ^2 not control-2) the screen will look like
@ echo I like SM
I like SM
as if I had just typed it in (@ is the prompt) . Typing
^^ (Yes, ^$ ) <CR>
will now result in SM printing (truthfully)
I like SM (Yes, SM )

It is possible to delete commands from the history buffer with the DELETE command. If the command is given with zero, one, or two arguments, then the specified range is deleted (but their numbers are not re-used). If no arguments are given, the last command on the buffer is deleted, and its number is released to be re-used. In other words, the command DELETE will delete first itself, and then the previous command from the history list. The command DELETE HISTORY only removes itself from the history list, and several of the common commands are defined as macros which use it, for instance dev is defined as DELETE HISTORY DEVICE. This means that the command will not appear on the history list, to confuse you when you do a playback. But if you now innocently use dev in a macro, that macro won't appear on the list either. Still worse, if you use dev twice in one macro, the previous command will be deleted as well which could be quite confusing. You can also delete lines of history using ESC-^D as described shortly.

The numbering is consecutive, starting at zero. Each command retains its number until you use a HISTORY command to list the remembered commands, in which case they are all renumbered, and it is these new numbers that are listed.

By default only 80 lines are remembered, and as you continue typing earlier ones fall off the list.@findex history

Because the history buffer is also used to compose complex commands, this limit can be aggravating. You may be able to defeat this by putting many commands on each line (you may have to use \n to terminate label commands explicitly) or by writing macros. Alternatively you can define a longer history buffer when you start SM by including an entry history in your environment file

which gives the number of commands to be remembered. If you set history to be 0 the history list is made infinitely long. Incidently, it is the total number of commands that matters, not the range of history numbers present.

This limit on the number of history lines isn't enforced while writing a macro onto the history list (using WRITE HISTORY). You can use this fact to write a sneaky macro that extends your history; type HELP extend_history if you are interested.

Some people seem to like their history editors to remember where they were, so that after they retrieve and execute a command the next ^P or will retrieve the command one further back on the history list (that is, if you have just retrieved command number 123 and executed it as command number 234, then ^P will get you command number 124; you can execute it as command number 235). If this describes you, define the variable remember_history_line, which you can either do directly, or by putting a line remember_history_line 1 in your `.sm' file.

The editor allows you to modify commands, either as you type them or as you retrieve them from the history list. The various editing commands may be bound to keys of your choosing, but the default bindings are given in this list of possible commands:

Go to start of line.
Go back one character. (Equivalent to ).
Interrupt (as usual).
Delete character under cursor.
Go to end of line.
Go forward one character. (Equivalent to ).
Identical to ^? (DEL). Delete character to left of cursor.
^I (TAB)
Insert spaces up to the next tab stop. By default a tab is taken to be 8 characters wide, but this may be changed by specifying tabsize in your `.sm' file.
^J (LF)
Equivalent to ^M.
Delete to end of line. The deleted string is stored, and may be restored using ^Y, repeatedly if so desired.
Redraw the current line.
^M (CR)
Send line to be executed. Some terminals seem to replace ^M with a linefeed (^J), thereby making it impossible to make SM obey you. We therefore make ^@ equivalent to ^M for emergency use. (This is control-space on many terminals).
Get the next command on the history list, if it exists (see ^P). (Equivalent to ).
Execute the previous command on the history list. Equivalent to ^P^E^M.
Get the previous command on the history list, if it exists (see ^N).(Equivalent to ).
Quote next character; Turn off any special significance to the editor. ^Q is often used by the terminal, so we have defined ^[-q (that is escape followed by q) as an alternative.
Search backwards (reversed) for a string; the opposite of ^S. The `string' can actually be any regular expression (see the manual entry for APROPOS). If you specify a zero-length string (i.e. simply hit carriage return) the previous search string will be reused.
Search forward for a string; the opposite of ^R. ^S is often used by the terminal, so we have defined ^[-s (that is escape followed by s) as an alternative.
Toggle insert/overwrite. By default, characters are inserted before the cursor. If overwrite is set, they replace the character under the cursor. Note that ESC-u will not correctly restore words deleted with ESC-d in overwrite mode.
Delete from the cursor to the start of the line.
Go forward 5 lines.
Delete the previous word. Identical to ESC-h
Insert the string most recently deleted with ^K after the cursor.
Return to the operating system, without killing SM. (Under VMS, if you are running SM in a spawned subprocess ^Z will attach you to DCL. Otherwise, SM returns you to DCL.)
^? (DEL)
Equivalent to ^H.
Delete this line and remove it from the history list. Note that this is different from just clearing a line with (e.g.) ^U, which only erases a copy of the line.
Go to the first line of a macro, or the oldest history command.
Go to the last line of a macro, or the most recent history command.
Go to a given line of a macro, or a given history command. You'll be prompted for the line number, if you change your mind you can get out with DEL or ^H.
Quote the next character, turning off any special significance to the editor. Identical to ^Q.
Search forward for a string. Identical to ^S.
The opposite of ^V, go back 5 lines.
Like ^Y, except that it gets older deletions, cycling back through a collection of (currently 5) deleted lines.

Some ESC-letter combinations are available which operate upon complete words. A word is defined as a whitespace delimited string, so 2.998e8 is a perfectly good word. In addition, it is possible to undelete words that have been deleted with an ESC-d or ESC-h.

Go to the start of the previous word.
Delete to the beginning of the next word.
Go to the beginning of the next word.
Delete back to the beginning of the current word. The same as ^W.
Restore the last word deleted, putting it before the cursor. Further ESC-u's will restore more words. When no more are available, the bell is rung.

Any printing character is inserted before the cursor (unless overwrite has been set with ^T ). Illegal characters ring the terminal bell. If you insert a non-printing character on a line, the cursor may get confused.

If ever you are stuck at the command interpreter, and you want to send a signal to the operating system (e.g. a ^Y to DCL), but SM is catching the key and using it for its own purposes, the easiest thing to do is to define a macro such as MACRO aa {aa2 , and then run it. While it is running (i.e. until you type ^C) keys should have their usual functions.

Go to the previous, next section.