Mercurial > emacs
annotate lisp/vmsproc.el @ 728:2d5acaebbe7e
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Wed, 24 Jun 1992 21:56:16 +0000 |
parents | fec3f9a1e3e5 |
children | 4f28bd14272c |
rev | line source |
---|---|
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
656
diff
changeset
|
1 ;; vmsproc.el --- run asynchronous VMS subprocesses under Emacs |
656
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 (defun subprocess-command-to-buffer (command buffer) | |
72 "Execute COMMAND and redirect output into BUFFER." | |
73 (let (cmd args) | |
74 (setq cmd (substring command 0 (string-match " " command))) | |
75 (setq args (substring command (string-match " " command))) | |
76 (call-process cmd nil buffer nil "*dcl*" args))) | |
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 (concat "SYS$SCRATCH:OUTPUT-FOR-" | |
83 ; (getenv "USER") ".LISTING"))) | |
84 ; (while (file-exists-p output-filename) | |
85 ; (delete-file output-filename)) | |
86 ; (define-logical-name "SYS$OUTPUT" (concat output-filename "-NEW")) | |
87 ; (send-command-to-subprocess 1 command) | |
88 ; (send-command-to-subprocess 1 (concat | |
89 ; "RENAME " output-filename | |
90 ; "-NEW " output-filename)) | |
91 ; (while (not (file-exists-p output-filename)) | |
92 ; (sleep-for 1)) | |
93 ; (define-logical-name "SYS$OUTPUT" nil) | |
94 ; (insert-file output-filename) | |
95 ; (delete-file output-filename)))) | |
96 | |
97 (defun subprocess-command () | |
98 "Starts asynchronous subprocess if not running and switches to its window." | |
99 (interactive) | |
100 (if (not subprocess-running) | |
101 (start-subprocess)) | |
102 (and subprocess-running | |
103 (progn (pop-to-buffer subprocess-buf) (goto-char (point-max))))) | |
104 | |
105 (defun command-send-input () | |
106 "If at last line of buffer, sends the current line to | |
107 the spawned subprocess. Otherwise brings back current | |
108 line to the last line for resubmission." | |
109 (interactive) | |
110 (beginning-of-line) | |
111 (let ((current-line (buffer-substring (point) | |
112 (progn (end-of-line) (point))))) | |
113 (if (eobp) | |
114 (progn | |
115 (if (not subprocess-running) | |
116 (start-subprocess)) | |
117 (if subprocess-running | |
118 (progn | |
119 (beginning-of-line) | |
120 (send-command-to-subprocess 1 current-line) | |
121 (if command-prefix-string | |
122 (progn (beginning-of-line) (insert command-prefix-string))) | |
123 (next-line 1)))) | |
124 ;; else -- if not at last line in buffer | |
125 (end-of-buffer) | |
126 (backward-char) | |
127 (next-line 1) | |
128 (if (string-equal command-prefix-string | |
129 (substring current-line 0 (length command-prefix-string))) | |
130 (insert (substring current-line (length command-prefix-string))) | |
131 (insert current-line))))) | |
132 | |
133 (defun command-kill-line() | |
134 "Kills the current line. Used in command mode." | |
135 (interactive) | |
136 (beginning-of-line) | |
137 (kill-line)) | |
138 | |
139 (define-key esc-map "$" 'subprocess-command) | |
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
656
diff
changeset
|
140 |
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
656
diff
changeset
|
141 ;;; vmsproc.el ends here |