The Magma Line Editor
Magma keeps the command lines of the current session in a history buffer — together with any lines it has remembered from earlier sessions (see Section The History File) — and the line editor is how they are recalled and edited.
Magma provides a line editor with both Emacs and VI style key bindings. To enable the VI style of key bindings, type
and type
to revert to the Emacs style of key bindings. By default ViMode is false; that is, the Emacs style is in effect. Many key bindings are the same in both Emacs and VI style. This is because some VI users like to be able to use some Emacs keys (like <Ctrl>-P) as well as the VI command keys. Thus key bindings in Emacs which are not used in VI insert mode can be made common to both.
Key Bindings (Emacs and VI mode)
<Ctrl>-key means hold down the Control key and press key.
- <Tab>
Complete the word which the cursor is on or just after. If the word doesn’t have a unique completion, it is first expanded up to the common prefix of all the possible completions. An immediately following Tab key will list all of the possible completions. Currently completion occurs for system functions and procedures, parameters, reserved words, and user identifiers.
- <Ctrl>-D
On an empty line, send a EOF character (i.e., exit at the top level of the command interpreter). If at end of line, list the completions. Otherwise, delete the character under the cursor (“delete”).
- <Ctrl>-L
Redraw the line on a new line (helpful if the screen gets wrecked by programs like “write”, etc.).
- <Ctrl>-N
Go forward a line in the history buffer (“next”). If the cursor is not at the beginning of the line, go forward to the first following line which starts with the same string (ignoring spaces iff the ignore spaces option is on — see
SetIgnoreSpaces) as the string consisting of all the characters before the cursor. Also, if<Ctrl>-Nis typed initially at a new line and the last line entered was actually a recall of a preceding line, then the next line after that is entered into the current buffer. Thus to repeat a sequence of lines (with minor modifications perhaps to each), then one only needs to go back to the first line with<Ctrl>-P(see below), press<Return>, then successively press<Ctrl>-Nfollowed by<Return>for each line.
- <Ctrl>-P
Go back a line in the history buffer (“previous”). If the cursor is not at the beginning of the line, go back to the first preceding line which starts with the same string (ignoring spaces iff the ignore spaces option is on — see
SetIgnoreSpaces) as the string consisting of all the characters before the cursor. For example, typing at a new linex:=and then<Ctrl>-Pwill go back to the last line which assignedx(if a line begins with, say,x :=, it will also be taken).
On most systems the arrow keys also have the obvious meaning.
Key Bindings in Emacs mode only
<Meta>-key means press the Meta key and then key. (At the moment, the Meta key is only the Esc key.)
- <Ctrl>-R
Search backwards through the history for a line containing what the user types, a character at a time — the incremental reverse search of
readlineandIPython. The row becomes(i-search)`pat':followed by the most recent line that contains pat, and it is re-searched as each character is typed. Where<Ctrl>-Psearches by prefix, this searches anywhere in the line.Another
<Ctrl>-Rmoves to the next older line that matches, and<Ctrl>-Nto the next newer. Once the history buffer is exhausted the search goes on into the saved sessions, if an archive is being kept (Section Saved Sessions and the Browser); the prompt then reads(i-search saved), and(failing i-search)when there is nothing left to find. With no archive the buffer is the whole of it — and it holds what was read from the history file (Section The History File), so there is nothing further to reach.<Backspace>shortens the pattern and<Ctrl>-Uclears it.<Return>puts the line that was found into the editor without running it, so that it can be edited first; a second<Return>runs it, as always.<Ctrl>-Gor<Esc>abandons the search and puts back the line the user was typing — except that when the pattern has failed, the first<Ctrl>-Gtakes it back to the last part of it that did match, so that a typo costs one key rather than a<Backspace>for each character of it (as inemacsitself). Any other control character ends the search, keeps the line that was found, and then does what it normally does.In emacs mode the session browser (Section Saved Sessions and the Browser) is
<Esc> r(or<Esc> R), or a second<Ctrl>-Rat an empty search prompt on an empty line. In vi mode<Ctrl>-Ron an empty line opens the browser instead (or offers to start an archive), and this search is on/in command mode. All of these keys can be changed with thesearch-key,search-key-vi,browser-key-emacs, andbrowser-key-vioptions (Section The Options File).
Key Bindings in VI mode only
In the VI mode, the line editor can also be in two modes: the insert mode and the command mode. When in the insert mode, any non-control character is inserted at the current cursor position. The command mode is then entered by typing the Esc key. In the command mode, various commands are given a range giving the extent to which they are performed. The following ranges are available:
- %
Move to the matching bracket. (Bracket characters are (, ), [, ], \(\{\), \(\}\), \(<\), and \(>\).)
Any range may be preceded by a number to multiply to indicate how many times the operation is done. The VI-mode also provides the yank-buffer, which contains characters which are deleted or “yanked” – see below. The following keys are also available in command mode:
- a
Move forward a character (if not already at the end of the line) and change to insert mode (“append”).
- /
Start the incremental history search, as
<Ctrl>-Rdoes in emacs mode; the keys within the search are the same, except that<Ctrl>-P(rather than another/, which is part of the pattern) moves to the next older line that matches. Ifsearch-key-viis set to a control key instead, that key does so, as<Ctrl>-Rdoes in emacs mode. Unlike the/ofreadline’s vi mode, the search is incremental. The key can be changed with thesearch-key-vioption (Section The Options File).
Completion Preferences
When the user presses the Tab key for completion, the line editor offers all intrinsics matching the partial word typed so far. Because many intrinsics have more than one spelling (e.g., the British (-ise) and American (-ize) variants, or the -our/-or families), both spellings are normally offered. The following procedures let the user nominate a preferred spelling, so that the non-preferred duplicates are suppressed from the completion list. Usually, the user would simply prefer to use SetCompletionPreferenceStyle("US"); or SetCompletionPreferenceStyle("UK"); but the SetCompletionPreference procedure allows fine-grained behaviour to be specified.
- SetCompletionPreference(P, O): MonStgElt, MonStgElt
Record a preference for the spelling given by the string
P(‘preferred’) over that given by the stringO(‘other’) when the line editor expands tab completions. Thereafter, whenever the completions for a partial word contain two entries that differ only byPversusO– at the end of the word or at the end of an internal subword (as delimited by a capital letter in aCamelCasename), the entry containingOis discarded and only thePform is offered.As a special case, the pair
("ize", "ise")(or its reverse("ise", "ize")) also installs the related suffix forms automatically, namely the pairsizes/ises,ized/ised,izing/ising,izer/iser,izers/isers,izable/isable, andization/isation.Several preferences may be in force at once; each call adds a new rule.
- ClearCompletionPreference()
Remove all completion preferences previously set by
SetCompletionPreference, restoring the default behaviour in which every registered spelling is offered as a completion.
- SetCompletionPreferenceStyle(S): MonStgElt
A convenience procedure that calls
SetCompletionPreferenceon a standard collection of British/American spelling pairs at once. IfSis"US", the American (US) spellings are preferred, so that-ize,-or,-ors,-oring, and-erare kept in preference to-ise,-our,-ours,-ouring, and-rerespectively; ifSis"UK", the British spellings are preferred instead.