CL Arrow-Key History Translations
Mike Fitzpatrick wrote on Dec 05, 2000
One of the most common CL-feature requests is the ability to use
the arrow keys to scroll through the CL history in the same way as is done
with tcsh shells. This was implemented directly in the NCL as part of
the SAO R&D package (http://hea-www.harvard.edu/RD) by Eric mandel, but
it turns out this can largely be done using the existing translations
provided by Xterm and XGterm without modifying the CL at all.
The idea is to use the keymap() translation function to program
various keymap "modes" for the window, each mode can redefine the action
taken by certain keys to provide extra keyboard functionality for a given
task. In this case we can define a "CL mode" which remaps the arrow keys
to implement the arrow-key history mechanism by invoking EHISTORY automat-
ically. As it turns out other modes and translations are needed so the
arrow keys still work as expected when in EPAR and so modes terminate
correctly.
The translations are appended to this posting. To use them do
the following:
1) Save the translations to your .Xdefaults file (or whichever file
defines your user resources).
2) Load the new resources using the command
% xrdb -load ~/.Xdefaults
and start a new XGterm.
3) In the new window, log into the CL and type various commands to
establish a history list.
4) To begin using the arrow keys, type the F2 key to begin CL mode,
the arrow keys can then be used as in tcsh to scroll through the
history.
5) If a problem occurs (i.e. arrows no longer work as expected), or
you leave the CL, type F1 to reset to the default keymap mode.
6) Aside from the arrow keys these translations also redefine the
following function keys in CL mode
F2 toggle the graphics window
F3 invoke the graphics cursor
F4 invoke the image cursor
7) An example mode for remapping the arrows for use with DBX is also
shown, this is invoked with the F3 key from the normal mode.
LIMITATIONS:
- Because these translations affect the text window all the time leaving
the keymap in CL mode will cause the arrow keys to be remapped even
when you're not still in the CL. This means that e.g. the arrows
will no longer scroll the history in the normal unix tcsh. The F1 key
will reset to the default mode in all cases.
- Occassionally you can be left in the ehist mode is you scroll off
the top of the CL history stack, again use F1 to reset.
- The translations here are for use with the 'vi' editor, emacs users
should consult the dev$emacs.ed file for a listing of the keys necessary
for movement with that editor.
- Care should be taken to select keyboard function keys that don't
overlap with functions mapped to them by the window manager (e.g F5 may
be used by the WM to iconify the window and overrides it's use as a
translation here). Modifiers such as Shift, Ctrl or Alt can be used to
work around this.
While not perfect these translations seem to work in most cases. They're
provided "as is" and it's hoped people will follow-up with other more clever
translations or fixes. For more details on translation functions available
see the xterm man page.
-Mike
--------------------------- cut here ------------------------------------
*VT100.Translations: #override \
!<Key>F1: keymap(None) \n\
!<Key>F2: keymap(cl) \n\
!<Key>F3: keymap(dbx)
*VT100.clKeymap.translations: #override \
!<Key>F1: keymap(None) \n\
!<Key>F2: set-visibility(tek,toggle) \n\
!<Key>F3: string("=gcur\n") \n\
!<Key>F4: string("=imcur\n") \n\
!<Key>e: keymap(epar) string("e") \n\
!<Key>Up: keymap(ehist) string("ehist\n") \n\
!<Key>KP_Up: keymap(ehist) string("ehist\n") \n\
None<Key>Down: string(0x0A) keymap(epar) \n\
None<Key>KP_Down: string(0x0A) keymap(epar)
*VT100.ehistKeymap.translations: #override \
<Key>Return: string(0x0D) keymap(cl) \n\
<Key>e: string("e") keymap(ehist) \n\
<Ctrl>c: string(0x0D) keymap(cl) string(0x03) \n\
<Ctrl>u: string(0x0D) keymap(cl) string(0x15) \n\
None<Key>Up: string(0x0B) keymap(ehist) \n\
None<Key>KP_Up: string(0x0B) keymap(ehist) \n\
None<Key>Down: string(0x0A) keymap(ehist) \n\
None<Key>KP_Down: string(0x0A) keymap(ehist) \n\
None<Key>Left: string(0x08) keymap(ehist) \n\
None<Key>KP_Left: string(0x08) keymap(ehist) \n\
None<Key>Right: string(0x0C) keymap(ehist) \n\
None<Key>KP_Right: string(0x0C) keymap(ehist) \n\
!Alt<Key>Left: string(0x02) keymap(ehist) \n\
!Alt<Key>KP_Left: string(0x02) keymap(ehist) \n\
!Alt<Key>Right: string(0x17) keymap(ehist) \n\
!Alt<Key>KP_Right: string(0x17) keymap(ehist)
*VT100.sectionKeymap.translations: #override \
!<Key>Return: string(0x0D) keymap(epar) \n\
!<Key>colon: string(0x3A) keymap(epar) \n\
<Key>bracketright: string(0x5D) keymap(epar)
*VT100.eparKeymap.translations: #override \
!<Key>Return: string(0x0D) keymap(cl) \n\
!<Key>colon: string(0x3A) keymap(cl) \n\
<Key>e: string("e") keymap(epar) \n\
None<Key>Up: string(0x0B) keymap(epar) \n\
None<Key>Down: string(0x0A) keymap(epar) \n\
None<Key>KP_Up: string(0x0B) keymap(epar) \n\
None<Key>KP_Down: string(0x0A) keymap(epar) \n\
!Alt<Key>Left: string(0x02) keymap(epar) \n\
!Alt<Key>KP_Left: string(0x02) keymap(epar) \n\
!Alt<Key>Right: string(0x17) keymap(epar) \n\
!Alt<Key>KP_Right: string(0x17) keymap(epar) \n\
<Key>bracketleft: string(0x5B) keymap(section)
*VT100.dbxKeymap.translations: \
!<Key>F1: keymap(None) \n\
None<Key>Right: string("next\n") \n\
None<Key>Down: string("step\n") \n\
None<Key>Up: string("up\n") \n\
None<Key>Left: string("where\n")
Last post on Dec 05, 2000