This library enhances the built-in editor of the HP49G with features known from famous GNU Emacs editor. You will find things like dynamic or table guided completion, incremental search, regular expressions, folding, macro recording, programming language support (RPL and ML) and extensibility (write you own editor commands).
This library is copyright
and may be distributed freely, provided that this copyright notice remains unchanged and is distributed with the program. We are not responsible for whatever this program does to your calculator. Back up your RAM.
COMMANDS IN THE EMACS APPLICATION MENU
Page 1: General editing commands
Page 2: SysRPL and ML programming
Library |
HP49G |
hp49g+ |
Main library |
Use EMACS.49G and install normally. |
Use EMACS.49GP and install normally. |
Stack diagram display In order to display stack diagrams, you need a version of the SDIAG library. |
On the HP49G, all the stack diagrams are part of a (very large) library. Use SDIAG.49G and install normally |
On the hp49g+, the SDIAG library is small. It accesses data from a special directory on the SD card. Use the library SDIAG.49GP and install it normally. Then use an SD card reader (no, you cannot do this via the USB connection) and copy the entire directory SDIAG unchanged into the root directory on the SD-card |
If you’d like to program in SystemRPL and/or ML, you need a version of the EXTABLE library. You can get one from HP and from www.hpcalc.org. You can also use the extended version extable2.lib included in the emacs distribution. |
Use extable.lib or extable2.lib and install it normally. If attaching the library fails, try installing it through the Filer with Move. |
|
For decompiling code, you need either Nosy of CQIF?, available from www.hpcalc.org |
Download and install the library you want to use. Nosy is recommended. If you use CQIF?, you also need to configure Emacs to use it, see below under Confg.EMACS. |
|
If you’d like Emacs to be able to edit BZ compressed files and to recompress those files after editing, you need the OT49 library, available from www.hpcalc.org |
Get OT49 and install it normally. |
Get OT49+ and install it normally. |
Library Menu |
The menu which you get with <<1790 TMENU>>. In contrast to many other libraries, this menu is hardly ever used, except when making a program involving Emacs commands. |
Application |
The menu which comes up when you launch RPLED. This is a 3 page Menu where all menu keys (unshifted, left- and right shifted) provide access to most Emacs commands. |
Default mode |
The normal operating mode of the calculator, with the stack visible on the scree. |
In the editor |
The HP49G editor is the editing environment that is entered by typing numbers and text into the command line, by editing an object using DOWNARROW or by using a command like INPUT or InputLine. |
MASD files |
When developing SysRPL or ML code, you are working with MASD source files. These files contain a "@" as the last character. Emacs sees this character and behaves differently. For example, RPLCPL completes UserRPL commands in the command line, but SysRPL/ML entry names in MASD source files. |
Selection: |
The text between the BEGIN and the END marker. The HP49G displays this text inverted. Several commands in Emacs act on the current selection, but only if the cursor is inside or next to the selection. This is a precaution since some commands like searching leave small selections in the buffer which you may not be aware of when you execute a command. If not at a selection, these commands act either on the whole file or on the current line. |
Long: |
Several commands behave slightly different when you press the key invoking them slightly LONGER than normal, similar to KEYMAN's IfL assignments. This models the behavior of "prefix arguments" in the real "GNU Emacs". In this library, LONG usually means "more detailed" or "deeper". |
LEFTSHIFT: |
Indicates the menu key function when pressed with leftshift. Shifted menu keys execute commands which are related to the unshifted keys. |
RIGHTSHIFT: |
Indicates the menu key function when pressed with rightshift. |
UP LEFT RIGHT DOWN: |
The arrow keys. |
In general you should not use the EMACS
library menu to access the commands. Instead, assign RPLED to a key as shown
below and use the application menu installed by this command. We also recommend
assigning RPLCPL to keys both with and without alpha mode, since you will be
using this command a lot. You may want to assign other commands as well if you
find you need them all the time.
An easy way to make several useful key
assignments is to
- use the APPS key
- select the "Emacs" entry
- press the "AsnEmacs" menu key
- press OK.
This will produce the following key assignments (the "&" means that you need to hold the Shift key):
|
|
Key |
Assignment |
also in ALPHA mode? |
RightShift |
& |
DOWN |
RPLED |
No |
RightShift |
& |
RIGHT |
RPLCPL |
Yes |
LeftShift |
& |
RIGHT |
DYNCPL |
Yes |
RightShift |
& |
UP |
SDIAG |
Yes |
LeftShift |
& |
UP (with longpress) |
EDOB |
Yes |
RightShift |
& |
. |
NL&IND |
Yes |
RightShift |
& |
| |
|
Yes |
If you don't like any of these assignments,
you will have to do the ones you want yourself. Let's say you'd like
- RPLED on RightShift&DOWN
- RPLCPL on RightShift&RIGHT
- DYNCPL on LeftShift&RIGHT
With Wolfgang Rautenberg's KEYMAN, the
following keys will make these assignments. Note that we want to keep Kermit
SERVER program on RightShift&RIGHT outside the editor. In the following,
'→TO', '
\<<
RPLED \>> ENTER →TO A?D LeftShift&DOWN
\<< RPLCPL \>> \<< SERVER\>> ENTER
\<< DYNCPL \\> ENTER →TO DUP A?D LeftShift&RIGHT A?D ALPHA LeftShift&RIGHT
The last two assignments are duplicated for
normal and ALPHA mode, so that you don't need to leave ALPHA mode for
completion.
RPLED |
When called from within the editor, brings up the EMACS menu. This works no matter how you entered the editor (DOWN, INPUT, InputLine, whatever). The menu also contains the additions you may have defined with the "emacs" variable, see below. When called in Default mode, RPLED is a shell around the editor which behaves much like the Jazz editor ED. It decompiles the object on level 1 and edits the resulting string. If the stack is empty, or if you press the key invoking RPLED long, an empty ":: ;" template is pushed on the stack and then edited. The editor comes up with the application menu. When you exit the editor with ENTER, things depend on how you started RPLED. If you are editing a string, the changed string is put on the stack. If you are editing an object (which was decompiled for editing), the source code is compiled back into an object. If there is an error in the object source, the error is shown and you return to error position in the editor. A slightly longer press on the ENTER key will give you a choice whether to compile the source/string or not. RPLED can also detect BZ strings and self-expanding BZ objects (programs, not code). If the corresponding configuration option is turned on, such compressed files will be transparently expanded before and recompressed after editing. |
||||||||||||||||
Confg.EMACS |
Configure various aspects of Emacs/RPLED. Also available with RightShift Help Confg from inside the Editor. This command shows an InputForm with the following settings.
|
DCO.. <<DYNCPL>> (LS CO..) |
Completion based on … |
CO.. |
What is completed on the command line (UserRPL)?
|
||||||||||||||||||||||||||||
DCO..(LS CO..) << DYNCPL >>
|
Completion based on the words present in the file being edited. It is called "dynamic" because it adapts to contents of the current file. The interface is different from RPLCPL. If you complete on "fl", DYNCPL searches backwards through the current file to find other words which start with "fl" as well and immediately inserts the first match. It highlights the part of the word you had typed. If you don't like that particular match, press again THE SAME KEY which invoked DYNCPL, and it will search for further matches. "ON" aborts, "ENTER" accepts the current match, and all other keys accept the match and execute the key. Most of the time, you will press SPC or NEWLINE after completion. If you press DCO.. long, dynamic completion will ignore any leading `=', `*', `!' in both the current word and any possible matches. This is nice for completing labels in ML and local variables in SysRPL. Examples for LONG-Touch application:
|
||||||||||||||||||||||||||||
MSG..(RS CO..) |
Message number retrieval. This command helps to find the access bint of built-in messages in the calculator. It prompts for a search string and matches it against all messages on the calculator. The matches are offered in a choose box. Select a message and the corresponding message number will be inserted into the editor, ready for JstGETTHEMSG etc. Using #nnn JstGETTHEMSG instead of a string generally saves a lot of bytes. Pressing this key long will access the list stored in $MESSAGE instead, so this can be used to get message numbers while writing a new library. The number inserted into the editor will not contain the library number, assuming that the library handles messages with a special rompointer which adds the library number before calling JstGETTHEMSG or DO#EXIT. |
||||||||||||||||||||||||||||
SetMk(LS GoMk) |
Prompts for a mark number (1-3) and saves the position and 3 lines of context in the hidden directory (EMC.mrk). Therefore, these marks survive exiting the editor and can be used when you re-edit the file. Note that they take up permanent storage space, so you should use not too may different marks or purge the variable occasionally (see Confg.EMACS). |
||||||||||||||||||||||||||||
GoMk(Mark) |
Prompts for a mark number (1-3) and jumps to the position where this mark was set. Searches for the saved context (3 lines) and goes to the match closest to the old position. When the context cannot be found (because it was changed), jumps to the old character position. |
||||||||||||||||||||||||||||
GoToLbl(RS GoMk) |
Offers CHOOSE box with the labels in the
edited file and jumps to the selected label. Unlike the built-in GOTOLABEL
command, this ignores lines with space between the "*" and the
text. So it will find "* |
||||||||||||||||||||||||||||
<< MPLAY >> |
Execute the previously recorded key macro, see MREC below. Example: How to put a "*" in the first column of several lines. Put the cursor at the beginning of the first line. Then press:
The first line now carries the star, the cursor is in the second line. Now press |> a few times to execute the macro. Hold the key down to automatically repeat. Want to do it for exactly 33 lines? Press RightShift |> 33 ENTER |> |
||||||||||||||||||||||||||||
MREC(LS |>) |
Start recording a macro key sequence. This command records several key presses into a macro which you then can execute as one command. Pressing "ON" terminates the recording. The keyboard macro is stored in a variable in the hidden directory and therefore preserved between editing sessions. In order to free up the space taken by a macro, purge the hidden variables (see Config) or record an empty macro with MREC ON/CANCL. |
||||||||||||||||||||||||||||
ARG?(RS |>) |
Repetition factor for the following command. Enter a number N and press ENTER. The next key you press will be executed N times. For example 'ARG? 5 ENTER A' will insert "AAAAA" into the editor. |
||||||||||||||||||||||||||||
Find<< IFIND >> |
Find searches the command-line for a string and is generally much faster to use then the built-in SEARCH. The search starts immediately when the first character is keyed in and continues as you add characters to the find string ("incremental search"). If you press the Find key LONG, the previous search is repeated. Interface When you press the Find key in the menu you see in the header area "Find: " and you are immediately in alpha mode. Start keying in the characters you want to search for. Find will go to the first match after the current position. If you are not satisfied with this position, key in more characters or press the RIGHT-arrow to find subsequent matches until you find the right place. Press ENTER to return to the editor at that position or press ON/CANCEL to return to the original cursor position. Find has its own menu, but most commands are also available with other keys, in particular the arrow keys. The arrow keys have their functionality independent of ALPHA mode, so there is no need to toggle alpha mode for using these commands. Menu and Key Commands EDIT (or DOWN-arrow) takes you into an INPUT screen to provide more editing options for the find string. REPL (or LEFT-arrow) prompts for a string to replace matches of the current find$ with. If you press ENTER, Emacs will find matches of the find string and offer a menu with the following options.
RCL (or UP-arrow) recalls the word currently under the cursor, from cursor to end of word, into the find$. If pressed again gets next word too. NEXT (or RIGHT-arrow) finds next match of the find string or beeps if not found. If the search string is empty, this command retrieves the most recent item in the find string history (see below) and uses it as find string. Pressing Find long repeats the previous search without starting the incremental search environment. HIST (or LeftShift UP-arrow) CHOOSE box with 5 most recent find strings. The history is stored in the Hidden directory and survives exiting the editor. Each time you terminate a search with ENTER, the current find string is added to the history. CaSe / CaSe# toggles case sensitivity. Whenever a lower case letter a-z is keyed in, case sensitivity is automatically set. Backspace (the key, not in the menu) delete last character in find string, search again from original position. RightShift UP search from beginning of file. ENTER exit Find, return to editor at current position. ON/CANCEL exit Find, return to original cursor position.
|
||||||||||||||||||||||||||||
ReEx(LS Find) |
Regular expression search. The environment provided for regular expression search and replacement is exactly the same as for the incremental search (see above). Only difference: typing a new search character starts a new editor for editing the regular expression. So the regexp search is not "incremental". The regular expressions in Emacs don't backtrack, quantifiers are greedy and possessive. For detailed documentation see the Regexp.txt file in the distribution. Regular expression metacharacters
|
||||||||||||||||||||||||||||
REPLACE(RS Find) |
Global Find&Replace, without query. Asks for a search string and a replacement string and replaces one with the other in the entire file. If you have to do many replacements, this is faster then the replace option in the Find application. |
||||||||||||||||||||||||||||
|
Starts the Emacs Meta mode to execute a
command in the Emacs macro language. The macro language gives access to most
simple motion and editing commands without having to switch to the TOOL menu,
as well as to more complex commands like transposition and paragraph filling.
For a list of available commands, see near the end of this document. In Pressing |
||||||||||||||||||||||||||||
HALT(LS Meta) |
Suspend the editor and start a session with the stack. Recursive RPLED's are allowed. Press CONT to get back into the editor. |
||||||||||||||||||||||||||||
→STK(RS Meta) |
Push a copy of the editor contents onto the stack. When the selection is active and the cursor inside or next to the selection, the selection is copied to the stack. Otherwise the entire Editor content. |
||||||||||||||||||||||||||||
Help |
Display help for Emacs. You can choose between a menu chart and command descriptions. In the chart there are there are 3 rows of labels for each menu page. The rows mean, from top to bottom: unshifted, leftshifted, rightshifted. The inverted labels indicate commands which have a LONG touch option, they will act slightly differently when the key is pressed long. If you choose the command description, you get a file with shows reference descriptions of all Emacs commands. |
||||||||||||||||||||||||||||
FNT(LS Help) |
Toggle minifont display. Be careful since the display update is not always reliable. Works best if your current font is FONT6. |
||||||||||||||||||||||||||||
Config(RS Help) |
Offers a CHOOSE box for Emacs configuration. The different items in the box mean: OptionsPurge Hidden VarsEdit 'emacs'Edit 'diagram'Edit 'cpltab'Edit the content of the 'cpltab' variable which is used for completion of user-specified items (see above). Asn Keys |
Indnt |
Indent current line according to context. This indents code correctly even if you have several commands in each line. If the cursor is at or inside a selection, the entire selection will be re-indented. Otherwise only the current line. EXAMPLE: The following fragment was indented automatically with this function:
To re-indent a part of a program, put the cursor on the opening "::", use the command "[..]" (see below) to select the current secondary and press "|→" to indent. The Emacs library also contains the command NL&IND which inserts a newline char and indents the new line. This is a very useful assignment for the newline key.
|
||||||||||||||||||||||||
UNCOMMENT(LS Indent) |
Remove the SysRPL comment starter "* " from the beginning of the current line or all lines in the current selection. When pressed LONG, the ML comment starter "% " is used.
|
||||||||||||||||||||||||
COMMENT(RS Indent) |
Add the SysRPL comment starter "* " to the beginning of the current line or all lines in the current selection. When pressed LONG, the ML comment starter "% " is used.
|
||||||||||||||||||||||||
{↔}<< DFIND >> |
Jump to matching delimiter. Jumps between
The normal version of this command
ignores MATRIX, SYMBOL and UNIT since they would make ::
|
||||||||||||||||||||||||
~FOLD(LS {↔}) |
Toggle folding of the current secondary or list into a single line. The cursor must be on the opening delimiter. Folding works by converting the NEWLINE characters into char number 29. Folding can be very useful to gain overview over stacked embedded secondaries or lists. Example: Lets say you have the following program in the editor. ITE If the horizontal line marks the end of the screen, the ELSE clause of the ITE statement is not visible. In order to get overview over the entire structure, put the cursor on the first :: after the ITE and press ~FOLD. The IF clause collapses into a single line. Press ~FOLD again to get the normal structure back.
CAVEAT: - The char \1D must not be used in the file.
|
||||||||||||||||||||||||
UNFOLD(RS {↔}) |
Unfold any folded parts in the entire file.
|
||||||||||||||||||||||||
OBSEL<< OBSEL >> |
Select syntactic unit. When the cursor is on a delimiter, select the region between the delimiter and its matching delimiter. Otherwise select the object at point. For example, if the cursor is anywhere in HXS 4 1234, the entire "HXS 4 1234" is selected.
With LeftShift: Select the current line. With RightShift: Select the entire text in the editor.
|
||||||||||||||||||||||||
( → )<< SDIAG >> |
Show the stack diagram or library provided help for the command/entry under the cursor. This command works also outside the editor with a string, rompointer or a list containing a rompointer on the stack. First, the SDIAG library is searched for a stack diagram of the command. If none is found, we check if the command is a rompointer and has help provided by the corresponding library. This works for all built-in CAS commands in the calculator, for all Emacs commands and for any other libraries which provide help for their commands through the library message handler. '( → )' works in many different locations. For example, to get help about the EXPAND command, press the key with · "EXPAND" on the stack · EXPAND on the stack (e.g. {EXPAND} HEAD) · {EXPAND} on the stack · in the command line with cursor at EXPAND · when editing a MASD source file with cursor near xEXPAND
The display will look like this
and you can use the following menu keys:
|
||||||||||||||||||||||||
EBR(LS ( → ) ) |
Browse the entry list in a functionality-sorted way. This opens a browser which contains the table of contents of the Entry database. Selecting a section shows a list of entries in that section. For each of these entries you can look at the stack diagram and description. For fast navigation in the browser use the number keys 1-9,0 to jump to a chapter, and then use the X key to jump to the subsections of that chapter. If you press SHOW, a new browser opens with all entries in that category. From that list you can use the following commands:
|
||||||||||||||||||||||||
→EBR(RS ( → ) ) |
Like EBR, but jumps immediately to the section containing the entry at the cursor position. For example, if the cursor is near CMD_PLUS, it jumps to the subsection on Inserting Text in the Editor Commands section in the Input and Output chapter. Press F6 (SHOW) to see a list of other commands inserting text into the command line editor. |
||||||||||||||||||||||||
EDOB |
Extract and decompile object under cursor. The decompiled object can be viewed in another instance of RPLED. Exiting with ON or ENTER returns to the first instance of RPLED. Special cases:
|
||||||||||||||||||||||||
LOCATE(RS EDOB) |
LOCATE is intended for large ML projects which distribute the code over several files. LOCATE visits include files and finds the definition of constants, variables and functions.
Emacs will try to locate the corresponding definition with a brute-force search of all string files on the current search path. If the definition is found, the file will be visited in a secondary editor session. After exiting, you will be back in the initial editor session. For a detailed description of Locate, see Denis' document Locate.txt in the Emacs distribution.
|
||||||||||||||||||||||||
ASM |
Call ASM on the content of the editor without leaving the editor. When there are compilation errors, jumps to the first error. If there is an active selection in the editor, only the selected part is compiled - otherwise the full file. Compilation is done in MASD SysRPL mode, but if the key is pressed long, ML mode will be used.
|
||||||||||||||||||||||||
Import(LS ASM) |
Decompile the object on stack level 1 and insert the resulting string into the editor.
|
||||||||||||||||||||||||
Export(RS ASM) |
ASM the object at the cursor and push the compiled object onto the stack. If there is an error during compilation, shows the error and where it happened.
|
|
Insert ":: ;" templates in one or several lines.
|
||||||
LAMS |
Insert a template for binding named or unnamed local variables (LAMS)
|
||||||
BEGIN |
Loop templates.
|
||||||
TRAP |
Error handling templates:
|
||||||
CODE |
Insert basic ML templates
|
||||||
IT→{} |
MASD SKIP templates for INT (ifnot-then) and INTE (ifnot-then-else), and for a simple loop.
|
|
Delete the rest of the current line and append it to the current content of the Clipboard. If the cursor is already at the end of the line, deletes the newline character. So when you are at the beginning of the line, pressing CUT→ twice deletes the whole line. When pressed LONG, the Clipboard is first cleared. Example: Press the key 4 times (long short short short) and two lines including final new lines will be on the clipboard, ready to be pasted back. |
TAB→ |
Tabulator command. Inserts enough spaces to reach the next TAB position. Tab positions are 0,4,8,12,... |
NL&IND |
Insert a LINEFEED character and indent the new line according to context, by using the Emacs INDENT command. This is a very useful assignment for the newline key. |
Insert string at cursor position. The string can contain control sequences which execute editor commands (macro language, see below). |
|
A list is interpreted as {LABEL ACTION}, as in normal CST menus. If ACTION is a list, the list elements define actions for unshifted and shifted key presses, as usual. If any of these actions is a list, it defines a submenu. |
|
program |
Execute program. TakeOver is not required. When invoked, process content of variable as Emacs menu entry. If the content of the variable is a list, it defines a submenu and the label for the menu entry will have the DIR bar. |
Any other object type is illegal and will produce "???" as label to indicate the error. |
{ ":: ;" ":: ;|b|b"} @ insert :: ;"
template, position cursor
{ "EOF" "|>" }
@ Go to end of file
MyProgs
@
Menu entry, to execute content of global
@ var MyProgs. When the var contains
@ a list, execution produces a submenu.
}
|
Cut the rest of the current line from the editor and save it in the clipboard for pasting. 1. Mark as BEGIN. 2. Goto end of line. 3. Mark as END 4. CUT Here is the macro string: "|[|e|]|w" |
b) |
Duplicate the current line:
In the macro language, this is written as: "|L|W|y" |
c) |
Insert a "*" at the beginning of the current line and move to the next. We already discussed this problem above as an example for the keyboard macro recorder. If you need this command more often, it will be useful to include it into list `emacs' list.
Here is the macro string: "*|b|n" |
With these 3 example macros, the `emacs' list looks like this:
{ "CUT→" "|[|e|]|w" }
{ "DUPL" "|L|W|y" }
{ "*" "*|b|n" }
}
f |
forward char, like (LEFT) |
b |
backward char, like (RIGHT) |
n |
next line, like (DOWN) |
p |
previous line (UP) |
A |
beginning of line (RS-LEFT) |
E |
end of line (RS-RIGHT) |
< |
beginning of file |
> |
end of file |
F |
skip to next word-start |
B |
skip to previous word-start |
I |
Tab→ |
h |
backspace (BS) |
d |
delete ( |
H |
delete to previous word-start |
D |
delete to next word-start |
k |
delete to beginning of line |
K |
delete to end of line |
X |
delete the current line, including the newline |
[ |
set beginning of selection (BEGIN) |
] |
set end of selection (END) |
- |
same as [ |
+ |
same as ] |
c |
clear selection |
l |
select line (excluding final newline, cursor at beginning) |
L |
select line (including final newline, cursor at beginning) |
0 |
select word at point |
1 |
select object at point (OBSEL) |
G |
jump to beginning of selection. If already there, jump to end. |
J |
jump between delimiters (DFIND) |
w |
copy selection into clipboard (COPY) |
W |
delete selection into clipboard (CUT) |
z |
copy selection and append it to the clipboard |
Z |
delete selection and append it to the clipboard |
Y |
yank clipboard into editor (PASTE) |
y |
edit the clipboard contents |
P |
evaluate the current selection and replace it with the result. If there is no selection, the region from the beginning of the line to the current cursor position is used instead. |
U |
make current word UPCASE and move on to next word. |
u |
make current word downcase and move on to next word. |
C |
capitalize current word and move on to next word. |
|
Mnemonics: second letter of style name |
||||||
|
|
|
Mnemonics: like the arrows on a keypad |
S |
center current line in screen width. |
Q |
fill the current line or selection to the width of the screen. The beginning of the selection sets the left border of the filled text, which is useful to format hanging paragraphs like the one you are reading now. |
7 |
Remove one space from the start of each line in the selection, or the current line. |
9 |
Add one space to the start of each line in the selection, or the current line.
|
m |
Insert newline |
| |
Insert `|'. So it insert a bar, use "||". |
@ |
show cursor position as → and pause for 3
seconds. For debugging. Not available in |
* |
move cursor to this position after macro
finishes. E.g. ":: |* ;". Does not work as a |
$ |
"Standard flag settings": -68(auto indent) set, -69(infinite line) set Useful to write templates independent of flag settings. System Flags are always saved and restored around an Emacs macro. |
March 2004. Carsten and Pivo.