History Commands
These are the oldest part of the history system, and most of what they once did is now done by the line editor (Section The Magma Line Editor) and, since V2.30, by the session browser (Section Saved Sessions and the Browser).
%P remains the way to print what has been typed in the current session, for pasting or saving.
All the commands here begin with the history character ‘%’ and are typed straight at the prompt, followed by Enter.
Since V2.30 there are several more of them: %b, %c, %E, %f, %h, %o, and %r; a range may be given as all; and a command given no range acts on the current session (or, for %e and %, its last line).
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 %h %history
%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.
There are two things a command can act on, and the difference is worth having clear: the lines entered in this session, which is what it acts on if given nothing, and everything the history remembers, which the user asks for with the word all.
This session. With no argument, %p, %P, %s, %S, %E, and %r act on the lines entered in this session. A number here is a line number, as it always has been, and the numbers are the ones %p prints:
%p this session's lines, each preceded by its line number
%P the same without the numbers
%p 12 line 12
%p 12 20 lines 12 to 20
%r re-enter and rerun this session's lines
A number reaches any line the buffer holds, though, not only this session’s: the lines read from the history file (Section The History File) when Magma starts are numbered too, and they come first — which is why the first line typed in a session may be number 1001.
Everything the history remembers. This is the whole history buffer, which normally holds the whole history file (Section The History File): by default the last thousand lines the user has typed, this session’s and earlier sessions’ alike. Add the word all and the command takes them all in. It may be abbreviated to a, with or without a space, and may run on to the command letter, as in %pa. A number after all is a count: the last \(N\) lines, not a line number:
%p all every remembered line, numbered
%pa %p a the same -- 'all' abbreviates to 'a', with or without a space
%PA every remembered line, unnumbered -- the one to paste
%p all 20 the last 20 remembered lines, numbered
%PA 20 the last 20, unnumbered
%h %h 20 %h is exactly %P all, and takes the same count
%h 0 all of them, however many
A count is useful when there may be a thousand lines or more in the full history (a count larger than the history gives all of it). all may be written in any case; the case of the command letter still matters (%PA is %P all).
Given all and no count, a printing command stops at the last 100 lines and says so (to avoid dumping a long history onto the screen by default). A count asks for a different number and 0 asks for all of them; the option history-print-lines (Section The Options File) changes the 100, and setting it to zero turns the limit off. It applies only to the commands that print: %e all and %E all are never shortened.
- %p all
List every line the history buffer holds, including any recalled from earlier sessions, in
%pformat.allmay be abbreviated toa.
- %P all
List every line the history buffer holds, in
%Pformat.allmay be abbreviated toa, so that%PAis the shortest way to see everything the history remembers. This is what%hdoes.
- %h
List every line the history buffer holds — those entered in this session and any recalled from earlier ones — without the line numbers. It is exactly
%P all. It takes no line number of its own, but it does take the same count thatalldoes:%h 20is the last twenty remembered lines and%h 0is all of them. With no count it stops athistory-print-lines, 100 by default, and says that it has. (In a prompt string ‘%h’ is a different thing altogether and is unchanged: there it expands to the number of the line being typed.)
- %s
List the lines entered in this session 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₁ n₂
Print the history lines in the range \(n_1\) to \(n_2\) in %s format.
allmay be given instead of a range, and takes in every line the buffer holds — though the seeds of lines recalled from an earlier session are not meaningful, as noted in Section The History File.
- %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).
- %e
Edit the last line. The editor is taken to be the value of the
EDITORenvironment variable if it is set, otherwise/bin/edis 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₁ n₂
Edit the history lines in the range \(n_1\) to \(n_2\).
allmay be given instead of a range, and edits every line the buffer holds.
- %E
Edit this session’s lines; this is like %e but with no line number given it edits all the lines entered in this session rather than just the last one. A line number or range may also be supplied, exactly as for %e, or
allto edit every line the buffer holds.
- %r
Re-enter and rerun the lines entered in this session: they are all run again, in order, as if they had been typed afresh. A line number or range may be given instead, exactly as for
%p.%ris the one ranged command with noallform. It is also the only one that runs what it selects with nothing in between, and rerunning every remembered line is too drastic for a short form; give an explicit range instead.
- %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 number is printed as a Magma comment, in the form/* n */, so that the listing can also be pasted straight back into a session. The pattern is a regular expression unless optionbrowser-search-literalis set, and is matched case-insensitively if optionbrowser-filter-ignore-caseis (Section The Options File) — the same two options the browser’s own searching obeys.
- %o
Show the history options: each one, the value in force, the default it replaced if it has replaced one, and whether it came from the options file. The heading names the file that was read, or else says why none was — there may be no history directory, or no
optionsfile in the one there is, or the history may be turned off altogether. Use it to find out why an option seems to have had no effect.
- %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%!).
- %b
Open the browser of saved sessions (Section Saved Sessions and the Browser). It is usually opened with a key —
<Esc> rin emacs mode,<Ctrl>-Rin vi mode — but those can be rebound or unbound with thebrowser-key-emacsandbrowser-key-vioptions (Section The Options File), whereas this command always works and is the same in both editing modes.