home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 2: PC
/
frozenfish_august_1995.bin
/
bbs
/
d09xx
/
d0945.lha
/
EmacsStarter
/
rexx
/
emacs.rexx
next >
Wrap
OS/2 REXX Batch file
|
1993-12-20
|
9KB
|
287 lines
/*
FILE Emacs.rexx
VERSION $VER: V1.06 Emacs.rexx
DESCRIPTION Load a file into a (running) emacs.
emacs [flags and files]
The following options are supported:
-[not]tofront (Don't) move the Emacs window and screen
to the front.
-[not]sticky Do not terminate until the files on the
command line are killed.
-[no]screen Open a public screen (Requiers ScreenManager)
where the third and fourth argument corresponds to the
the screensize.
AUTHOR Anders Lindgren, d91ali@csd.uu.se
Bo Liljegren, bo-lilje@dsv.su.se
STATUS This file is in the public domain
HISTORY
11-Aug-92 ALi Created this file
13-Aug-92 ALi Replaced "runwsh" with "run".
"else nop" added.
14-Aug-92 ALi 1.00 V1.0 released.
20-Aug-92 Bo L 1.01 Added ScreenManager stuff.
03-Jan-93 ALi 1.02 MODE edited. COLOURS removed.
amiga-set-geometry moved to .emacs
13-Jan-93 ALi 1.03 TOBACK added. SHANGHAI and DEFAULT removed,
emacs can now open itself correctly.
-nottofront flag added.
20-Jan-93 Bo L 1.04 Replaced the static portname with the dynamic
in the 'WaitForPort'-line
16 aug 93 Bo L 1.05 Changed screenresolution argument to DISPID.
To avoid nameconflict with different languages.
Changed ScrenManager parse part for those
(unblessed) who don't have WShell.
22-Sep-93 ALi 1.06 Real option and filename parser added.
(amiga-window-to-front) and
(amiga-activate-window) called instead of
ScreenManager.
(cd ) removed. (Why should emacs move directry?)
Sticky option added.
Files loaded by (load-file ), even when Emacs
is started by the script.
Temporary file which sets the window size and
screen name added. (No use for anything in .emacs)
POPPUB option removed.
Now gets screen font from WB.
*/
OPTIONS RESULTS
OPTIONS FAILAT 21
/* Make sure required libraries are present */
IF ~SHOW('l',"rexxsupport.library") THEN DO
IF ~ADDLIB("rexxsupport.library",0,-30,0) THEN DO
SAY "Can't find rexxsupport.library"
EXIT
END
END
/* The name for the public screen */
screenname = 'Emacs'
portname = 'EMACS1'
args = ARG(1)
/* The commandline to send to a new emacs */
cmd = ""
/* A stem containing the options, the defaults are set here */
flags.batch = 0 /* Batch mode, always start a new Emacs */
flags.kill = 0 /* Kill a running emacs. */
flags.screen = 1 /* Use a public screen (Requiers ScreenManager) */
flags.sticky = 0 /* Wait until the buffers are terminated */
flags.tofront = 1 /* Send the screen to the front */
/* Argument parser */
filesidx = 0
DO WHILE LENGTH(args) > 1
args = strip(args, 'L') /* Strip leading blanks */
IF LEFT(args,1) = '"' THEN DO
filesidx = filesidx + 1
PARSE VAR args '"' files.filesidx '"' args
END
ELSE DO
PARSE VAR args onearg args
IF LEFT(onearg,1) = '-' THEN DO
SELECT
WHEN onearg = "-tofront" THEN flags.tofront = 1
WHEN onearg = "-nottofront" THEN flags.tofront = 0
WHEN onearg = "-sticky" THEN flags.sticky = 1
WHEN onearg = "-notsticky" THEN flags.sticky = 0
WHEN onearg = "-screen" THEN flags.screen = 1
WHEN onearg = "-noscreen" THEN flags.screen = 0
WHEN onearg = "-batch" THEN flags.batch = 1
WHEN onearg = "-kill" THEN DO
flags.kill = 1
cmd = cmd onearg
END
/* Emacs options with one argument */
WHEN (onearg = "-l" | onearg = "-load" | onearg = "-f",
| onearg = "-funcall" | onearg = "-i" | onearg = "-insert",
| onearg = "-t" | onearg = "-u" | onearg = "-user") THEN DO
PARSE VAR args optarg args
cmd = cmd onearg optarg
END
/* Emacs options with two arguments */
WHEN (onearg = "-dev" | onearg = "-fn") THEN DO
PARSE VAR args optarg1 optarg2 args
cmd = cmd onearg optarg1 optarg2
END
OTHERWISE cmd = cmd onearg
END
END
ELSE IF LEFT(onearg,1) = '+' THEN DO
PARSE VAR onearg '+' flags.linenumber
END
ELSE DO
filesidx = filesidx + 1
files.filesidx = onearg
END
END
END
/* If in batch-mode, start a new Emacs synchronous using the
* original options */
IF flags.batch THEN DO
ADDRESS COMMAND "temacs" arg(1)
EXIT rc
END
/* If an Emacs Screen doesn't exists, create one */
IF flags.screen & ~SHOWLIST('W',screenname||'-Demon') THEN DO
filnamn = 'T:SM'||d2x(random(256,1024,time('s')))
ADDRESS COMMAND 'ScreenManager INFO Workbench EXPERT >'||filnamn
IF ~OPEN(fil,filnamn,'R') THEN EXIT 20
cnt = 4
rad = READLN(fil)
IF EOF(fil) THEN cnt = 0
DO WHILE cnt ~= 0
ord = WORD(rad,1)
SELECT
WHEN ord = 'Position:' THEN DO
PARSE VAR rad . '=' xpos ' ' . '=' ypos ' ' .
cnt = cnt - 1
END
WHEN ord = 'Size:' THEN DO
PARSE VAR rad . '=' xsize ' ' . '=' ysize ' ' .
cnt = cnt - 1
END
WHEN ord = 'DisplayID:' THEN DO
resmode = WORD(rad,2)
cnt = cnt - 1
END
WHEN ord = 'Font:' THEN DO
PARSE VAR rad 'Font:' font '.font ' fontsize
font = strip(font)
cnt = cnt - 1
END
OTHERWISE
NOP
END
rad = READLN(fil)
IF EOF(fil) THEN cnt = 0
END
CALL CLOSE(fil)
CALL DELETE(filnamn)
menubar = fontsize + 2
ypos = ypos + menubar
ysize = ysize - menubar
ScrMng = ' OPEN '||screenname||' TITLE="'||screenname||' Screen"'
ScrMng = ScrMng||' DISPID='||resmode
ScrMng = ScrMng||' PLANES=2'
ScrMng = ScrMng||' PENS=011213103'
ScrMng = ScrMng||' FONT='||font||'.'||fontsize
ScrMng = ScrMng||' AUTOCLOSE' /* close screen when Emacs exists */
ScrMng = ScrMng||' TOBACK' /* It's moved to the front below */
ScrMng = ScrMng||' CX_TOFRONT="LCOMMAND e"'
ScrMng = ScrMng||' CX_DEFAULT="LCOMMAND SHIFT e"'
ADDRESS COMMAND 'ScreenManager' ScrMng
/* Create a small elisp file which sets the screen and size of Emacs */
sizefilename = 't:size' || d2x(random(256,1024,time('s'))) || '.el'
IF ~OPEN(fil, sizefilename, 'W') THEN EXIT 20
CALL WRITELN(fil, ';; Automagically created by Emacs.rexx')
CALL WRITELN(fil, '(amiga-set-geometry 0' fontsize+3 xsize ysize '"' || screenname || '")')
CALL CLOSE(fil)
cmd = cmd '-load' sizefilename
END
/* Start a new Emacs, if no one exists. */
IF SHOW('P', portname) = 0 THEN DO
CALL PRAGMA('stack', 40000)
ADDRESS COMMAND 'run <nil: >nil: temacs' cmd
ADDRESS COMMAND 'WaitForPort' portname
flags.kill = 0
END
ADDRESS VALUE portname
/* This no-op call doesn't return until after the
* t:sizeXX file has been read */
"()"
/* Delete the temporary file, if it was created. */
IF SYMBOL('sizefilename') = 'VAR' THEN CALL DELETE(sizefilename)
/* If in sticky mode, load sticky module into Emacs and
* open a communication port */
IF flags.sticky THEN DO
"(require 'sticky)"
count = 1
DO UNTIL ~SHOW('P', stickyportname)
stickyportname = "EMACS_CLIENT" || count
count = count + 1
END
CALL OPENPORT(stickyportname)
IF ~SHOW('P', stickyportname) THEN DO
SAY "Emacs client: Can't open sticky port."
EXIT 20
END
END
/* Get the current diretory. (There is no point in building a correct
* filename, since Emacs does that for us.) */
dir = PRAGMA('directory')
IF RIGHT(dir,1) ~= ':' THEN dir = dir || '/'
stickycount = 0 /* The number of files to wait for */
/* Load the files into emacs */
DO i = 1 TO filesidx
'(find-file "' || dir || files.i || '")'
IF flags.sticky THEN DO
'(setq sticky-rexx-port "' || stickyportname || '")'
stickycount = stickycount + 1
END
END
/* If the +linenumber option was given, go to the correct line */
IF SYMBOL('flags.linenumber') = 'VAR' THEN '(goto-line ' || flags.linenumber || ')'
/* Bring an activated Emacs window and screen to the front */
IF flags.tofront THEN DO
'(amiga-window-to-front)'
'(amiga-activate-window)'
END
/* If in sticky mode, wait for the buffers to be deleted */
IF flags.sticky THEN DO
DO WHILE stickycount > 0
CALL WAITPKT(stickyportname)
pkt = GETPKT(stickyportname)
IF pkt = NULL() then iterate
IF GETARG(pkt) = "TERMINATING" THEN
stickycount = stickycount - 1
CALL REPLY(pkt, 0)
END
CALL CLOSEPORT(stickyportname)
END
IF flags.kill THEN DO
'(save-buffers-kill-emacs)'
/* Screen normally closed automatically, but this won't hurt */
IF flags.screen THEN DO
ADDRESS COMMAND 'ScreenManager close' screenname
END
END
EXIT 0