1 ;; -*- no-byte-compile: t -*-
2 ;;; vmsproc.el --- run asynchronous VMS subprocesses under Emacs
4 ;; Copyright (C) 1986, 2001, 2002, 2003, 2004, 2005,
5 ;; 2006, 2007 Free Software Foundation, Inc.
7 ;; Author: Mukesh Prasad
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 3, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
32 (defvar display-subprocess-window nil
33 "If non-nil, the subprocess window is displayed whenever input is received.")
35 (defvar command-prefix-string
"$ "
36 "String to insert to distinguish commands entered by user.")
38 (defvar subprocess-running nil
)
39 (defvar subprocess-buf nil
)
41 (defvar command-mode-map
42 (let ((map (make-sparse-keymap)))
43 (define-key map
"\C-m" 'command-send-input
)
44 (define-key map
"\C-u" 'command-kill-line
)
47 (defun subprocess-input (name str
)
48 "Handle input from a subprocess. Called by Emacs."
49 (if display-subprocess-window
50 (display-buffer subprocess-buf
))
51 (with-current-buffer subprocess-buf
52 (goto-char (point-max))
55 (defun subprocess-exit (name)
56 "Called by Emacs upon subprocess exit."
57 (setq subprocess-running nil
))
59 (defun start-subprocess ()
60 "Spawn an asynchronous subprocess with output redirected to
61 the buffer *COMMAND*. Within this buffer, use C-m to send
62 the last line to the subprocess or to bring another line to
64 (if subprocess-running
66 (setq subprocess-buf
(get-buffer-create "*COMMAND*"))
67 (with-current-buffer subprocess-buf
68 (use-local-map command-mode-map
))
69 (setq subprocess-running
(spawn-subprocess 1 'subprocess-input
71 ;; Initialize subprocess so it doesn't panic and die upon
72 ;; encountering the first error.
73 (and subprocess-running
74 (send-command-to-subprocess 1 "ON SEVERE_ERROR THEN CONTINUE")))
76 (defun subprocess-command-to-buffer (command buffer
)
77 "Execute COMMAND and redirect output into BUFFER."
79 (setq cmd
(substring command
0 (string-match " " command
)))
80 (setq args
(substring command
(string-match " " command
)))
81 (call-process cmd nil buffer nil
"*dcl*" args
)))
82 ;; BUGS: only the output up to the end of the first image activation is trapped.
83 ;; (if (not subprocess-running)
84 ;; (start-subprocess))
85 ;; (with-current-buffer buffer
86 ;; (let ((output-filename (concat "SYS$SCRATCH:OUTPUT-FOR-"
87 ;; (getenv "USER") ".LISTING")))
88 ;; (while (file-exists-p output-filename)
89 ;; (delete-file output-filename))
90 ;; (define-logical-name "SYS$OUTPUT" (concat output-filename "-NEW"))
91 ;; (send-command-to-subprocess 1 command)
92 ;; (send-command-to-subprocess 1 (concat
93 ;; "RENAME " output-filename
94 ;; "-NEW " output-filename))
95 ;; (while (not (file-exists-p output-filename))
97 ;; (define-logical-name "SYS$OUTPUT" nil)
98 ;; (insert-file output-filename)
99 ;; (delete-file output-filename))))
101 (defun subprocess-command ()
102 "Start asynchronous subprocess if not running and switch to its window."
104 (if (not subprocess-running
)
106 (and subprocess-running
107 (progn (pop-to-buffer subprocess-buf
) (goto-char (point-max)))))
109 (defun command-send-input ()
110 "If at last line of buffer, send the current line to
111 the spawned subprocess. Otherwise bring back current
112 line to the last line for resubmission."
115 (let ((current-line (buffer-substring (point) (line-end-position))))
118 (if (not subprocess-running
)
120 (if subprocess-running
123 (send-command-to-subprocess 1 current-line
)
124 (if command-prefix-string
125 (progn (beginning-of-line) (insert command-prefix-string
)))
127 ;; else -- if not at last line in buffer
128 (goto-char (point-max))
132 (if (compare-strings command-prefix-string nil nil
133 current-line
0 (length command-prefix-string
))
134 (substring current-line
(length command-prefix-string
))
137 (defun command-kill-line ()
138 "Kill the current line. Used in command mode."
143 (define-key esc-map
"$" 'subprocess-command
)
147 ;; arch-tag: 600b2512-f903-4887-bcd2-e76b306f5b66
148 ;;; vmsproc.el ends here