Home Page The Club Computers News Links Glossary EYAWTK
Before Amiga Background ICS OCS ECS AGA ??? PPC
U-Boot SLB Linux Amiga OS Dual Boot Motherboards Peripherals Other
Initialisation Installation OS4 Updates About OS4 File Systems Networking Printing Other
Introduction File System Workbench Preferences Commands Error Msgs Miscellaneous

AmigaOS 4.0 - About OS4 - Commands

MEMACS Tool
Purpose: Enables screen-oriented text editing.
Format: MEMACS [<filename>] [OPT W] [GOTO <n>]
Template: FROM/M, OPT/K, GOTO/K
Path: SYS:Tools/MEmacs
MEmacs (MicroEmacs) is a screen-oriented text editor with which you can edit multiple files at the same time. MEmacs is similar to the UNIX-based Emacs editor, and performs all operations on the memory-resident text, requiring that entire text files be able to fit in memory at once.

Line length, generally 80 characters long, (but 114 characters using 800x600 and more at higher resolutions) is limited to the right hand edge of the screen. You can enter characters beyond the limit, but they are not displayed, unless you break the line or delete some of the displayed characters. A dollar sign ($) at the right edge of the screen indicates that there are characters beyond what is displayed.

The <filename> argument is optional; if not specified it assumes you are opening a new file. Also, if the name specified does not previously exist, a new file will be created.

The OPT W argument specifies that you want to open MEmacs in a Workbench window rather than on its own screen, which can save memory.

The GOTO <n> argument specifies the line on which the cursor is to appear when the file is opened.

The following shows the MEmacs opening screen:

The line at the bottom of the screen identifies either the current file name or the name of the current buffer, if no file name is specified. Command arguments are also entered on this line.

Several buffers can be in use at the same time and one or more can be displayed on the screen simultaneously. Menu options switch between them. At all times, the screen displays what is actually in the buffer.

MEmacs has two conditions of operation:
Normal When you enter and manipulate text directly in the file without special functions.
Command When you enter a command through a menu selection or the keyboard shortcut for it. In the command condition, the cursor jumps to the bottom line of the display and waits for you to supply additional information following the prompt. You cannot return to the normal condition until you satisfy or cancel the command by pressing Return.

In the MEmacs normal condition, you can:

  • Move the cursor using the arrow keys.
  • Move the cursor to the edge of the window by holding down Shift and pressing the appropriate arrow key.
  • Move the cursor by clicking the left mouse button at the desired place on the screen.
  • Insert characters at the current cursor position by typing them.
  • Delete the character at the current cursor position by pressing Del or Delete.
  • Delete the character to the left of the cursor by pressing Backspace.
  • Perform other special menu and command functions.
When using MEmacs, you should be familiar with the following special terms:

Buffer A memory area that MEmacs controls. There is always at least one buffer used by MEmacs containing zero or more text characters.
Dot The current cursor position.
Mark A specified cursor position. (Each buffer has it own Dot and Mark.) The Set-mark menu item marks the current cursor position. You can move forward or backward in the file, adding or deleting text. To return to the Marked place, select the Swap-dot&mark menu item. You can also set a Mark to indicate the beginning of a block of text that you want to duplicate, move or delete. The block encompasses all of the characters starting with the Mark and continuing to the current cursor position.
Kill Kill commands remove text from the screen to save in a Kill buffer. This text can be retrieved and inserted into your document by using the Yank command. Issuing successive Kill commands (without selecting Yank in between) adds each block of text to the existing text in the Kill buffer. If you select Yank, the next block of Killed text overwrites the current block.
Window MEmacs screens can be split into multiple layers for editing and displaying more than one buffer or two or more portions of the same buffer. Each layer is a MEmacs window.
Modified Buffers Buffers are marked as modified when any changes are made. The modified status is removed when the buffer is saved. To see modified buffers, use the List-buffers command; modified buffers are identified with an asterisk (*). If you exit MEmacs without saving any changes, a prompt tells you that modified buffers exist and asks if you really want to quit.

Menu Commands
MEmacs has the following menus:
Project Contains system and file-oriented items.
Edit Contains buffer editing commands.
Window Controls the characteristics of the MEmacs windows.
Move Controls the placement of the cursor.
Line Controls line-oriented operations.
Word Controls word-oriented operations.
Search Controls search and search/replace options.
Extras Controls the numerical value of arguments and enables you to execute a series of operations as though it were a single special command.

The following sections describe each of the menus in detail and show the keyboard shortcut key combinations for each menu item, e.g. Ctrl+X A which is interpreted as pressing the Ctrl key and 'X' together and then pressing the 'A' key by itself, or Esc A which is interpreted as pressing the Esc key followed by the 'A' key. In some cases more than one keyboard shortcut may be shown on consecutive lines.

Project Menu
The commands in the Project Menu, except for Visit-file, affect the buffer associated with the current cursor position.

Rename Ctrl+X F Changes the name of the file associated with the current buffer. Pressing Return without specifying a file name disassociates the buffer from any file.
Read-file Ctrl+X Ctrl+R Replaces the contents of the current buffer with the contents of the file. Enter a complete file path. Press return without specifying a file name to ignore the request and return to normal mode.
Visit-file Ctrl+X Ctrl+V Enables you to work with additional files other than the one you are currently editing. Enter the complete path.
Insert-file Ctrl+X Ctrl+I Inserts the contents of a file into the current buffer at a point one line above the current cursor position. Enter the complete file path.
Save-file Ctrl+X Ctrl+S Writes the contents of the current buffer to the file name associated with that buffer. Displays the file's line count following a successful save. MEmacs does not save the file if no name is provided; instead it displays an error message: 'No file name'.
Save-as-file Ctrl+X Ctrl+W Enables you to specify the name and path of a file associated with a buffer.
Save-mod Ctrl+X Ctrl+M Writes the contents of all modified buffers to the disk. Do not accidentally modify a buffer that you did not intend to change.
Save-exit Ctrl+X Ctrl+F Saves all modified buffers and exits MEmacs.
New-Cli Ctrl+ - Opens a new Shell window known as a Spawn Window. Enter AmigaDOS commands in the Spawn Window without interfering with MEmacs. Close the window with ENDSHELL.
Cli-Command Ctrl+X ! Enables you execute an AmigaDOS command while in MEmacs. Enter a command following the ! prompt at the bottom of the screen. Command output is placed in the spawn.output buffer.
Quit Ctrl+C
Ctrl+X Ctrl+C
Esc Ctrl+C
Exits MEmacs. You are given an opportunity to save modified buffers or quit without saving.
About... Displays program copyright information.

Edit Menu
The commands in the Edit Menu affect the editing of your buffers and their associated files.

Kill-region Ctrl+W Deletes blocks of text from the current buffer and saves them in a kill buffer. Text can be retrieved with the Yank command. Make copies of a block by immediately selecting Yank without changing the cursor position after killing the block. This restores the block to its position and leaves a copy in the kill buffer.
Yank Ctrl+Y Copies the contents of the kill buffer to the current cursor location on the current line. Reverses the action of Kill-region without changing the contents of the kill buffer. Used with Kill-region for moving text or for repeatedly copying a single block of text.
Set-mark Ctrl+@
Esc -
Marks the cursor position in a buffer. The subsequent cursor position is referred to as a Dot. Move between the Mark and the Dot using the Swap-dot&mark command in the Move menu. Used for marking blocks of text.
Copy-region Esc W Copies the contents of the marked region to the kill buffer without deleting it, replacing any previous contents.
Upper-region Ctrl+X Ctrl+U Changes the text of the entire marked region to upper case.
Lower-region Ctrl+X Ctrl+L Changes the text of the entire marked region to lower case.
List-buffers Ctrl+X Ctrl+B Splits the current buffer's window and displays a list of the buffers MEmacs is maintaining. To redisplay the current buffer, select the One-window command or press Ctrl+X 1. The List-buffer fields are:
C Displays an asterisk if the buffer has been modified since it was last saved to a file (Stands for Changed.)
Size Shows how many characters are in the buffer.
Buffer Shows the name given to the buffer. If you read in a file, this is the name of the file without the full path.
File Shows the full path to the file. This is the file to which MEmacs writes the buffer if you Save-file or Save-exit while the cursor is in that buffer.
Select-buffer Ctrl+X B Enables you to select the buffer to edit in the current window. Replaces the contents of the window with the selected buffer or new buffer.
Insert-buffer Esc Ctrl+Y Inserts the contents of a named buffer into the current buffer at the line above the current cursor position.
Kill-buffer Ctrl+X K Deletes the contents of one or more chosen buffers, returning the memory to the memory manager to reuse. You must specify the buffer to be deleted; a buffer cannot be killed if its contents are currently displayed.
Justify-buffer Ctrl+X J Removes all blank spaces and tabs from the left edge of all lines in the current buffer. The text realigns with the current margins.
Redisplay Ctrl+L Redraws the screen.
Quote-char Ctrl+Q
Ctrl+X Q
Enables insertion of any literal character in the text file except the Tab key.
Indent Ctrl+J Moves the cursor to the next line, automatically indenting by the same number of spaces as the previous line.
Transpose Ctrl+T Swaps the positions of two adjacent characters. Place the cursor on the rightmost of the two characters and execute the command.
Cancel Ctrl+G Ends an ongoing menu command, such as query search and replace.

Window Menu
The Window Menu controls how to view buffers on the screen.

One-window Ctrl+X 1 Makes the current buffer a single, full-sized window on the MEmacs screen.
Split-window Ctrl+X 2 Splits the current window in half, positioning the current buffer identically in both windows. Any changes you make in either window affect the whole buffer.
Next-window Ctrl+X N Moves the cursor to the next window and makes that window available for editing.
Prev-window Ctrl+X P Moves the cursor to the previous window and makes that window available for editing.
Expand-window Ctrl+X Z Adds a line to the height of the current window and simultaneously subtracts a line from the height of the adjacent window.
Shrink-window Ctrl+X Ctrl+Z Subtracts a line from the height of the current window and simultaneously adds a line to the height of the adjacent window.
Next-w-page Esc Ctrl+V Displays the next page of the adjacent window. This does not make the window available for editing.
Prev-w-page Ctrl+X V Displays the previous page of the adjacent window. If only one window is displayed, it displays the previous page of that window.

Move Menu
These commands move the cursor rapidly through the current buffer.

Top-of-buffer Esc < Moves the cursor to the top line of the current buffer.
End-of-buffer Esc > Moves the cursor to the bottom line of the current buffer.
Top-of-window Esc , Moves the cursor to the top of the current window.
End-of-window Esc . Moves the cursor to the bottom of the current window.
Goto-line Ctrl+X Ctrl+G Moves the cursor to a specified line number. Specifying a line number larger than the total number of lines in a buffer moves the cursor to the last line of the buffer.
Swap-dot&mark Ctrl+X Ctrl+X Marks the current cursor position (Dot) and moves the cursor to the previously marked setting.
Next-page Ctrl+V Moves the cursor towards the end of the current buffer by one full window, less one line.
Prev-page Esc V Moves the cursor towards the beginning of the current buffer by one full window, less one line.
Next-word Esc F Moves the cursor forward to the next non-alphabetic character, such as a space or punctuation mark, following the current word.
Previous-word Esc B Moves the cursor back to the first letter of the previous word.
Scroll-up Crtl+Z Moves the text up one line.
Scroll-down Esc Z Moves the text down one line.

Line Menu
These commands move the cursor within or between lines and perform operations involving entire lines.

Open-line Ctrl+O Splits the line containing the cursor, forcing the character at the current cursor position to become the first character of the following line. The cursor remains on the original line. Pressing the Del or Delete key cancels an accidental Open-line.
Kill-line Ctrl+X Ctrl+D Deletes the line containing the cursor and places the text in the kill buffer.
Kill-to-eol Ctrl+K Deletes the text between the current cursor position and the end of the line, and places the text in the kill buffer.
Start-of-line Ctrl+A Moves the cursor to the first position on a line.
End-of-line Ctrl+E Moves the cursor to the last position on a line.
Next-line Ctrl+N Moves the cursor down one line.
Previous-line Ctrl+P Moves the cursor up one line.
Line-to-top Esc ! Moves the line containing the cursor to the top of the window.
Delete-blanks Ctrl+X Ctrl+O Deletes blank lines, proceeding forward form the current cursor position until MEmacs reaches the next line on which there is text. Does not delete single blank lines.
Show-line# Ctrl+X = Displays information on the present cursor position.

Word Menu
The Word Menu contains word associated operations.

Delete-forw Esc D Deletes the character on which the cursor is positioned and allremaining characters to the right until the next non-alphanumeric character is found, such as a blank space, tab, or punctuation.
Delete-back Esc H
Esc Del
Esc Delete
Deletes all characters to the left of the cursor until it finds the first character of a word. The character at the current curosr position is not deleted.
Upper-word Esc U Changes a word to upper-case, starting at the current cursor position, and proceeding to the last character of the word.
Lower-word Esc L Changes a word to lower-case, starting at the current cursor position, and proceeding to the last character of the word.
Cap-word Esc C Changes the character at the current cursor position to upper-case. Also changes the characters to the right of the cursor, up to the end of the word, to lower-case.
Switch-case Esc ^ Changes the case of a word, starting at the current cursor position and proceeding to the right until it reaches the end of the word. If a word is upper-case or has mixed-case text, it changes upper-case to lowr-case and vice-versa.

Search Menu
These commands search through the current buffer for specific text strings. The case (upper or lower) of the string is not significant in the search unless the Set Case command has been specified previously. However, if you are using text substitution (search and replace), the text is replaced in the case of the replacement string.

Search-forward Ctrl+S
Ctrl+X S
Searches through the text starting at the current cursor position and moving forward to the end of the buffer. At the 'Search:' prompt, enter the character string for the search.
Search-backward Ctrl+R
Ctrl+X R
Searches through the text starting at the current cursor position and moving backward to the beginning of the buffer. At the 'Search:' prompt, enter the character string for the search.
Search-replace Esc R Searches the same as Search-forward, allowing you to replace the string with different text. At the 'Search:' prompt, enter the character string for the search, and at the 'Replace:' prompt, enter the replacement string of characters. On completion it will display how many matching occurences were replaced.
Query-s-r Esc Q Operates the same as Search-replace, except it asks for confirmation to replace each time it finds the specified string. The options are Y (yes), N (no), C (change all occurrences), and Ctrl+G (abort).
Fence-match Esc Ctrl+F Finds the closest occurrence of the fence character to match the one at the current cursor position. Fence characters are parenthesis, brackets, braces and angle brackets.

Extras Menu
These commands are MEmacs operational commands and macro commands. Specific numeric arguments may be required before selecting a command; an * indicates that an argument is required. Macro commands are executed by selecting the Execute-macro menu item.

Set-arg Ctrl+U Enables you to specify a numeric argument for a command. When you issue this command, MEmacs prompts:
Arg: 4
If you select Set-arg again, MEmacs multiplies he argument value by 4, for example:
Arg: 16
If you press a numeric key (0-9), MEmacs accepts an integer argument, for example:
Arg: 1    (after first key pressed)
Arg: 12   (after second key pressed)
If you press a minus sign first, MEmacs accepts a negative integer argument, for example:
Arg: -3    (after first key pressed)
Arg: -34   (after second key pressed)
MEmacs uses the argument value as a key for whatever you do next. To add 20 lines at the current cursor position specify an argument of 20, then press Return.

To set one of the MEmacs operational parameters (described later) select the value of the argument (do not press Return) then select the appropriate menu item or shortcut key combination. MEmacs will use the argument to set the value.

If the command does not support parameters, MEmacs executes the command the specified number of times. For example, to add 10 minus signs, select an argument number of 10 (do not press Return) then press the minus sign on the keyboard. Do not use the keypad's minus sign because it is mapped to a different value.

Set Esc S Lets you set the following MEmacs parameters:
Screen Places the MEmacs display in a Workbench window or back onto a custom screen.
Interlace Turns the interlace mode on or off.
Mode Results in a second prompt "Mode:"; you can enter Cmode (for editing C programs) or Wrap (to enable automatic word-wrap when the text reaches a set cursor position). Cmode provides automatic fence matching. Use +mode or -mode to add or subtract a mode.
Left Determines the left margin. Prompts for a numerical argument if not provided with the entry.
Right Determines the right margin. Prompts for a numerical argument if not provided with the entry.
Tab Sets the increment for tab spacing. Prompts for a numerical argument if not provided with the entry.
Indent Determines how far to indent each level of nesting (used in Cmode). Prompts for a numerical argument if not provided with the entry.
Case Turns case-sensitive searches on or off; default is off.
Backup Turns the MEmacs backup function on or off. Your options are:
ON (renames the current file <filename>.bak and saves that backup file to the T: directory);
SAFE (this option checks to see if a file already exists for the buffer - if so it displays an error and does not overwrite the existing file, Ctrl+X clears the display);
OFF (this is the default option - MEmacs does not perform any backup).
Start-macro Ctrl+X, ( Tells MEmacs to start recording any subsequent keystrokes. Used with the Stop-macro and Execute-macro commands.
Stop-macro Ctrl+X ) Tell MEmacs to stop recording keystoked.
Execute-macro Ctrl+X E Repeats keystrokes that were entered between Start-macro and Stop-macro.
Set-key Ctrl+X Ctrl+K Enables you to redefine all of the function keys, the Shifted function keys, the Help (Scroll Lock) key, or any key on the numeric keypad as keyboard macros. You cannot use the menu shortcut of Ctrl+@ to insert the Set-mark command into any keyboard macro definitions.
Reset-keys Esc K Returns any keys defined by Set-key to their original default state.
Execute-file Esc E Enables you to execute a program file within MEmacs.
Execute-line Ctrl+[ Ctrl+[
Esc Esc
Set MEmacs to command mode. At the prompt enter any menu command and its parameters.

The following table contains the default values of the Set-key/function keys when used in macro commands:

F1 Clone line Ctrl+A Ctrl+K Ctrl+Y Ctrl+M Ctrl+Y
F2 Delete line Ctrl+X Ctrl+D
F3 Execute keyboard macro Ctrl+X E
F4 Next screen Ctrl+V
F5 Previous screen Esc V
F6 Split window Ctrl+X 2
F7 One window Ctrl+X 1
F8 Scroll window up Ctrl+Z
F9 Scroll window down Esc Z
F10 Save file and exit Ctrl+X Ctrl+F
Help (Scroll Lock) Insert line Ctrl+J
Enter on Keypad Insert line Ctrl+J

Commands Not In Menus
The following commands are only accessible through the keyboard.

Keys are bound when they can be used to perform a function. For example, any key or key sequence that can be used as a shortcut for a menu item is bound to that menu item.

Describe Key Esc Ctrl+D Tells you if any functions are bound to a key or key sequence. At the prompt enter the specific key or key sequence.
Bind Key Esc Ctrl+B Enables you to bind to a key or key sequence to a function. At the prompt enter the key or key sequence.
Unbind Key Esc Ctrl+U Enables you to return a bound key to an unbound state. At the prompt enter the specific key or key sequence. Standard bound keys cannot be unbound.
Echo Esc Ctrl+E Displays the string entered in the command line.
Move to Edge of Window Shift+Arrow Moves the cursor to the top, bottom, left, or right edge of the screen.
Delete the Next Character Ctrl+D Deletes the character at the current cursor position. Same as pressing Del or Delete.
Delete the Previous Character Ctrl+H Deletes the character to the left of the current cursor position. Same as pressing Backspace.
Move to Next Line Ctrl+M Inserts a newline character after the current cursor position and moves the cursor to the start of the new line.
Move x number of Characters Forward Ctrl+U x Ctrl+F Enables you to move the cursor forward a specified number of characters. If no value is specified for 'x' the cursor moves forward 4 characters.
Move x number of Characters Backward Ctrl+U x Ctrl+B Enables you to move the cursor backward a specified number of characters. If no value is specified for 'x' the cursor moves backward 4 characters.

Customising MEmacs
The following commands are only accessible through the keyboard.

MEmacs looks for an Emacs_pro file when it is opened to see if there are any commands or local files that it should automatically execute. You can customise the Emacs_pro file by adding commands to it that you use often, command sequences, or text strings. If an Emacs_pro file does not already exist you can create one.

To create a global file of commands, place the Emacs_pro file in the S: directory.

Previous versions of MEmacs could also use local files that could be put in any directory. If that directory was the current directory when MEmacs is opened, the commands in that particular local file would be executed. When both local and global Emacs_pro files were present, the local file overrode the global file. However, this aspect appears to have been removed from the version available with AmigaOS 4.0.

Setting up the Emacs_pro file can also be a little confusing when using a standard PC keyboard with 12 Function keys, as MEmacs only expects to find 10 Function keys, so F11 is interpreted as Shift+F1 rather than the F11 key, for example:

Set Case On
Set-Key F11 "Dear Sirs:"
Set-Key F12 "^S Workbench"
Set-Key F13 "^X^B"
makes the following assignments:

Shift+F1 Enters the text string "Dear Sirs:"
Shift+F2 Search forward for the next occurrence of the word Workbench. (The Set Case On command makes any text searches case-sensitive.)
Shift+F3 Displays the list of buffers

You must use Ctrl+Q to enter a Ctrl+key sequence. For example, to enter the ^S character shown in the example above, press Ctrl+Q followed by Ctrl+S.

Quitting MEmacs
You can exit MEmacs by selecting the Quit menu item in the Project menu or by entereing Ctrl+C. MEmacs lets you save any modified buffers or quit without saving.

Example 1:

3.OS4:> MEMACS mytext starts up MEMACS on its own screen and loads the text file mytext into a buffer for editing.

Example 2:

3.OS4:> MEMACS mytext OPT W GOTO 1000 starts up MEMACS in a Workbench window and loads the file mytext into a buffer for editing and positions the cursor at line 1000.

See Also: ED, EDIT, Notepad


Return to Commands Selection

Disclaimer: Amiga Auckland have prepared the above information for the use of its members based on our experiences and as such is subject to revision at any time. Amiga Auckland cannot guarantee any of the information and cannot be held accountable for any issues that may result from using it.


Copyright 2006 Amiga Auckland Inc. All rights reserved.
Revised: February 9, 2006.