1992-07-16 21:47:34 +00:00
|
|
|
;;; vmsproc.el --- run asynchronous VMS subprocesses under Emacs
|
|
|
|
|
2006-12-05 07:06:08 +00:00
|
|
|
;; Copyright (C) 1986, 2001, 2002, 2003, 2004, 2005,
|
2006-02-06 15:23:23 +00:00
|
|
|
;; 2006 Free Software Foundation, Inc.
|
1992-07-22 02:58:48 +00:00
|
|
|
|
1992-07-16 21:47:34 +00:00
|
|
|
;; Author: Mukesh Prasad
|
|
|
|
;; Maintainer: FSF
|
1992-07-17 18:53:44 +00:00
|
|
|
;; Keywords: vms
|
1992-05-30 19:21:46 +00:00
|
|
|
|
1989-10-31 15:59:53 +00:00
|
|
|
;; 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
|
1992-07-16 21:47:34 +00:00
|
|
|
;; the Free Software Foundation; either version 2, or (at your option)
|
1989-10-31 15:59:53 +00:00
|
|
|
;; 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
|
1996-01-14 07:34:30 +00:00
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
2005-07-04 23:32:44 +00:00
|
|
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
;; Boston, MA 02110-1301, USA.
|
1989-10-31 15:59:53 +00:00
|
|
|
|
2001-07-15 16:15:35 +00:00
|
|
|
;;; Commentary:
|
|
|
|
|
1992-07-16 21:47:34 +00:00
|
|
|
;;; Code:
|
1989-10-31 15:59:53 +00:00
|
|
|
|
|
|
|
(defvar display-subprocess-window nil
|
1996-01-04 23:53:00 +00:00
|
|
|
"If non-nil, the subprocess window is displayed whenever input is received.")
|
1989-10-31 15:59:53 +00:00
|
|
|
|
|
|
|
(defvar command-prefix-string "$ "
|
|
|
|
"String to insert to distinguish commands entered by user.")
|
|
|
|
|
|
|
|
(defvar subprocess-running nil)
|
2005-07-29 20:16:51 +00:00
|
|
|
(defvar subprocess-buf nil)
|
|
|
|
|
2005-07-29 20:14:37 +00:00
|
|
|
(defvar command-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map "\C-m" 'command-send-input)
|
|
|
|
(define-key map "\C-u" 'command-kill-line)
|
|
|
|
map))
|
1989-10-31 15:59:53 +00:00
|
|
|
|
|
|
|
(defun subprocess-input (name str)
|
2006-11-27 17:05:54 +00:00
|
|
|
"Handle input from a subprocess. Called by Emacs."
|
1989-10-31 15:59:53 +00:00
|
|
|
(if display-subprocess-window
|
|
|
|
(display-buffer subprocess-buf))
|
2005-07-29 20:16:51 +00:00
|
|
|
(with-current-buffer subprocess-buf
|
1989-10-31 15:59:53 +00:00
|
|
|
(goto-char (point-max))
|
2005-07-29 20:16:51 +00:00
|
|
|
(insert str ?\n)))
|
1989-10-31 15:59:53 +00:00
|
|
|
|
|
|
|
(defun subprocess-exit (name)
|
|
|
|
"Called by Emacs upon subprocess exit."
|
|
|
|
(setq subprocess-running nil))
|
|
|
|
|
|
|
|
(defun start-subprocess ()
|
2006-11-27 17:05:54 +00:00
|
|
|
"Spawn an asynchronous subprocess with output redirected to
|
1989-10-31 15:59:53 +00:00
|
|
|
the buffer *COMMAND*. Within this buffer, use C-m to send
|
|
|
|
the last line to the subprocess or to bring another line to
|
|
|
|
the end."
|
|
|
|
(if subprocess-running
|
|
|
|
(return t))
|
|
|
|
(setq subprocess-buf (get-buffer-create "*COMMAND*"))
|
2005-07-29 20:14:37 +00:00
|
|
|
(with-current-buffer subprocess-buf
|
1989-10-31 15:59:53 +00:00
|
|
|
(use-local-map command-mode-map))
|
|
|
|
(setq subprocess-running (spawn-subprocess 1 'subprocess-input
|
|
|
|
'subprocess-exit))
|
|
|
|
;; Initialize subprocess so it doesn't panic and die upon
|
|
|
|
;; encountering the first error.
|
|
|
|
(and subprocess-running
|
|
|
|
(send-command-to-subprocess 1 "ON SEVERE_ERROR THEN CONTINUE")))
|
|
|
|
|
|
|
|
(defun subprocess-command-to-buffer (command buffer)
|
|
|
|
"Execute COMMAND and redirect output into BUFFER."
|
|
|
|
(let (cmd args)
|
|
|
|
(setq cmd (substring command 0 (string-match " " command)))
|
|
|
|
(setq args (substring command (string-match " " command)))
|
|
|
|
(call-process cmd nil buffer nil "*dcl*" args)))
|
2005-07-29 20:14:37 +00:00
|
|
|
;; BUGS: only the output up to the end of the first image activation is trapped.
|
|
|
|
;; (if (not subprocess-running)
|
|
|
|
;; (start-subprocess))
|
|
|
|
;; (with-current-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))))
|
1989-10-31 15:59:53 +00:00
|
|
|
|
|
|
|
(defun subprocess-command ()
|
2006-11-27 17:05:54 +00:00
|
|
|
"Start asynchronous subprocess if not running and switch to its window."
|
1989-10-31 15:59:53 +00:00
|
|
|
(interactive)
|
|
|
|
(if (not subprocess-running)
|
|
|
|
(start-subprocess))
|
|
|
|
(and subprocess-running
|
|
|
|
(progn (pop-to-buffer subprocess-buf) (goto-char (point-max)))))
|
|
|
|
|
|
|
|
(defun command-send-input ()
|
2006-11-27 17:05:54 +00:00
|
|
|
"If at last line of buffer, send the current line to
|
|
|
|
the spawned subprocess. Otherwise bring back current
|
1989-10-31 15:59:53 +00:00
|
|
|
line to the last line for resubmission."
|
|
|
|
(interactive)
|
|
|
|
(beginning-of-line)
|
2005-07-29 20:14:37 +00:00
|
|
|
(let ((current-line (buffer-substring (point) (line-end-position))))
|
1989-10-31 15:59:53 +00:00
|
|
|
(if (eobp)
|
|
|
|
(progn
|
|
|
|
(if (not subprocess-running)
|
|
|
|
(start-subprocess))
|
|
|
|
(if subprocess-running
|
|
|
|
(progn
|
|
|
|
(beginning-of-line)
|
|
|
|
(send-command-to-subprocess 1 current-line)
|
|
|
|
(if command-prefix-string
|
|
|
|
(progn (beginning-of-line) (insert command-prefix-string)))
|
|
|
|
(next-line 1))))
|
|
|
|
;; else -- if not at last line in buffer
|
2005-07-29 20:14:37 +00:00
|
|
|
(goto-char (point-max))
|
1989-10-31 15:59:53 +00:00
|
|
|
(backward-char)
|
|
|
|
(next-line 1)
|
2005-07-29 20:14:37 +00:00
|
|
|
(insert
|
|
|
|
(if (compare-strings command-prefix-string nil nil
|
|
|
|
current-line 0 (length command-prefix-string))
|
|
|
|
(substring current-line (length command-prefix-string))
|
|
|
|
current-line)))))
|
1989-10-31 15:59:53 +00:00
|
|
|
|
2005-07-29 20:14:37 +00:00
|
|
|
(defun command-kill-line ()
|
2006-11-27 17:05:54 +00:00
|
|
|
"Kill the current line. Used in command mode."
|
1989-10-31 15:59:53 +00:00
|
|
|
(interactive)
|
|
|
|
(beginning-of-line)
|
|
|
|
(kill-line))
|
|
|
|
|
|
|
|
(define-key esc-map "$" 'subprocess-command)
|
1992-05-30 20:24:49 +00:00
|
|
|
|
2005-07-29 20:14:37 +00:00
|
|
|
;; arch-tag: 600b2512-f903-4887-bcd2-e76b306f5b66
|
1992-05-30 20:24:49 +00:00
|
|
|
;;; vmsproc.el ends here
|