Revert the change of 2003-07-29 as GTK+ 2.2 is not required anymore.
[emacs.git] / lisp / vmsproc.el
blob14f9b2903addb40444c75048d5779bbe569f070d
1 ;;; vmsproc.el --- run asynchronous VMS subprocesses under Emacs
3 ;; Copyright (C) 1986 Free Software Foundation, Inc.
5 ;; Author: Mukesh Prasad
6 ;; Maintainer: FSF
7 ;; Keywords: vms
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)
14 ;; any later version.
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.
26 ;;; Commentary:
28 ;;; Code:
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)
39 (if command-mode-map
40 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))
52 (insert str)
53 (insert ?\n)
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
64 the end."
65 (if subprocess-running
66 (return t))
67 (setq subprocess-buf (get-buffer-create "*COMMAND*"))
68 (save-excursion
69 (set-buffer subprocess-buf)
70 (use-local-map command-mode-map))
71 (setq subprocess-running (spawn-subprocess 1 'subprocess-input
72 'subprocess-exit))
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."
80 (let (cmd args)
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)
86 ; (start-subprocess))
87 ; (save-excursion
88 ; (set-buffer buffer)
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))
99 ; (sleep-for 1))
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."
106 (interactive)
107 (if (not subprocess-running)
108 (start-subprocess))
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."
116 (interactive)
117 (beginning-of-line)
118 (let ((current-line (buffer-substring (point)
119 (progn (end-of-line) (point)))))
120 (if (eobp)
121 (progn
122 (if (not subprocess-running)
123 (start-subprocess))
124 (if subprocess-running
125 (progn
126 (beginning-of-line)
127 (send-command-to-subprocess 1 current-line)
128 (if command-prefix-string
129 (progn (beginning-of-line) (insert command-prefix-string)))
130 (next-line 1))))
131 ;; else -- if not at last line in buffer
132 (end-of-buffer)
133 (backward-char)
134 (next-line 1)
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."
142 (interactive)
143 (beginning-of-line)
144 (kill-line))
146 (define-key esc-map "$" 'subprocess-command)
148 ;;; vmsproc.el ends here