Page: (editor)Top, Next: readline, Up: (cpl)cpl i Index

cpl-embedded line and full-screen editor

cpl includes a powerful console screen editor. It serves a double purpose as a GNU readline look-alike, providing command completion and command history to cpl interactive input, and as a full-screen editor for program development, equipped with CPL word and syntax completion. Interactive cpl and the editor are actually a single integrated environment (IDE): programs can be run from within the editor, and the cpl and editor screens can be swapped at the touch of a key. Both tools display in a console, which makes for a terse graphical appearance but in exchange allows equally swift use in local and remote terminals, as well as in a terminal-only environment like the Windows subsystem for Linux, and even in a smartphone's ssh client if one feels the need for it. Bash-like command completion and command history are traditionally provided by the GNU readline library, which supplies the familiar Tab and Up Arrow commands, input logging and more. The purpose of readline is to allow the user to edit each command line before committing it, and to keep a history of previous commands for rapid reuse. cpl readline accepts cursor-movement and other commands in one of three equivalent ways: dedicated editing keys, vi-like single-letter commands, and the mouse. Single-letter command mode is toggled in and out of by the Esc key. Full-screen mode is toggled in and out of by F1 or Esc `. Any cursor movement while Shift is pressed (or mouse movement with left button pressed) selects text. For single-letter functions which admit an inverse (such as undo - redo or search forwards - search backwards), the corresponding capital letter or the right mouse button selects its inverse. With the exception of those control characters that already have their own meaning (such as Ctrl-i, which is Tab, and Ctrl-h which is Backspace), Ctrl-<key> also works as an alternative to Esc followed by the same lower-case key. As a further alternative, Alt-<key> in most terminals sends the sequence Esc <key>, and thus produces the same effect as switching command mode on and then pressing <key>. On macOS, you may have to set the Use Option as Meta key option to use this modality. See support.apple.com/en-bn/guide/terminal/trmlkbrd/mac If full-screen mode is toggled on with no other file opened, the command history shows up in the full-screen editor, and the Enter key is now entered as a regular newline. On return to readline mode (when F1 or Esc ` is pressed again), the modified command history is replayed through interactive cpl as if this list of commands had been given afresh when it was launched. Other editing keys work just as in readline mode, except that history lines are now edited in place.
Page: (editor)readline, Next: full-screen, Prev: Top, Up: Top Index

Readline assisted console input

Most used editing keys: - Left (Esc h), right arrow (Esc l): previous, next char - Home (Esc ^), end (Esc $): beginning, end of line - Ctrl-Home (Ctrl-^), Ctrl-End (Ctrl-$, Esc A): beginning, end of file - Backspace: erase left - Delete (Esc d): erase right - Shift-delete (Esc D): erase line - Up (Esc j), down arrow (Esc k): previous, next command in history. If a partial line is entered, only lines containing it become visible. Previous commands are immutable; when a character is added or deleted in a previous command, this is copied to the most recent position before being modified. - Tab: autocomplete keyword or identifier. Successive tabs move forward along the list of available completions; Shift-Tab moves backwards. - Enter: submit line. - F1, Esc `: switch to full-screen mode. - F2, Esc -, Ctrl-: repeat last command. - Esc u, Esc U: Undo, respectively redo, the last modification. (Undo) - Esc \, Ctrl-\: add next (special or control) character verbatim
Page: (editor)full-screen, Next: character set, Prev: readline, Up: Top Index

Full-screen editor

The full-screen editor is accessed by pressing F1 or Esc ` or by the edit command in interactive cpl, as cpl edit in the shell, or also as edit in the shell if no other edit command takes precedence. Most used editing keys: - Left (Esc h), right arrow (Esc l): previous, next char - Home (Esc ^), End (Esc $): beginning, end of line or of selection - Ctrl-Home (Ctrl-^), Ctrl-End (Ctrl-$, Esc A): beginning, end of file - Backspace: erase left; Delete (Esc d): erase at cursor - Shift-Delete (Esc D): erase line - Up arrow (Esc j), down arrow (Esc k): previous, next line. - PgUp (Esc p), PgDn (Esc n): move to prev or next paragraph of the same or lesser indentation. - Esc f (Ctrl-f, Esc /), Esc F (Esc ?): Find forwards, respectively backwards. - Tab: autocomplete keyword or identifier. Successive tabs move forward along the list of available completions; Shift-Tab moves backwards. - Enter: Enter new line, and trigger possible autocompletion of CPL syntax - Esc =: Autoindent current line or selection (Indent and complete) - F1, Esc `: switch in and out of command-line mode. - F2, Esc -, Ctrl-: repeat last command. - Esc u, Esc U: Undo, respectively redo, the last modification. (Undo) - Esc \, Ctrl-\: add next (special or control) character verbatim. Selection is achieved by Shift-arrow keys (Select), or by moving the mouse with its left button pressed. The center mouse button copies the current selection if the mouse is moved to a new position, or deletes it if the mouse sits on it. The right mouse button moves (cuts and pastes) the current selection. Clicking the mouse on the bottom left corner, or pressing Esc followed by any unassigned key (say, Esc Space), opens up a menu of editor commands. Clicking the mouse on the bottom right corner opens context-sensitive help (through the info program), about the word where the cursor is, or this info page if the cursor is outside any word. Clicking the right mouse button does the same at the position where the mouse is clicked. The full-screen editor can work on multiple screens, in addition to the session log (command history). Simultaneously open buffers are rotated into view by clicking the mouse menu, which shows them as tabs, or by pressing Esc <digit>. A file is opened in a new screen with the edit iteractive cpl command (also available in the menu, or as Esc e, or as the edit symbolic link from a unix shell), and closed with the close menu command (aka Esc c or Ctrl-c or Esc q or Ctrl-q). Capitalized Edit, or Esc E, or right-clicking the edit menu button, opens the file to be edited in a separate terminal window. The optional +<linenumber> parameter at the end of the edit or Edit commands opens the file at the given line number. The bottom status line contains the name of the currently displayed file and the current line number. A star trailing the file name denotes whether the in-memory buffer has been modified since last saved (and warns that changes would be lost if not saved again). Closing an unsaved file elicits a prompt asking for confirmation before exit. load and save (Esc a and Esc s) respectively load (insert) a file at the current cursor position and save the current in-memory buffer to a file, with the original file name as a default. Ctrl-s immediately saves the in-memory buffer to the original file name. In case some text was just selected, Esc s instead opens a save selection as prompt which saves the current selection to a file. run (Esc r) runs the current screen as a CPL program, after saving all unsaved screens so that other possibly USEd files are up to date. By contrast, switching into line mode always runs the session log, independent of which screen is currently in view. options (Esc o) opens a menu of editor options. Most prompts and menus can be aborted by pressing Esc ∗twice∗.
Page: (editor)Select, Next: Indent and complete, Prev: full-screen, Up: full-screen Index

Select, Insert and Delete

Selection of a text area is achieved either by keeping the left mouse button pressed while sweeping, or by pressing shift together with arrow keys. Selection can apply to the text enclosed between the starting and ending selected positions or to a rectangular tile with the given corners (a.k.a. selection by columns). Esc t toggles in and out of tile mode. Esc w or double-clicking the mouse selects the word under the cursor; if applied to an opening or closing bracket, Esc w or double clicking selects the entire parenthesis. Esc # or triple clicking selects the line under the cursor. Esc s, or clicking save, when some text is selected saves the current selection rather than the entire file. When some text is selected, the character count of the selection is displayed in the status line in place of the current line number. At the same time the Home and End keys, or their equivalent command letters, lead to the begining and end of the selection. Whenever text is selected, the Insert key (or Esc i, or Ctrl-v for those who are accustomed to it) inserts (pastes) the selected text at the current cursor position; no copy operation is needed as buffer coincides with selection. The Backspace and Delete keys (also aliased to Esc d, Esc x, Ctrl-x) erase the selected text if pressed immediately after a selection. At any other time these keys erase a single character, the preceding one for Backspace. Deleted text remains buffered and can be re-inserted after its deletion. Typing a new character, or pressing Insert, immediately after a selection without any intervening cursor movement replaces the current selection. In this case the function of Insert changes to inserting the butlast selection. Esc m moves (cuts and pastes) the butlast onto the last selection. Pressing the middle mouse button achieves the same purpose as Esc i; the right mouse button the same purpose as Esc m. The CPL editor features a multiple-selection buffer: right after an insertion, pressing Esc i or Insert again replaces the current selection by the historically former selection. Pressing Esc i or Insert multiple times cycles through the last three selections. In case you want to insert the same selection more than once, exit Esc mode or press End in between. In the way of example, in order to: delete: select, delete; overtype: select, type; copy and paste: select, move cursor, insert; cut and paste: select, delete, move cursor, insert; copy and replace: select, move, select, insert; cut and replace: select, delete, move, select, insert. type again: type something, move, insert; type and replace: type something, move, select, insert. insert the former selection: select, move, select, move, insert, insert. If so many rules look complicated, just remember that you can recall and insert anything that you have recently selected, written or deleted; just try pressing Insert, and if what you see is not what you want, press Insert again. The copy-and-paste functionality of the underlying xterm-compatible terminal is also available, and necessary if you want to copy some text to/from other windows. This is accessed by pressing Shift together with the corresponding mouse button (left button to select, center button to paste). Shift-Insert also pastes from the clipboard at the current cursor position. Notice that when the editor is run remotely, involved is the one of the two clipboards that resides on the machine where the terminal is running, which probably is what you want anyway. In addition, if the xsel program is installed, Esc ' copies the current selection to the clipboard (on the remote machine, unfortunately, when not the same; for those who know, this feature to be done properly would require OSC 52 support; writing only would be enough). Esc !, respectively Esc @, turns the current selection to all uppercase or to all lowercase letters.
Page: (editor)Indent and complete, Next: Find, Prev: Select, Up: full-screen Index

CPL syntax-sensitive indentation and completion

When a .cpl file is being edited, pressing Enter at the end of a freshly modified line automatically: 1) indents the new line according to the contents of the previous line; 2) if the line is the opening of a new program block, like a SUBROUTINE, LOOP or IF statement, it inserts the corresponding closing statement and the appropriate indentation for the block's contents; 3) it converts to upper case some CPL keywords when they are recognized as having been entered in lower case; 4) open brackets are automatically provided with a matching closing bracket; typing of the closing bracket is optional, and silently ignored if brackets match; 5) since CPL allows the usage of the three kinds of brackets like in mathematics ((cpl)Parentheses), the editor automatically alternates the three kinds even if only one kind is typed in. Where needed, the following explicit indentation commands are available: Esc ) : indent the current selection one more space to the right, Esc ( : unindent the current selection by one space to the left, Esc = : even the margin of the current selection, or indent as to CPL syntax. In addition, word completion using the Tab key is available in full-screen just as well as in readline mode. Successive tabs move forward along the list of available completions; Shift-Tab moves backwards. A hint is shown under the cursor at the end of the current line, foreshowing in faint type the completion that pressing Tab would currently produce. Parentheses and quote completion also operates, automatically adding closed parentheses and quotes at the time they are opened.
Page: (editor)Find, Next: Undo, Prev: Select, Up: full-screen Index

Find and replace

find (Esc f or Ctrl-f or Esc /) and goto (Esc g or Esc +) seek the cursor to a given string or to a given line number. Esc F (or Esc ?, or clicking find with the right mouse button) seeks backwards. The search is caseinsensitive if the first character of the search string is a lowercase letter, case-sensitive otherwise. The found string is automatically selected. Esc , (lowercase <) repeats the last find backwards. Esc . (lowercase >) repeats the last find forwards. Finding with an empty argument also repeats the last find, possibly changing its direction. If some text is selected when one of this keys is pressed, the selected text will be searched. In order to find and replace, find a given text, exit Esc mode, and start typing the replacement. Just typed text automatically goes to the insertion buffer; therefore after you search again, pressing Insert will insert the same replacement. Esc > is a shortcut for pressing Insert and Esc . one after the other, and thus serves as replace-and-find-again. Keeping Esc > pressed is a means to perform multiple replacements, possibly to the end of file. Esc < likewise replaces-and-finds backwards. Esc Enter repeats the most recent command, for instance the last (forward or backward) find or the last replace-and-find-again.
Page: (editor)Undo, Prev: Find, Next: options, Up: full-screen Index

Undo and redo

Unlimited undo and redo functionality is supported, activated by Esc u and Esc U respectively (or Esc z and Esc Z as alternates, or Ctrl-z and Ctrl-y, but with the variation detailed below). As a distinctive feature of this editor (shared by emacs, with some distinctions, but almost no others), memory of the undone edits is retained even when further edits take place after an undo. A standard editor allows the following pitfall to occur: you undo several times with the purpose of inspecting how your text was at an earlier stage, but with the intention to return to the present, and then before redo-ing, you accidentally hit a key (for example, redo is Ctrl-y and you hit y without Ctrl); now your redo buffer is gone forever, and all you typed in the meanwhile is gone with it. Emacs and its kin keep memory of the complete history of commands including undo's. You do not redo in emacs, you undo an undo. You never lose anything, if no cap is posed on the length of the history, but once you start to undo an undo an undo the interface may become confusing, and the distance to any given past command increases rapidly. In the CPL editor you can think of undo and redo commands as not changing anything, just scrolling backwards and forwards along what you did before. It is when you start typing again (or save) that actual changes take place, and they are recorded with no loss. The next time you undo, you will roll back the time series of changes without again seeing your past undo's, and roll forward when you redo. If you redo all the way to the present nothing is remembered, but otherwise the state of the document when you resume typing is. Save for undo's and redo's, and for characters corrected with backspace immediately after being written, the complete history of changes since the file was opened remains available, and is never overwritten when you resume editing after undoing your previous edits. Its lifespan is, nevertheless, finite and coincides with the editing session; contrary to full-fledged version-control systems, no history is preserved after the file is closed. For added flexibility, Esc z or Ctrl-z provides the traditional undo with no repetition of previously undone edits, while Esc u or Ctrl-u provides the full undo. History is not lost with either, and redo is always full. Multi-line movements (PgUp, PgDn, Ctrl-Home, Ctrl-End, find and go to line) can also be undone, using the Esc b (back) key. Memory is only kept up to the most recent text modification. Esc U, Esc Z, Esc B and Ctrl-y redo (reverse undo) whatever was undone interchangeably.
Page: (editor)options, Prev: Undo, Next: character set, Up: full-screen Index

Editor options

options (Esc o) opens a submenu of editor options. Lines can be selected by up and down arrows or by the mouse, and activated/deactivated by pressing y or left arrow for yes, or n or right arrow for no, or toggled by the space bar. Enter exits the menu. As a quick shortcut, the initial of each option toggles it and exits the menu at once.
Page: (editor)hex editor, Prev: options, Next: character set, Up: options Index

Hex editor mode

The show bytes option toggles hex editor mode. In this mode individual bytes are displayed (non-printing ones as □), instead of being interpreted as UTF-8 Unicode, and at the same time a sliding window shows the hex representation of the line under the cursor. Typing in hexadecimal digits modifies the byte under the cursor. Space adds a new byte. Other alphanumeric keys are inactive.
Page: (editor)character set, Prev: full-screen, Up: Top Index

Character set

The cpl editor is 8-bit safe, and correctly aligns UTF-8 Unicode characters displayed by the underlying console. Double-width Unicode characters are handled as well. The hex representation of a binary file can be obtained, if desired, by turning on the hex editor.