;;; vmsproc.el --- run asynchronous VMS subprocesses under Emacs;; Copyright (C) 1986 Free Software Foundation, Inc.;; Author: Mukesh Prasad;; Maintainer: FSF;; Keywords: vms;; This file is part of GNU Emacs.;; GNU Emacs is free software; you can redistribute it and/or modify;; it under the terms of the GNU General Public License as published by;; the Free Software Foundation; either version 2, or (at your option);; any later version.;; GNU Emacs is distributed in the hope that it will be useful,;; but WITHOUT ANY WARRANTY; without even the implied warranty of;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the;; GNU General Public License for more details.;; You should have received a copy of the GNU General Public License;; along with GNU Emacs; see the file COPYING. If not, write to the;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,;; Boston, MA 02111-1307, USA.;;; Code:(defvardisplay-subprocess-windownil"If non-nil, the subprocess window is displayed whenever input is received.")(defvarcommand-prefix-string"$ ""String to insert to distinguish commands entered by user.")(defvarsubprocess-runningnil)(defvarcommand-mode-mapnil)(ifcommand-mode-mapnil(setqcommand-mode-map(make-sparse-keymap))(define-keycommand-mode-map"\C-m"'command-send-input)(define-keycommand-mode-map"\C-u"'command-kill-line))(defunsubprocess-input(namestr)"Handles input from a subprocess. Called by Emacs."(ifdisplay-subprocess-window(display-buffersubprocess-buf))(let((old-buffer(current-buffer)))(set-buffersubprocess-buf)(goto-char(point-max))(insertstr)(insert?\n)(set-bufferold-buffer)))(defunsubprocess-exit(name)"Called by Emacs upon subprocess exit."(setqsubprocess-runningnil))(defunstart-subprocess()"Spawns an asynchronous subprocess with output redirected tothe buffer *COMMAND*. Within this buffer, use C-m to sendthe last line to the subprocess or to bring another line tothe end."(ifsubprocess-running(returnt))(setqsubprocess-buf(get-buffer-create"*COMMAND*"))(save-excursion(set-buffersubprocess-buf)(use-local-mapcommand-mode-map))(setqsubprocess-running(spawn-subprocess1'subprocess-input'subprocess-exit));; Initialize subprocess so it doesn't panic and die upon;; encountering the first error.(andsubprocess-running(send-command-to-subprocess1"ON SEVERE_ERROR THEN CONTINUE")))(defunsubprocess-command-to-buffer(commandbuffer)"Execute COMMAND and redirect output into BUFFER."(let(cmdargs)(setqcmd(substringcommand0(string-match" "command)))(setqargs(substringcommand(string-match" "command)))(call-processcmdnilbuffernil"*dcl*"args)));BUGS: only the output up to the end of the first image activation is trapped.; (if (not subprocess-running); (start-subprocess)); (save-excursion; (set-buffer buffer); (let ((output-filename (concat "SYS$SCRATCH:OUTPUT-FOR-"; (getenv "USER") ".LISTING"))); (while (file-exists-p output-filename); (delete-file output-filename)); (define-logical-name "SYS$OUTPUT" (concat output-filename "-NEW")); (send-command-to-subprocess 1 command); (send-command-to-subprocess 1 (concat; "RENAME " output-filename; "-NEW " output-filename)); (while (not (file-exists-p output-filename)); (sleep-for 1)); (define-logical-name "SYS$OUTPUT" nil); (insert-file output-filename); (delete-file output-filename))))(defunsubprocess-command()"Starts asynchronous subprocess if not running and switches to its window."(interactive)(if(notsubprocess-running)(start-subprocess))(andsubprocess-running(progn(pop-to-buffersubprocess-buf)(goto-char(point-max)))))(defuncommand-send-input()"If at last line of buffer, sends the current line tothe spawned subprocess. Otherwise brings back currentline to the last line for resubmission."(interactive)(beginning-of-line)(let((current-line(buffer-substring(point)(progn(end-of-line)(point)))))(if(eobp)(progn(if(notsubprocess-running)(start-subprocess))(ifsubprocess-running(progn(beginning-of-line)(send-command-to-subprocess1current-line)(ifcommand-prefix-string(progn(beginning-of-line)(insertcommand-prefix-string)))(next-line1))));; else -- if not at last line in buffer(end-of-buffer)(backward-char)(next-line1)(if(string-equalcommand-prefix-string(substringcurrent-line0(lengthcommand-prefix-string)))(insert(substringcurrent-line(lengthcommand-prefix-string)))(insertcurrent-line)))))(defuncommand-kill-line()"Kills the current line. Used in command mode."(interactive)(beginning-of-line)(kill-line))(define-keyesc-map"$"'subprocess-command);;; vmsproc.el ends here