Mercurial > emacs
annotate lisp/=vmsx.el @ 742:7704767cd8d2
entered into RCS
author | Charles Hannum <mycroft@gnu.org> |
---|---|
date | Mon, 06 Jul 1992 00:46:31 +0000 |
parents | d74e65773062 |
children | 4f28bd14272c |
rev | line source |
---|---|
656
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
1 ;;; vmsx.el --- run asynchronous VMS subprocesses under Emacs |
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
2 |
35 | 3 ;; Copyright (C) 1986 Free Software Foundation, Inc. |
4 | |
5 ;; This file is part of GNU Emacs. | |
6 | |
7 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
8 ;; it under the terms of the GNU General Public License as published by | |
9 ;; the Free Software Foundation; either version 1, or (at your option) | |
10 ;; any later version. | |
11 | |
12 ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 ;; GNU General Public License for more details. | |
16 | |
17 ;; You should have received a copy of the GNU General Public License | |
18 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | |
21 ;; Written by Mukesh Prasad. | |
22 | |
23 (defvar display-subprocess-window nil | |
24 "If non-nil, the suprocess window is displayed whenever input is received.") | |
25 | |
26 (defvar command-prefix-string "$ " | |
27 "String to insert to distinguish commands entered by user.") | |
28 | |
29 (defvar subprocess-running nil) | |
30 (defvar command-mode-map nil) | |
31 | |
32 (if command-mode-map | |
33 nil | |
34 (setq command-mode-map (make-sparse-keymap)) | |
35 (define-key command-mode-map "\C-m" 'command-send-input) | |
36 (define-key command-mode-map "\C-u" 'command-kill-line)) | |
37 | |
38 (defun subprocess-input (name str) | |
39 "Handles input from a subprocess. Called by Emacs." | |
40 (if display-subprocess-window | |
41 (display-buffer subprocess-buf)) | |
42 (let ((old-buffer (current-buffer))) | |
43 (set-buffer subprocess-buf) | |
44 (goto-char (point-max)) | |
45 (insert str) | |
46 (insert ?\n) | |
47 (set-buffer old-buffer))) | |
48 | |
49 (defun subprocess-exit (name) | |
50 "Called by Emacs upon subprocess exit." | |
51 (setq subprocess-running nil)) | |
52 | |
53 (defun start-subprocess () | |
54 "Spawns an asynchronous subprocess with output redirected to | |
55 the buffer *COMMAND*. Within this buffer, use C-m to send | |
56 the last line to the subprocess or to bring another line to | |
57 the end." | |
58 (if subprocess-running | |
59 (return t)) | |
60 (setq subprocess-buf (get-buffer-create "*COMMAND*")) | |
61 (save-excursion | |
62 (set-buffer subprocess-buf) | |
63 (use-local-map command-mode-map)) | |
64 (setq subprocess-running (spawn-subprocess 1 'subprocess-input | |
65 'subprocess-exit)) | |
66 ;; Initialize subprocess so it doesn't panic and die upon | |
67 ;; encountering the first error. | |
68 (and subprocess-running | |
69 (send-command-to-subprocess 1 "ON SEVERE_ERROR THEN CONTINUE"))) | |
70 | |
71 (defvar subprocess-command-to-buffer-tmpdir "SYS$SCRATCH:" | |
72 "*Put temporary files from subprocess-command-to-buffer here.") | |
73 | |
74 (defun subprocess-command-to-buffer (command buffer) | |
75 "Execute command and redirect output into buffer. | |
76 | |
77 BUGS: only the output up to the end of the first image activation is trapped." | |
78 (if (not subprocess-running) | |
79 (start-subprocess)) | |
80 (save-excursion | |
81 (set-buffer buffer) | |
82 (let ((output-filename | |
83 (concat subprocess-command-to-buffer-tmpdir | |
84 "OUTPUT-FOR-" (getenv "USER") ".LISTING"))) | |
85 (while (file-attributes output-filename) | |
86 (delete-file output-filename)) | |
87 (send-command-to-subprocess 1 (concat "DEFINE/USER SYS$OUTPUT " | |
88 output-filename "-NEW")) | |
89 (send-command-to-subprocess 1 command) | |
90 (send-command-to-subprocess 1 (concat "RENAME " output-filename | |
91 "-NEW " output-filename)) | |
92 (while (not (file-attributes output-filename)) | |
93 (sleep-for 2)) | |
94 (insert-file output-filename)))) | |
95 | |
96 (defun subprocess-command () | |
97 "Starts asynchronous subprocess if not running and switches to its window." | |
98 (interactive) | |
99 (if (not subprocess-running) | |
100 (start-subprocess)) | |
101 (and subprocess-running | |
102 (progn (pop-to-buffer subprocess-buf) (goto-char (point-max))))) | |
103 | |
104 (defun command-send-input () | |
105 "If at last line of buffer, sends the current line to | |
106 the spawned subprocess. Otherwise brings back current | |
107 line to the last line for resubmission." | |
108 (interactive) | |
109 (beginning-of-line) | |
110 (let ((current-line (buffer-substring (point) | |
111 (progn (end-of-line) (point))))) | |
112 (if (eobp) | |
113 (progn | |
114 (if (not subprocess-running) | |
115 (start-subprocess)) | |
116 (if subprocess-running | |
117 (progn | |
118 (beginning-of-line) | |
119 (send-command-to-subprocess 1 current-line) | |
120 (if command-prefix-string | |
121 (progn (beginning-of-line) (insert command-prefix-string))) | |
122 (next-line 1)))) | |
123 ;; else -- if not at last line in buffer | |
124 (end-of-buffer) | |
125 (backward-char) | |
126 (next-line 1) | |
127 (if (string-equal command-prefix-string | |
128 (substring current-line 0 (length command-prefix-string))) | |
129 (insert (substring current-line (length command-prefix-string))) | |
130 (insert current-line))))) | |
131 | |
132 (defun command-kill-line() | |
133 "Kills the current line. Used in command mode." | |
134 (interactive) | |
135 (beginning-of-line) | |
136 (kill-line)) | |
137 | |
138 (define-key esc-map "$" 'subprocess-command) | |
656
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
139 |
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
140 ;;; vmsx.el ends here |