home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / emacs-18.59src.lha / emacs-18.59 / amiga / contrib / chopps / rexx / invoker next >
Encoding:
Text File  |  1993-05-08  |  7.9 KB  |  286 lines

  1. From: chopps@ro-chp.UUCP (Chris Hopps)
  2. Subject: Emacs invoker.
  3.  
  4.     This is the newest invoker of mine I am very pleased with it
  5. and think it would be good for inclusion in the main distribution.
  6. With the included rexx file (and some of the mods to emacs I sent you
  7. earlier,) this invoker supports multiple files on the cmd line.  It
  8. also supports turning backups off for the files loaded on that line,
  9. and a WAIT command that will have Emacs return the prompt only after
  10. the files specified on the command line have been killed.  The invoker
  11. also checks to see if Emacs is iconified if so it will de-iconify it.
  12. It brings emacs to the front and activates it (my mods needed for
  13. this.)
  14.  
  15. This makes leaving GNUEmacs up and running all the time very feasable.
  16. The invoker can be used for programs like ``Arn'', ``Elm'' or whatever
  17. else kind of program that does something with a file after the editor
  18. returns.
  19.  
  20. Here is the lisp code required for using the ``WAIT'' option of the
  21. invoker.  It should be loaded in the .emacs file.
  22.  
  23. -------8<-------------8<-------------8<-------------8<-------------8<--
  24. ;; [notify-rexx-wait.el] notification of kill of a buffer to rexx.
  25. ;; Copyright © 1993 Christian E. Hopps.
  26.  
  27. ;; This program is free software; you can redistribute it and/or modify
  28. ;; it under the terms of the GNU General Public License as published by
  29. ;; the Free Software Foundation; either version 2 of the License, or
  30. ;; (at your option) any later version.
  31.  
  32. ;; This program is distributed in the hope that it will be useful,
  33. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  35. ;; GNU General Public License for more details.
  36.  
  37. ;; You should have received a copy of the GNU General Public License
  38. ;; along with this program; if not, write to the Free Software
  39. ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  40.  
  41. ;; I can be contacted at:
  42. ;; bix: chopps
  43. ;; uucp: chopps@ro-chp.UUCP (sycom.mi.org!ro-chp!chopps)
  44.  
  45. (provide 'notify-rexx-wait)
  46.  
  47. (make-variable-buffer-local 'notify-rexx-port)
  48. (set-default 'notify-rexx-port nil)
  49.  
  50. ;;; Set old-kill-buffer to the internal version
  51. ;; first check to see if it has already been bound.
  52. ;; if not then bind it to the internal.
  53. ;;
  54. (if (not (fboundp 'old-rexx-notify-kill-buffer ))
  55.     (fset 'old-rexx-notify-kill-buffer (symbol-function 'kill-buffer)))
  56.  
  57. ;;; redefine kill-buffer to check to see if it should
  58. ;;  notify rexx that the buffer is being killed.
  59. ;;
  60. (defun kill-buffer (buffer-strp)
  61.   "Notifys rexx that the current buffer is about to be killed. If it has one."
  62.   (interactive "bBuffer:")
  63.   (let ((buf nil))
  64.     (setq buf (get-buffer buffer-strp))
  65.     (switch-to-buffer buf)
  66.     (if (eq notify-rexx-port nil)
  67.     (old-rexx-notify-kill-buffer buffer-strp)
  68.       (amiga-arexx-send-command (concat "ADDRESS " notify-rexx-port "; QUIT") t)
  69.       (old-rexx-notify-kill-buffer buf))))
  70. -------8<-------------8<-------------8<-------------8<-------------8<--
  71.  
  72. Here is the rexx code for the invoker, it can be copied to ``rexx:g.rexx''
  73. to be called from wshell with ``[prompt]g myfile.c WAIT'' or copied
  74. to ``s:g'' (or somewhere in path) to be called from the AmigaShell 
  75. (make sure to set the ``s'' script bit.
  76. -------8<-------------8<-------------8<-------------8<-------------8<--
  77. /***[g.rexx]***************************************************/
  78. /* An invoker for GNU Emacs.
  79.  * Copyright © 1993 Christian E. Hopps
  80.  *
  81.  * FILES/M,WAIT=STICKY/S,NOBACKUPS/S"
  82.  *
  83.  * use WAIT or STICKY option to have g.rexx wait for buffers 
  84.  * to be killed before returning (same as TurboText's ``WAIT''
  85.  * option or CED's ``STICKY'')
  86.  *
  87.  * NOBACKUPS will cause the files loaded by g.rexx not
  88.  * to perform backup saves.
  89.  *
  90.  * all options aply only to FILES that are specified on this
  91.  * invocation of g.rexx.
  92.  *
  93.  * This program is free software; you can redistribute it and/or modify
  94.  * it under the terms of the GNU General Public License as published by
  95.  * the Free Software Foundation; either version 2 of the License, or
  96.  * (at your option) any later version.
  97.  *
  98.  * This program is distributed in the hope that it will be useful,
  99.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  100.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  101.  * GNU General Public License for more details.
  102.  *
  103.  * You should have received a copy of the GNU General Public License
  104.  * along with this program; if not, write to the Free Software
  105.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  106.  *
  107.  * I can be contacted at:
  108.  * bix: chopps
  109.  * uucp: chopps@ro-chp.UUCP (sycom.mi.org!ro-chp!chopps)
  110.  * 
  111.  */
  112.  
  113. options results
  114. PARSE ARG argv
  115.  
  116. /* wait for buffer to be killed */
  117. wait = 0
  118. /* files that are being waited on. */
  119. waitingfiles = 0
  120.  
  121. /* do not make backups */
  122. nobackups = 0
  123.  
  124. /* Parse the args from command line. */
  125. idx = 0
  126. DO WHILE argv ~= ""
  127.     carg = GetNextItem()
  128.     uarg = UPPER(carg)
  129.     IF uarg = "STICKY" | uarg = "WAIT" THEN
  130.     wait = 1
  131.     ELSE IF uarg = "NOBACKUPS" THEN
  132.     nobackups = 1
  133.     ELSE IF uarg = "?" THEN DO
  134.     SAY "template: FILES/M,WAIT=STICKY/S,NOBACKUPS/S"
  135.     EXIT 0
  136.     END
  137.     ELSE IF uarg ~= "" THEN DO
  138.     IF SUBSTR(uarg,1,5) = "FILES" THEN DO
  139.         IF uarg = "FILES" THEN DO
  140.         file = GetNextItem()
  141.         IF file = "" THEN DO
  142.             SAY "template: FILES/M,WAIT=STICKY/S,NOBACKUPS/S"
  143.             EXIT 0
  144.         END
  145.         END
  146.         ELSE IF SUBSTR(uarg,6,1) = "=" THEN DO
  147.         file = SUBSTR(carg,7)
  148.         IF file = "" THEN DO
  149.             SAY "template: FILES/M,WAIT=STICKY/S,NOBACKUPS/S"
  150.             EXIT 0
  151.         END
  152.         END
  153.  
  154.     END
  155.     ELSE DO
  156.         file = carg
  157.         IF file = "" THEN DO
  158.         SAY "template: FILES/M,WAIT=STICKY/S,NOBACKUPS/S"
  159.         EXIT 0
  160.         END
  161.     END
  162.     dir = PRAGMA('Directory')
  163.     IF 0 = pos(':',file) THEN DO
  164.         IF lc ~= '/' & lc ~= ':' THEN
  165.         dir = dir || '/'
  166.         filename = dir || file
  167.     END
  168.     ELSE DO
  169.         IF lc ~= '/' & lc ~= ':' THEN
  170.         dir = dir || '/'
  171.         filename = dir || file
  172.     END
  173.     filestoload.idx = filename
  174.     idx = idx + 1
  175.     END
  176. END
  177.  
  178. IF wait = 1 THEN DO
  179.     start = 1
  180.     notifyport = "EMACS_NOTIFY" || start
  181.     DO WHILE SHOW('P',notifyport)
  182.     start = start + 1
  183.     notifyport = "EMACS_NOTIFY" || start
  184.     END
  185.  
  186.     notifymp = OPENPORT(notifyport)
  187.     IF ~SHOW('P',notifyport) THEN DO
  188.     SAY "Cannot initialize the notification port."
  189.     EXIT 20
  190.     END
  191. END
  192.  
  193. /* Load emacs if it is not already running */
  194. if (~show('p', 'EMACS1')) THEN DO
  195.     ADDRESS COMMAND
  196.     'run >NIL: emacs'
  197.     'waitforport EMACS1'
  198. END
  199.  
  200. ADDRESS EMACS1
  201.  
  202. IF wait = 1 THEN
  203.     "(require 'notify-rexx-wait)"
  204.  
  205. /* will return either nil or t */
  206. "(symbol-value 'amiga-emacs-iconified)"
  207.  
  208. IF result = "t" THEN
  209.     '(amiga-iconify)'
  210.  
  211. fileidx = 0
  212. DO WHILE fileidx < idx
  213.     '(buffer-name)'
  214.     curbuf = RESULT
  215.  
  216.     lisp = ' (progn '
  217.     IF curbuf ~= '"*scratch*"' THEN
  218.     lisp = lisp || ' (find-file-other-window "' || filestoload.fileidx || '"))'
  219.     ELSE
  220.     lisp = lisp || ' (find-file "' || filestoload.fileidx || '"))'
  221.  
  222.     ADDRESS EMACS1 lisp
  223.  
  224.     IF nobackups = 1 THEN DO
  225.     "(make-local-variable 'make-backup-files)"
  226.     '(setq make-backup-files nil)'
  227.     END
  228.  
  229.     IF wait = 1 THEN DO
  230.     '(setq notify-rexx-port "' || notifyport || '")'
  231.     waitingfiles = waitingfiles + 1;
  232.     END
  233.     fileidx = fileidx + 1
  234. END
  235.  
  236. '(amiga-window-to-front)'
  237. '(amiga-activate-window)'
  238.  
  239. IF wait = 1 THEN DO
  240.     quitflag = 0
  241.     DO FOREVER
  242.     IF waitingfiles = 0 THEN
  243.         EXIT 0
  244.     t = WAITPKT(notifyport)
  245.  
  246.     DO FOREVER
  247.         p = GETPKT(notifyport)
  248.         IF C2D(p) = 0 THEN BREAK
  249.         args = GETARG(p)
  250.  
  251.         PARSE VAR args argval args
  252.         IF argval = "QUIT" THEN
  253.         waitingfiles = waitingfiles - 1
  254.  
  255.         t = REPLY(p,1)
  256.     END
  257.     END
  258. END
  259.  
  260. EXIT 0
  261.  
  262. GetNextItem: PROCEDURE EXPOSE argv
  263. ch = LEFT(argv,1)
  264. DO WHILE ch = " " | ch = "    "
  265.     argv = SUBSTR(argv,2)
  266.     ch = LEFT(argv,1)
  267. END
  268. ch = LEFT(argv,1)
  269. IF ch = '"' THEN
  270.     PARSE VAR argv '"'string'"' argv
  271. ELSE
  272.     PARSE VAR argv string argv
  273. RETURN string
  274.  
  275.  
  276.  
  277. StripWS: PROCEDURE
  278.  
  279. ARG string
  280. RETURN string
  281. -------8<-------------8<-------------8<-------------8<-------------8<--
  282. ------------------------
  283. The Royal Oak Chophouse >> Chris Hopps
  284. Royal Oak, Michigan     >> sycom.mi.org!ro-chp!chopps
  285.  
  286.