home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 2
/
FFMCD02.bin
/
new
/
dev
/
misc
/
cweb
/
examples
/
oemacs.w
< prev
next >
Wrap
Text File
|
1993-12-21
|
38KB
|
897 lines
\datethis
@i xview_types.w
@* Introduction.
This program provides an interface between the GNU Emacs editor and the
OpenWindows environment, using the XView toolkit for interactive graphics.
It is based on \.{emacstool}, a SunView interface written by Jeff Peck
of Sun Microsystems in 1986 and adapted by him in 1988 to \.{xvetool},
an early XView interface. The present code, by Don Knuth, is designed to work
with OpenWindows Version~3 as distributed in 1992, using a Sun Type~4
keyboard.
GNU Emacs is a highly portable and versatile program, which does most
of the hard work involved in editing files. Our job is simply twofold:
To get \.{emacs} started in an appropriate window, and to transmit
keyboard and mouse events as sequences of characters that \.{emacs}
can happily consume. These simple tasks do, however, require us to
get a lot of fussy details right. In fact, this program could not have been
written without a good deal more knowledge about XView than can be found
in the manuals. Fortunately Jeff Peck works for Sun, and his
inside knowledge has provided the necessary clues. (All complaints below
about the XView documentation are based on the reference manuals and
programming manuals available from Sun and from O'Reilly \AM\ Associates, in
the summer of 1992. Let us hope that such problems will not persist;
computer programming should be fun, but some of the code below was
written only after a bitter struggle!)
The command-line arguments to \.{oemacs} are either standard XView
arguments, which specify the font and the size and position of the window,
the icon, the colors, etc.; or they are standard arguments of \.{emacs},
which typically specify the file to be edited and a position in that file.
If I decide later to make certain things in \.{oemacs} less hardwired,
I will look for options in the X resource database instead of on the
command line.
An important note about using \.{xmodmap} to change the behavior of
certain keys appears below. It makes \.{emacs} more powerful, unless you
have other good uses for those keys. (See the entry for \.{xmodmap}
in the index.)
Before using \.{oemacs}, you must compile \.{emacs} with the
\.{sunfns} module (which the \.{Makefile} will do for you if you've
configured it correctly), and you should include the lines
$$\vbox{\halign{\.{#}\hfil\cr
(load-library "sun-mouse")\cr
(load-library "sun-fns")\cr}}$$
in Emacs's file \.{lisp/site-init.el}.
Caution: This program was developed and tested with Peck's improved
versions of sun-mouse and sun-fns; these are available from
\.{peck@@sun.com} if not yet part of the GNU distribution.
@ We follow the traditional structure of XView applications. The |exit|
statement at the end is important, because \.{oemacs} can be invoked by
the \.{system} command in \TEX/ (when the user has typed \.e in response
to an error message); without |exit(0)|, \TEX/ would complain of trouble
executing this program, although we would simply be terminating the program
without returning any particular value.
@c
@<Include header files@>@;
@#
Frame frame; /* the base frame where we will live */
@<Global variables@>@; /* additional globals besides |frame| */
@#
@<Event-handling procedures@>@;
@#
main(argc,argv)
int argc;@+char *argv[]; /* typical \UNIX/ setup */
{
@<Special initialization@>;
@<Install the components and controls of |frame|@>;
xv_main_loop(frame);
exit(0);
}
@ Including the header file \.{<xview/xview.h>} also causes other
basic header files like \.{<xview/frame.h>}, \.{<xview/icon.h>}, etc.,
to be loaded. We must call the \CEE/ compiler with the flag
\.{-I\$(OPENWINHOME)/include} so that the \CEE/ preprocessor will
find the OpenWindows header files.
Some \UNIX/ systems define string functions in \.{<string.h>}, some in
\.{<strings.h>}; the Sun documentation calls for \.{<string.h>}. My
experiments indicate that Sun's compiler and loader work perfectly
well with string functions even when no header files are given, so the
programmer doesn't really have to remember the right name. Similarly,
\.{<stdio.h>} isn't really needed with Sun's \CEE/, unless certain macros
are used. I'll include \.{<string.h>} and \.{<stdio.h>} anyway, in the
spirit of being obedient to the stated rules.
@<Include...@>=
#include <string.h>
#include <stdio.h>
#include <xview/xview.h>
@* The icon and frame.
First we attach an icon that will appear if the user closes the \.{oemacs}
window later.
There are two reasons for doing this first. One is that we might as well
begin with an easy task, in order to get warmed up. The other is that
if we specify the icon {\it after\/} creating the frame, we will unconditionally
override an icon that the user may have specified with the \.{-WI}
option on the command line. (This is one of the little things a
programmer has to turn by trial and error, since the XView documentation
leaves much unsaid.)
The colors used in the icon will be inherited from the frame, so they will
be reversed if the user asks for reverse video. I~prefer to have the icon
always in black on a yellow background, so I'm making the color explicit.
(I hope this will work on monochrome displays; it works fine on my
grayscale monitor.)
@<Create a frame with the gnu icon@>=
{@+Server_image icon_image=(Server_image)xv_create(NULL,SERVER_IMAGE,@|
XV_WIDTH,64,XV_HEIGHT,64,SERVER_IMAGE_BITS,icon_bits,NULL);
Server_image mask_image=(Server_image)xv_create(NULL,SERVER_IMAGE,@|
XV_WIDTH,64,XV_HEIGHT,64,SERVER_IMAGE_BITS,mask_bits,NULL);
Cms cms=(Cms)xv_create(NULL,CMS,CMS_SIZE,2,@|
CMS_NAMED_COLORS,"yellow","black",NULL,NULL);
Icon icon=(Icon)xv_create(NULL,ICON,@|
ICON_IMAGE,icon_image,ICON_MASK_IMAGE,mask_image,@|
WIN_CMS,cms,NULL);
frame=xv_create(NULL,FRAME,FRAME_ICON,icon,NULL);
}
@ @<Include...@>=
#include <xview/cms.h>
@ If the user hasn't specified a label with the \.{-Wl} option, we turn off
the header line at the top of the frame. That gives us a chance to see
two more lines of the file \.{emacs} is editing. However, we add a
label of our own; it will show up in the virtual window manager display.
@<Remove the frame header, unless the user has specifically requested it@>=
if (xv_get(frame,XV_LABEL)==NULL) /* no label specified */
xv_set(frame,FRAME_SHOW_HEADER,FALSE,XV_LABEL,"OEMACS",NULL);
@ The following icon and mask are derived from the ``what's gnu'' image on the
back cover of the GNU Emacs manual. (This accounts for my black-on-yellow
preference.)
@<Global...@>=
unsigned short icon_bits[]={@|
0x0000, 0x0000, 0x0000, 0x1E00,
0x0000, 0x0000, 0x0000, 0x0900,@|
0x001E, 0x0000, 0x0000, 0x0880,
0x0064, 0x0000, 0x0000, 0x0440,@|
0x0088, 0x0000, 0x0000, 0x0420,
0x0110, 0x0000, 0x0000, 0x0210,@|
0x0220, 0x0000, 0x0000, 0x0210,
0x0420, 0x0FCF, 0x01C0, 0x0108,@|
0x0840, 0x1030, 0x8620, 0x0088,
0x1080, 0x00C0, 0x5810, 0x0084,@|
0x1080, 0x1F00, 0x2008, 0x0044,
0x2100, 0xE200, 0x1004, 0x0044,@|
0x4103, 0x0400, 0x0002, 0x0042,
0x4204, 0x080E, 0x0001, 0x0042,@|
0x8200, 0x7830, 0x0020, 0x8082,
0x8203, 0x9040, 0x0018, 0x4102,@|
0x8204, 0x2080, 0x07C6, 0x3E04,
0x8108, 0x410C, 0x0021, 0x8004,@|
0x8080, 0x8210, 0x03D0, 0x6008,
0x4041, 0x0420, 0x0008, 0x1810,@|
0x403E, 0x0820, 0x0FFC, 0x0620,
0x2000, 0x1040, 0x0002, 0x01C0,@|
0x1000, 0x608C, 0x0FFF, 0x0060,
0x0801, 0x8110, 0x0080, 0x8118,@|
0x0406, 0x0220, 0x1FFF, 0x66E0,
0x0238, 0x044F, 0x0000, 0xD800,@|
0x01C0, 0x0890, 0x8FFF, 0x4000,
0x0300, 0x10A6, 0x4041, 0x6000,@|
0x1C00, 0x2026, 0x4FFF, 0x6000,
0x60CC, 0x4026, 0x4001, 0x6000,@|
0x1F33, 0x8010, 0x8FFF, 0x4000,
0x0012, 0x000F, 0x0040, 0xC000,@|
0x0022, 0x4000, 0x07FF, 0x4000,
0x0024, 0x4000, 0x0000, 0x2000,@|
0x0024, 0x4818, 0x8FFF, 0xE000,
0x0024, 0x4907, 0x0040, 0x2000,@|
0x0044, 0x4900, 0x1FFF, 0xE000,
0x0044, 0x4900, 0x0000, 0x2000,@|
0x0044, 0x4900, 0x07FF, 0xE000,
0x0044, 0x4880, 0x0020, 0x2000,@|
0x0044, 0x4880, 0x07FF, 0xE000,
0x0044, 0x4840, 0x0000, 0x2000,@|
0x0044, 0x2A20, 0x07FF, 0xE000,
0x0044, 0x2410, 0x0020, 0x2000,@|
0x0042, 0x2448, 0x0FFF, 0xE000,
0x0042, 0x2948, 0x0000, 0x2000,@|
0x0041, 0x1144, 0x07FF, 0xA000,
0x0041, 0x1144, 0x2010, 0x1000,@|
0x0021, 0x1126, 0