* s/ms-w32.h (MULTI_KBOARD): Remove.
[bpt/emacs.git] / lisp / obsolete / vmsproc.el
CommitLineData
73e72da4 1;; -*- no-byte-compile: t -*-
16952f18
DN
2;; Not byte compiled because it uses functions that are not part of
3;; emacs, so it would generate unnecessary warnings.
e5167999
ER
4;;; vmsproc.el --- run asynchronous VMS subprocesses under Emacs
5
c90f2757 6;; Copyright (C) 1986, 2001, 2002, 2003, 2004, 2005,
409cc4a3 7;; 2006, 2007, 2008 Free Software Foundation, Inc.
58142744 8
e5167999
ER
9;; Author: Mukesh Prasad
10;; Maintainer: FSF
6251ee24 11;; Keywords: vms
76d7458e 12
0d20f9a0
JB
13;; This file is part of GNU Emacs.
14
eb3fa2cf 15;; GNU Emacs is free software: you can redistribute it and/or modify
0d20f9a0 16;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
17;; the Free Software Foundation, either version 3 of the License, or
18;; (at your option) any later version.
0d20f9a0
JB
19
20;; GNU Emacs is distributed in the hope that it will be useful,
21;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23;; GNU General Public License for more details.
24
25;; You should have received a copy of the GNU General Public License
eb3fa2cf 26;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
0d20f9a0 27
55535639
PJ
28;;; Commentary:
29
e5167999 30;;; Code:
0d20f9a0
JB
31
32(defvar display-subprocess-window nil
40198478 33 "If non-nil, the subprocess window is displayed whenever input is received.")
0d20f9a0
JB
34
35(defvar command-prefix-string "$ "
36 "String to insert to distinguish commands entered by user.")
37
38(defvar subprocess-running nil)
6bc52202
SM
39(defvar subprocess-buf nil)
40
ceee4f5d
SM
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)
45 map))
0d20f9a0
JB
46
47(defun subprocess-input (name str)
30cf0c33 48 "Handle input from a subprocess. Called by Emacs."
0d20f9a0
JB
49 (if display-subprocess-window
50 (display-buffer subprocess-buf))
6bc52202 51 (with-current-buffer subprocess-buf
0d20f9a0 52 (goto-char (point-max))
6bc52202 53 (insert str ?\n)))
0d20f9a0
JB
54
55(defun subprocess-exit (name)
56 "Called by Emacs upon subprocess exit."
57 (setq subprocess-running nil))
58
59(defun start-subprocess ()
30cf0c33 60 "Spawn an asynchronous subprocess with output redirected to
0d20f9a0
JB
61the buffer *COMMAND*. Within this buffer, use C-m to send
62the last line to the subprocess or to bring another line to
63the end."
64 (if subprocess-running
65 (return t))
66 (setq subprocess-buf (get-buffer-create "*COMMAND*"))
ceee4f5d 67 (with-current-buffer subprocess-buf
0d20f9a0
JB
68 (use-local-map command-mode-map))
69 (setq subprocess-running (spawn-subprocess 1 'subprocess-input
70 'subprocess-exit))
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")))
75
76(defun subprocess-command-to-buffer (command buffer)
77 "Execute COMMAND and redirect output into BUFFER."
78 (let (cmd args)
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)))
ceee4f5d
SM
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))
96 ;; (sleep-for 1))
97 ;; (define-logical-name "SYS$OUTPUT" nil)
98 ;; (insert-file output-filename)
99 ;; (delete-file output-filename))))
0d20f9a0
JB
100
101(defun subprocess-command ()
30cf0c33 102 "Start asynchronous subprocess if not running and switch to its window."
0d20f9a0
JB
103 (interactive)
104 (if (not subprocess-running)
105 (start-subprocess))
106 (and subprocess-running
107 (progn (pop-to-buffer subprocess-buf) (goto-char (point-max)))))
108
109(defun command-send-input ()
30cf0c33
JB
110 "If at last line of buffer, send the current line to
111the spawned subprocess. Otherwise bring back current
0d20f9a0
JB
112line to the last line for resubmission."
113 (interactive)
114 (beginning-of-line)
ceee4f5d 115 (let ((current-line (buffer-substring (point) (line-end-position))))
0d20f9a0
JB
116 (if (eobp)
117 (progn
118 (if (not subprocess-running)
119 (start-subprocess))
120 (if subprocess-running
121 (progn
122 (beginning-of-line)
123 (send-command-to-subprocess 1 current-line)
124 (if command-prefix-string
125 (progn (beginning-of-line) (insert command-prefix-string)))
97546017 126 (forward-line 1))))
0d20f9a0 127 ;; else -- if not at last line in buffer
ceee4f5d 128 (goto-char (point-max))
0d20f9a0 129 (backward-char)
97546017 130 (forward-line 1)
ceee4f5d
SM
131 (insert
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))
135 current-line)))))
0d20f9a0 136
ceee4f5d 137(defun command-kill-line ()
30cf0c33 138 "Kill the current line. Used in command mode."
0d20f9a0
JB
139 (interactive)
140 (beginning-of-line)
141 (kill-line))
142
143(define-key esc-map "$" 'subprocess-command)
d501f516 144
97546017
DN
145(provide 'vmsproc)
146
ceee4f5d 147;; arch-tag: 600b2512-f903-4887-bcd2-e76b306f5b66
d501f516 148;;; vmsproc.el ends here