/[cmucl]/src/hemlock/ts-buf.lisp
ViewVC logotype

Contents of /src/hemlock/ts-buf.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations)
Fri Feb 8 16:38:37 1991 UTC (23 years, 2 months ago) by ram
Branch: MAIN
Changes since 1.3: +8 -5 lines
Added new header with RCS FILE-COMMENT.
1 ram 1.1 ;;; -*- Package: Hemlock; Log: hemlock.log -*-
2     ;;;
3     ;;; **********************************************************************
4 ram 1.4 ;;; This code was written as part of the CMU Common Lisp project at
5     ;;; Carnegie Mellon University, and has been placed in the public domain.
6     ;;; If you want to use this code or any part of CMU Common Lisp, please contact
7     ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
8     ;;;
9     (ext:file-comment
10     "$Header: /tiger/var/lib/cvsroots/cmucl/src/hemlock/ts-buf.lisp,v 1.4 1991/02/08 16:38:37 ram Exp $")
11     ;;;
12 ram 1.1 ;;; **********************************************************************
13     ;;;
14     ;;; This file contains code for processing input to and output from slaves
15     ;;; using typescript streams. It maintains the stuff that hacks on the
16     ;;; typescript buffer and maintains its state.
17     ;;;
18     ;;; Written by William Lott.
19     ;;;
20    
21     (in-package "HEMLOCK")
22    
23    
24     (defhvar "Input Wait Alarm"
25     "When non-nil, the user is informed when a typescript buffer goes into
26     an input wait, and it is not visible. Legal values are :message,
27     :loud-message (the default), and nil."
28     :value :loud-message)
29    
30    
31    
32     ;;;; Structures.
33    
34     (defstruct (ts-data
35     (:print-function
36     (lambda (ts s d)
37     (declare (ignore ts d))
38     (write-string "#<TS Data>" s)))
39     (:constructor
40     make-ts-data (buffer
41     &aux
42     (fill-mark (copy-mark (buffer-end-mark buffer)
43     :right-inserting)))))
44     buffer ; The buffer we are in
45     stream ; Stream in the slave.
46     wire ; Wire to slave
47     server ; Server info struct.
48     fill-mark ; Mark where output goes. This is actually the
49     ; "Buffer Input Mark" which is :right-inserting,
50     ; and we make sure it is :left-inserting for
51     ; inserting output.
52     )
53    
54    
55     ;;;; Output routines.
56    
57     ;;; TS-BUFFER-OUTPUT-STRING --- internal interface.
58     ;;;
59     ;;; Called by the slave to output stuff in the typescript. Can also be called
60     ;;; by other random parts of hemlock when they want to output stuff to the
61     ;;; buffer. Since this is called for value from the slave, we have to be
62     ;;; careful about what values we return, so the result can be sent back. It is
63     ;;; called for value only as a synchronization thing.
64     ;;;
65     ;;; Whenever the output is gratuitous, we want it to go behind the prompt.
66     ;;; When it's gratuitous, and we're not at the line-start, then we can output
67     ;;; it normally, but we also make sure we end the output in a newline for
68     ;;; visibility's sake.
69     ;;;
70     (defun ts-buffer-output-string (ts string &optional gratuitous-p)
71     "Outputs STRING to the typescript described with TS. The output is inserted
72     before the fill-mark and the current input."
73     (when (wire:remote-object-p ts)
74     (setf ts (wire:remote-object-value ts)))
75     (system:without-interrupts
76     (let ((mark (ts-data-fill-mark ts)))
77     (cond ((and gratuitous-p (not (start-line-p mark)))
78     (with-mark ((m mark :left-inserting))
79     (line-start m)
80     (insert-string m string)
81     (unless (start-line-p m)
82     (insert-character m #\newline))))
83     (t
84     (setf (mark-kind mark) :left-inserting)
85     (insert-string mark string)
86     (when (and gratuitous-p (not (start-line-p mark)))
87     (insert-character mark #\newline))
88     (setf (mark-kind mark) :right-inserting)))))
89     (values))
90    
91     ;;; TS-BUFFER-FINISH-OUTPUT --- internal interface.
92     ;;;
93     ;;; Redisplays the windows. Used by ts-stream in order to finish-output.
94     ;;;
95     (defun ts-buffer-finish-output (ts)
96     (declare (ignore ts))
97     (redisplay)
98     nil)
99    
100     ;;; TS-BUFFER-CHARPOS --- internal interface.
101     ;;;
102     ;;; Used by ts-stream in order to find the charpos.
103     ;;;
104     (defun ts-buffer-charpos (ts)
105     (mark-charpos (ts-data-fill-mark (if (wire:remote-object-p ts)
106     (wire:remote-object-value ts)
107     ts))))
108    
109     ;;; TS-BUFFER-LINE-LENGTH --- internal interface.
110     ;;;
111     ;;; Used by ts-stream to find out the line length. Returns the width of the
112     ;;; first window, or 80 if there are no windows.
113     ;;;
114     (defun ts-buffer-line-length (ts)
115     (let* ((ts (if (wire:remote-object-p ts)
116     (wire:remote-object-value ts)
117     ts))
118     (window (car (buffer-windows (ts-data-buffer ts)))))
119     (if window
120     (window-width window)
121     80))) ; Seems like a good number to me.
122    
123    
124     ;;;; Input routines
125    
126     (defun ts-buffer-ask-for-input (remote)
127     (let* ((ts (wire:remote-object-value remote))
128     (buffer (ts-data-buffer ts)))
129     (unless (buffer-windows buffer)
130     (let ((input-wait-alarm
131     (if (hemlock-bound-p 'input-wait-alarm
132     :buffer buffer)
133     (variable-value 'input-wait-alarm
134     :buffer buffer)
135     (variable-value 'input-wait-alarm
136     :global))))
137     (when input-wait-alarm
138     (when (eq input-wait-alarm :loud-message)
139     (beep))
140     (message "Waiting for input in buffer ~A."
141     (buffer-name buffer))))))
142     nil)
143    
144     (defun ts-buffer-clear-input (ts)
145     (let* ((ts (if (wire:remote-object-p ts)
146     (wire:remote-object-value ts)
147     ts))
148     (buffer (ts-data-buffer ts))
149     (mark (ts-data-fill-mark ts)))
150     (unless (mark= mark (buffer-end-mark buffer))
151     (with-mark ((start mark))
152     (line-start start)
153     (let ((prompt (region-to-string (region start mark)))
154     (end (buffer-end-mark buffer)))
155     (unless (zerop (mark-charpos end))
156     (insert-character end #\Newline))
157     (insert-string end "[Input Cleared]")
158     (insert-character end #\Newline)
159     (insert-string end prompt)
160     (move-mark mark end)))))
161     nil)
162    
163     (defun ts-buffer-set-stream (ts stream)
164 ram 1.3 (let ((ts (if (wire:remote-object-p ts)
165     (wire:remote-object-value ts)
166     ts)))
167     (setf (ts-data-stream ts) stream)
168     (wire:remote (ts-data-wire ts)
169     (ts-stream-set-line-length (ts-buffer-line-length ts))))
170 ram 1.1 nil)
171    
172    
173     ;;;; Typescript mode.
174    
175     (defun setup-typescript (buffer)
176     (let ((ts (make-ts-data buffer)))
177     (defhvar "Current Package"
178     "The package used for evaluation of Lisp in this buffer."
179     :buffer buffer
180     :value nil)
181    
182     (defhvar "Typescript Data"
183     "The ts-data structure for this buffer"
184     :buffer buffer
185     :value ts)
186    
187     (defhvar "Buffer Input Mark"
188     "Beginning of typescript input in this buffer."
189     :value (ts-data-fill-mark ts)
190     :buffer buffer)
191    
192     (defhvar "Interactive History"
193     "A ring of the regions input to the Hemlock typescript."
194     :buffer buffer
195     :value (make-ring (value interactive-history-length)))
196    
197     (defhvar "Interactive Pointer"
198     "Pointer into the Hemlock typescript input history."
199     :buffer buffer
200     :value 0)
201    
202     (defhvar "Searching Interactive Pointer"
203     "Pointer into \"Interactive History\"."
204     :buffer buffer
205     :value 0)))
206    
207     (defmode "Typescript"
208     :setup-function #'setup-typescript
209     :documentation "The Typescript mode is used to interact with slave lisps.")
210    
211     ;;; TYPESCRIPTIFY-BUFFER -- Internal interface.
212     ;;;
213     ;;; Buffer creation code for eval server connections calls this to setup a
214     ;;; typescript buffer, tie things together, and make some local Hemlock
215     ;;; variables.
216     ;;;
217     (defun typescriptify-buffer (buffer server wire)
218     (setf (buffer-minor-mode buffer "Typescript") t)
219     (let ((info (variable-value 'typescript-data :buffer buffer)))
220     (setf (ts-data-server info) server)
221     (setf (ts-data-wire info) wire)
222     (defhvar "Server Info"
223     "Server-info structure for this buffer."
224     :buffer buffer :value server)
225     (defhvar "Current Eval Server"
226     "The Server-Info object for the server currently used for evaluation and
227     compilation."
228     :buffer buffer :value server)
229     info))
230    
231     (defun ts-buffer-wire-died (ts)
232     (setf (ts-data-stream ts) nil)
233     (setf (ts-data-wire ts) nil)
234     (buffer-end (ts-data-fill-mark ts) (ts-data-buffer ts))
235     (ts-buffer-output-string ts (format nil "~%~%Slave died!~%")))
236    
237     (defun unwedge-typescript-buffer ()
238     (typescript-slave-to-top-level-command nil)
239     (buffer-end (current-point) (current-buffer)))
240    
241     (defhvar "Unwedge Interactive Input Fun"
242     "Function to call when input is confirmed, but the point is not past the
243     input mark."
244     :value #'unwedge-typescript-buffer
245     :mode "Typescript")
246    
247     (defhvar "Unwedge Interactive Input String"
248     "String to add to \"Point not past input mark. \" explaining what will
249     happen if the the user chooses to be unwedged."
250     :value "Cause the slave to throw to the top level? "
251     :mode "Typescript")
252    
253 ram 1.2 ;;; TYPESCRIPT-DATA-OR-LOSE -- internal
254     ;;;
255     ;;; Return the typescript-data for the current buffer, or die trying.
256     ;;;
257     (defun typescript-data-or-lose ()
258     (if (hemlock-bound-p 'typescript-data)
259     (let ((ts (value typescript-data)))
260     (if ts
261     ts
262     (editor-error "Can't find the typescript data?")))
263     (editor-error "Not in a typescript buffer.")))
264    
265 ram 1.1 (defcommand "Confirm Typescript Input" (p)
266     "Send the current input to the slave typescript."
267     "Send the current input to the slave typescript."
268     (declare (ignore p))
269 ram 1.2 (let ((ts (typescript-data-or-lose)))
270 ram 1.1 (let ((input (get-interactive-input)))
271     (when input
272     (let ((string (region-to-string input)))
273     (declare (simple-string string))
274     (insert-character (current-point) #\NewLine)
275     (wire:remote (ts-data-wire ts)
276     (ts-stream-accept-input (ts-data-stream ts)
277     (concatenate 'simple-string
278     string
279     (string #\newline))))
280     (wire:wire-force-output (ts-data-wire ts))
281     (buffer-end (ts-data-fill-mark ts)
282     (ts-data-buffer ts)))))))
283    
284     (defcommand "Typescript Slave Break" (p)
285     "Interrupt the slave Lisp process associated with this interactive buffer,
286     causing it to invoke BREAK."
287     "Interrupt the slave Lisp process associated with this interactive buffer,
288     causing it to invoke BREAK."
289     (declare (ignore p))
290     (send-oob-to-slave "B"))
291    
292     (defcommand "Typescript Slave to Top Level" (p)
293     "Interrupt the slave Lisp process associated with this interactive buffer,
294     causing it to throw to the top level REP loop."
295     "Interrupt the slave Lisp process associated with this interactive buffer,
296     causing it to throw to the top level REP loop."
297     (declare (ignore p))
298     (send-oob-to-slave "T"))
299    
300     (defun send-oob-to-slave (string)
301 ram 1.2 (let* ((ts (typescript-data-or-lose))
302 ram 1.1 (wire (ts-data-wire ts))
303     (socket (wire:wire-fd wire)))
304     (unless socket
305     (editor-error "The slave is no longer alive."))
306     (ext:send-character-out-of-band socket (schar string 0))))

  ViewVC Help
Powered by ViewVC 1.1.5