1 ;;; vmsproc.el --- run asynchronous VMS subprocesses under Emacs
3 ;; Copyright (C) 1986 Free Software Foundation, Inc.
5 ;; Author: Mukesh Prasad
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (defvar display-subprocess-window nil
31 "If non-nil, the subprocess window is displayed whenever input is received.")
33 (defvar command-prefix-string
"$ "
34 "String to insert to distinguish commands entered by user.")
36 (defvar subprocess-running nil
)
37 (defvar command-mode-map nil
)
41 (setq command-mode-map
(make-sparse-keymap))
42 (define-key command-mode-map
"\C-m" 'command-send-input
)
43 (define-key command-mode-map
"\C-u" 'command-kill-line
))
45 (defun subprocess-input (name str
)
46 "Handles input from a subprocess. Called by Emacs."
47 (if display-subprocess-window
48 (display-buffer subprocess-buf
))
49 (let ((old-buffer (current-buffer)))
50 (set-buffer subprocess-buf
)
51 (goto-char (point-max))
54 (set-buffer old-buffer
)))
56 (defun subprocess-exit (name)
57 "Called by Emacs upon subprocess exit."
58 (setq subprocess-running nil
))
60 (defun start-subprocess ()
61 "Spawns an asynchronous subprocess with output redirected to
62 the buffer *COMMAND*. Within this buffer, use C-m to send
63 the last line to the subprocess or to bring another line to
65 (if subprocess-running
67 (setq subprocess-buf
(get-buffer-create "*COMMAND*"))
69 (set-buffer subprocess-buf
)
70 (use-local-map command-mode-map
))
71 (setq subprocess-running
(spawn-subprocess 1 'subprocess-input
73 ;; Initialize subprocess so it doesn't panic and die upon
74 ;; encountering the first error.
75 (and subprocess-running
76 (send-command-to-subprocess 1 "ON SEVERE_ERROR THEN CONTINUE")))
78 (defun subprocess-command-to-buffer (command buffer
)
79 "Execute COMMAND and redirect output into BUFFER."
81 (setq cmd
(substring command
0 (string-match " " command
)))
82 (setq args
(substring command
(string-match " " command
)))
83 (call-process cmd nil buffer nil
"*dcl*" args
)))
84 ;BUGS: only the output up to the end of the first image activation is trapped.
85 ; (if (not subprocess-running)
89 ; (let ((output-filename (concat "SYS$SCRATCH:OUTPUT-FOR-"
90 ; (getenv "USER") ".LISTING")))
91 ; (while (file-exists-p output-filename)
92 ; (delete-file output-filename))
93 ; (define-logical-name "SYS$OUTPUT" (concat output-filename "-NEW"))
94 ; (send-command-to-subprocess 1 command)
95 ; (send-command-to-subprocess 1 (concat
96 ; "RENAME " output-filename
97 ; "-NEW " output-filename))
98 ; (while (not (file-exists-p output-filename))
100 ; (define-logical-name "SYS$OUTPUT" nil)
101 ; (insert-file output-filename)
102 ; (delete-file output-filename))))
104 (defun subprocess-command ()
105 "Starts asynchronous subprocess if not running and switches to its window."
107 (if (not subprocess-running
)
109 (and subprocess-running
110 (progn (pop-to-buffer subprocess-buf
) (goto-char (point-max)))))
112 (defun command-send-input ()
113 "If at last line of buffer, sends the current line to
114 the spawned subprocess. Otherwise brings back current
115 line to the last line for resubmission."
118 (let ((current-line (buffer-substring (point)
119 (progn (end-of-line) (point)))))
122 (if (not subprocess-running
)
124 (if subprocess-running
127 (send-command-to-subprocess 1 current-line
)
128 (if command-prefix-string
129 (progn (beginning-of-line) (insert command-prefix-string
)))
131 ;; else -- if not at last line in buffer
135 (if (string-equal command-prefix-string
136 (substring current-line
0 (length command-prefix-string
)))
137 (insert (substring current-line
(length command-prefix-string
)))
138 (insert current-line
)))))
140 (defun command-kill-line()
141 "Kills the current line. Used in command mode."
146 (define-key esc-map
"$" 'subprocess-command
)
148 ;;; arch-tag: 600b2512-f903-4887-bcd2-e76b306f5b66
149 ;;; vmsproc.el ends here