# History

Magma provides a history system which allows the recall and editing of previous lines. The history system is invoked by typing commands which begin with the history character ‘%’. Currently, the following commands are available.

Each of the lettered commands may also be written out as a word — the letter is simply an abbreviation of it:

```
%e  %edit      %E  %Edit       %p  %print     %P  %Print
%s  %seed      %S  %Seed       %r  %rerun     %b  %browser
%c  %commands  %f  %find       %o  %options

```

`%c` prints the list itself, so it need not be remembered.

Case means the same thing in the word as in the letter, so `%Edit` is to `%edit` what `%E` is to `%e`, and `%Rerun` is no more a command than `%R` is. A line number may follow either form, with or without a space (`%p3` and `%print 3` are the same). Anything else after the `%` is an error — in earlier versions text following a command letter was ignored, so that `%rubbish` quietly reran the whole history.

## `%p`

List the contents of the history buffer. Each line is preceded by its history line number.

## `%pn`

List the history line $n$ in %p format.

## `%pn₁ n₂`

List the history lines in the range $n_1$ to $n_2$ in %p format.

## `%P`

List the contents of the history buffer. The initial numbers are *not* printed.

## `%Pn`

List the history line $n$ in %P format.

## `%Pn₁ n₂`

List the history lines in the range $n_1$ to $n_2$ in %P format.

## `%s`

List the contents of the history buffer with an initial statement for each line to reset the random number seed to the value it was just before the line was executed. This is useful when one wishes to redo a computation using exactly the same seed as before but does not know what the seed was at the time.

## `%sn`

Print the history line $n$ in %s format.

## `%sn₁ n₂`

Print the history lines in the range $n_1$ to $n_2$ in %s format.

## `%S`

As for %s except that the statement to set the seed is only printed if the seed has changed since the previous time it was printed. Also, it is not printed if it would appear in the middle of a statement (i.e., the last line did not end in a semicolon).

## `%Sn`

Print the history line $n$ in %S format.

## `%Sn₁ n₂`

Print the history lines in the range $n_1$ to $n_2$ in %S format.

## `%`

Reenter the last line into the input stream.

## `%n`

Reenter the line specified by line number $n$ into the input stream.

## `%n₁ n₂`

Reenter the history lines in the range $n_1$ to $n_2$ into the input stream.

## `%e`

Edit the last line. The editor is taken to be the value of the EDITOR environment variable if is set, otherwise “/bin/ed” is used. If after the editor has exited the file has not been changed then nothing is done. Otherwise the contents of the new file are reentered into the input stream.

## `%en`

Edit the line specified by line number $n$.

## `%en₁ n₂`

Edit the history lines in the range $n_1$ to $n_2$.

## `%E`

Edit the entire history; this is like %e but with no line number given it edits all the history lines (equivalent to %e $1$ $N$, where $N$ is the last line number) rather than just the last line. A line number or range may also be supplied, exactly as for %e.

## `%! shell-command`

Execute the given command in the Unix shell then return to Magma.

## `%r`

Re-enter and rerun the entire history; this is equivalent to typing %1 $N$, where $N$ is the number of the last history line. All the commands of the current session are run again in order.

## `%f pattern`

List the history lines that contain *pattern*, each with its line number, so that they can then be re-entered with `%`$n$. The pattern is a regular expression unless `browser-search-literal` is set, and is matched case-insensitively if `browser-filter-ignore-case` is (Section [The Options File](history-files.md#sec-options-file)) — the same two options the browser’s own searching obeys.

## `%o`

Show the history options: each one, the value in force, and whether that value came from the options file or is the built-in default. The heading names the file that was read, or says there was none — with `MAGMA_CONFIG_DIR` unset no options file is looked for at all, which is otherwise silent.

## `%c`

Print a list of the history commands, a line for each giving its letter, its word, and what it does, followed by the forms that have no letter (`%`$n$, `%` and `%!`). The list is generated from the same table the commands are dispatched from, so it cannot fall out of date.

## `%b`

Open the browser of saved sessions (see `MAGMA_CONFIG_DIR` in Section [Environment Variables](environment-variable.md#sec-environment-variable)). It is usually opened with a key — `<Esc> r` in emacs mode, Ctrl-R in vi mode — but those can be rebound or unbound with the `browser-key-emacs` and `browser-key-vi` options, whereas this command always works and is the same in both editing modes.
