*** empty log message ***
[bpt/emacs.git] / lisp / progmodes / xscheme.el
CommitLineData
c5c3d778
DL
1;;; xscheme.el --- run MIT Scheme under Emacs
2
ae940284
GM
3;; Copyright (C) 1986, 1987, 1989, 1990, 2001, 2002, 2003, 2004, 2005,
4;; 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
c5c3d778
DL
5
6;; Maintainer: FSF
7;; Keywords: languages, lisp
8
9;; This file is part of GNU Emacs.
10
b1fc2b50 11;; GNU Emacs is free software: you can redistribute it and/or modify
c5c3d778 12;; it under the terms of the GNU General Public License as published by
b1fc2b50
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
c5c3d778
DL
15
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.
20
21;; You should have received a copy of the GNU General Public License
b1fc2b50 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
c5c3d778
DL
23
24;;; Commentary:
25
26;; A major mode for interacting with MIT Scheme.
27;;
28;; Requires MIT Scheme release 5 or later.
29;; Changes to Control-G handler require runtime version 13.85 or later.
30
31;;; Code:
32
33(require 'scheme)
f28d4b0f
JB
34
35;;;; Internal Variables
36
37(defvar xscheme-previous-mode)
38(defvar xscheme-previous-process-state)
39(defvar xscheme-last-input-end)
40
41(defvar xscheme-process-command-line nil
42 "Command used to start the most recent Scheme process.")
43
44(defvar xscheme-process-name "scheme"
45 "Name of xscheme process that we're currently interacting with.")
46
47(defvar xscheme-buffer-name "*scheme*"
48 "Name of xscheme buffer that we're currently interacting with.")
49
50(defvar xscheme-expressions-ring-max 30
51 "*Maximum length of Scheme expressions ring.")
52
53(defvar xscheme-expressions-ring nil
54 "List of expressions recently transmitted to the Scheme process.")
55
56(defvar xscheme-expressions-ring-yank-pointer nil
57 "The tail of the Scheme expressions ring whose car is the last thing yanked.")
58
59(defvar xscheme-running-p nil
60 "This variable, if nil, indicates that the scheme process is
61waiting for input. Otherwise, it is busy evaluating something.")
62
63(defconst xscheme-control-g-synchronization-p t
64 "If non-nil, insert markers in the scheme input stream to indicate when
65control-g interrupts were signaled. Do not allow more control-g's to be
66signaled until the scheme process acknowledges receipt.")
67
68(defvar xscheme-control-g-disabled-p nil
69 "This variable, if non-nil, indicates that a control-g is being processed
70by the scheme process, so additional control-g's are to be ignored.")
71
72(defvar xscheme-string-receiver nil
73 "Procedure to send the string argument from the scheme process.")
74
75(defconst default-xscheme-runlight
76 '(": " xscheme-runlight-string)
77 "Default global (shared) xscheme-runlight modeline format.")
78
79(defvar xscheme-runlight "")
80(defvar xscheme-runlight-string nil)
81
82(defvar xscheme-process-filter-state 'idle
83 "State of scheme process escape reader state machine:
84idle waiting for an escape sequence
85reading-type received an altmode but nothing else
86reading-string reading prompt string")
87
88(defvar xscheme-allow-output-p t
89 "This variable, if nil, prevents output from the scheme process
90from being inserted into the process-buffer.")
91
92(defvar xscheme-prompt ""
93 "The current scheme prompt string.")
94
95(defvar xscheme-string-accumulator ""
96 "Accumulator for the string being received from the scheme process.")
97
98(defvar xscheme-mode-string nil)
99(setq-default scheme-mode-line-process
100 '("" xscheme-runlight))
101
e2c527c5
JB
102(mapc 'make-variable-buffer-local
103 '(xscheme-expressions-ring
104 xscheme-expressions-ring-yank-pointer
105 xscheme-process-filter-state
106 xscheme-running-p
107 xscheme-control-g-disabled-p
108 xscheme-allow-output-p
109 xscheme-prompt
110 xscheme-string-accumulator
111 xscheme-mode-string
112 scheme-mode-line-process))
c5c3d778
DL
113\f
114(defgroup xscheme nil
115 "Major mode for editing Scheme and interacting with MIT's C-Scheme."
116 :group 'lisp)
117
118(defcustom scheme-band-name nil
119 "*Band loaded by the `run-scheme' command."
120 :type '(choice (const nil) string)
121 :group 'xscheme)
122
123(defcustom scheme-program-arguments nil
124 "*Arguments passed to the Scheme program by the `run-scheme' command."
125 :type '(choice (const nil) string)
126 :group 'xscheme)
127
128(defcustom xscheme-allow-pipelined-evaluation t
129 "If non-nil, an expression may be transmitted while another is evaluating.
130Otherwise, attempting to evaluate an expression before the previous expression
131has finished evaluating will signal an error."
132 :type 'boolean
133 :group 'xscheme)
134
135(defcustom xscheme-startup-message
136 "This is the Scheme process buffer.
8cb95edf 137Type \\[xscheme-send-previous-expression] to evaluate the expression before point.
c5c3d778
DL
138Type \\[xscheme-send-control-g-interrupt] to abort evaluation.
139Type \\[describe-mode] for more information.
140
141"
142 "String to insert into Scheme process buffer first time it is started.
143Is processed with `substitute-command-keys' first."
144 :type 'string
145 :group 'xscheme)
146
147(defcustom xscheme-signal-death-message nil
148 "If non-nil, causes a message to be generated when the Scheme process dies."
149 :type 'boolean
150 :group 'xscheme)
151
152(defcustom xscheme-start-hook nil
153 "If non-nil, a procedure to call when the Scheme process is started.
154When called, the current buffer will be the Scheme process-buffer."
155 :type 'hook
156 :group 'xscheme
157 :version "20.3")
158
159(defun xscheme-evaluation-commands (keymap)
160 (define-key keymap "\e\C-x" 'xscheme-send-definition)
8cb95edf
SM
161 (define-key keymap "\C-x\C-e" 'xscheme-send-previous-expression)
162 (put 'xscheme-send-previous-expression :advertised-binding "\C-x\C-e")
c5c3d778
DL
163 (define-key keymap "\eo" 'xscheme-send-buffer)
164 (define-key keymap "\ez" 'xscheme-send-definition)
165 (define-key keymap "\e\C-m" 'xscheme-send-previous-expression)
166 (define-key keymap "\e\C-z" 'xscheme-send-region))
167
168(defun xscheme-interrupt-commands (keymap)
169 (define-key keymap "\C-c\C-s" 'xscheme-select-process-buffer)
170 (define-key keymap "\C-c\C-b" 'xscheme-send-breakpoint-interrupt)
171 (define-key keymap "\C-c\C-c" 'xscheme-send-control-g-interrupt)
172 (define-key keymap "\C-c\C-u" 'xscheme-send-control-u-interrupt)
173 (define-key keymap "\C-c\C-x" 'xscheme-send-control-x-interrupt))
174
175(xscheme-evaluation-commands scheme-mode-map)
176(xscheme-interrupt-commands scheme-mode-map)
177\f
178(defun run-scheme (command-line)
179 "Run MIT Scheme in an inferior process.
180Output goes to the buffer `*scheme*'.
181With argument, asks for a command line."
182 (interactive (list (xscheme-read-command-line current-prefix-arg)))
183 (xscheme-start command-line xscheme-process-name xscheme-buffer-name))
184
185(defun xscheme-start (command-line process-name buffer-name)
186 (setq-default xscheme-process-command-line command-line)
187 (switch-to-buffer
188 (xscheme-start-process command-line process-name buffer-name))
189 (make-local-variable 'xscheme-process-command-line)
190 (setq xscheme-process-command-line command-line))
191
192(defun xscheme-read-command-line (arg)
193 (let ((default
194 (or xscheme-process-command-line
195 (xscheme-default-command-line))))
196 (if arg
197 (read-string "Run Scheme: " default)
198 default)))
199
200(defun xscheme-default-command-line ()
201 (concat scheme-program-name " -emacs"
202 (if scheme-program-arguments
203 (concat " " scheme-program-arguments)
204 "")
205 (if scheme-band-name
206 (concat " -band " scheme-band-name)
207 "")))
208
209(defun reset-scheme ()
210 "Reset the Scheme process."
211 (interactive)
212 (let ((process (get-process xscheme-process-name)))
213 (cond ((or (not process)
214 (not (eq (process-status process) 'run))
215 (yes-or-no-p
216"The Scheme process is running, are you SURE you want to reset it? "))
217 (message "Resetting Scheme process...")
218 (if process
219 (progn
220 (kill-process process t)
221 (delete-process process)))
222 (xscheme-start-process xscheme-process-command-line
223 xscheme-process-name
224 xscheme-buffer-name)
225 (message "Resetting Scheme process...done")))))
226\f
227;;;; Multiple Scheme buffer management commands
228
229(defun start-scheme (buffer-name &optional globally)
230 "Choose a scheme interaction buffer, or create a new one."
231 ;; (interactive "BScheme interaction buffer: \nP")
232 (interactive
233 (list (read-buffer "Scheme interaction buffer: "
234 xscheme-buffer-name
235 nil)
236 current-prefix-arg))
237 (let ((buffer (get-buffer-create buffer-name)))
238 (let ((process (get-buffer-process buffer)))
239 (if process
240 (switch-to-buffer buffer)
241 (if (or (not (buffer-file-name buffer))
242 (yes-or-no-p (concat "Buffer "
243 (buffer-name buffer)
244 " contains file "
245 (buffer-file-name buffer)
246 "; start scheme in it? ")))
247 (progn
248 (xscheme-start (xscheme-read-command-line t)
249 buffer-name
250 buffer-name)
251 (if globally
252 (global-set-scheme-interaction-buffer buffer-name)))
253 (message "start-scheme aborted"))))))
254
255(fset 'select-scheme 'start-scheme)
256
257(defun global-set-scheme-interaction-buffer (buffer-name)
258 "Set the default scheme interaction buffer."
259 (interactive
260 (list (read-buffer "Scheme interaction buffer: "
261 xscheme-buffer-name
262 t)))
263 (let ((process-name (verify-xscheme-buffer buffer-name nil)))
264 (setq-default xscheme-buffer-name buffer-name)
265 (setq-default xscheme-process-name process-name)
266 (setq-default xscheme-runlight-string
267 (save-excursion (set-buffer buffer-name)
268 xscheme-runlight-string))
269 (setq-default xscheme-runlight
270 (if (eq (process-status process-name) 'run)
271 default-xscheme-runlight
272 ""))))
273
274(defun local-set-scheme-interaction-buffer (buffer-name)
275 "Set the scheme interaction buffer for the current buffer."
276 (interactive
277 (list (read-buffer "Scheme interaction buffer: "
278 xscheme-buffer-name
279 t)))
280 (let ((process-name (verify-xscheme-buffer buffer-name t)))
281 (make-local-variable 'xscheme-buffer-name)
282 (setq xscheme-buffer-name buffer-name)
283 (make-local-variable 'xscheme-process-name)
284 (setq xscheme-process-name process-name)
285 (make-local-variable 'xscheme-runlight)
286 (setq xscheme-runlight (save-excursion (set-buffer buffer-name)
287 xscheme-runlight))))
288
289(defun local-clear-scheme-interaction-buffer ()
290 "Make the current buffer use the default scheme interaction buffer."
291 (interactive)
292 (if (xscheme-process-buffer-current-p)
293 (error "Cannot change the interaction buffer of an interaction buffer"))
294 (kill-local-variable 'xscheme-buffer-name)
295 (kill-local-variable 'xscheme-process-name)
296 (kill-local-variable 'xscheme-runlight))
297
298(defun verify-xscheme-buffer (buffer-name localp)
299 (if (and localp (xscheme-process-buffer-current-p))
300 (error "Cannot change the interaction buffer of an interaction buffer"))
301 (let* ((buffer (get-buffer buffer-name))
302 (process (and buffer (get-buffer-process buffer))))
303 (cond ((not buffer)
ac72d80b 304 (error "Buffer `%s' does not exist" buffer-name))
c5c3d778 305 ((not process)
ac72d80b 306 (error "Buffer `%s' is not a scheme interaction buffer" buffer-name))
c5c3d778
DL
307 (t
308 (save-excursion
309 (set-buffer buffer)
310 (if (not (xscheme-process-buffer-current-p))
ac72d80b 311 (error "Buffer `%s' is not a scheme interaction buffer"
c5c3d778
DL
312 buffer-name)))
313 (process-name process)))))
314\f
315;;;; Interaction Mode
316
317(defun scheme-interaction-mode (&optional preserve)
318 "Major mode for interacting with an inferior MIT Scheme process.
319Like scheme-mode except that:
320
8cb95edf 321\\[xscheme-send-previous-expression] sends the expression before point to the Scheme process as input
c5c3d778
DL
322\\[xscheme-yank-pop] yanks an expression previously sent to Scheme
323\\[xscheme-yank-push] yanks an expression more recently sent to Scheme
324
325All output from the Scheme process is written in the Scheme process
326buffer, which is initially named \"*scheme*\". The result of
327evaluating a Scheme expression is also printed in the process buffer,
328preceded by the string \";Value: \" to highlight it. If the process
329buffer is not visible at that time, the value will also be displayed
330in the minibuffer. If an error occurs, the process buffer will
331automatically pop up to show you the error message.
332
333While the Scheme process is running, the modelines of all buffers in
334scheme-mode are modified to show the state of the process. The
335possible states and their meanings are:
336
337input waiting for input
338run evaluating
339gc garbage collecting
340
341The process buffer's modeline contains additional information where
342the buffer's name is normally displayed: the command interpreter level
343and type.
344
345Scheme maintains a stack of command interpreters. Every time an error
346or breakpoint occurs, the current command interpreter is pushed on the
347command interpreter stack, and a new command interpreter is started.
348One example of why this is done is so that an error that occurs while
349you are debugging another error will not destroy the state of the
350initial error, allowing you to return to it after the second error has
351been fixed.
352
353The command interpreter level indicates how many interpreters are in
354the command interpreter stack. It is initially set to one, and it is
355incremented every time that stack is pushed, and decremented every
356time it is popped. The following commands are useful for manipulating
357the command interpreter stack:
358
359\\[xscheme-send-breakpoint-interrupt] pushes the stack once
360\\[xscheme-send-control-u-interrupt] pops the stack once
361\\[xscheme-send-control-g-interrupt] pops everything off
362\\[xscheme-send-control-x-interrupt] aborts evaluation, doesn't affect stack
363
364Some possible command interpreter types and their meanings are:
365
366\[Evaluator] read-eval-print loop for evaluating expressions
367\[Debugger] single character commands for debugging errors
368\[Where] single character commands for examining environments
369
370Starting with release 6.2 of Scheme, the latter two types of command
371interpreters will change the major mode of the Scheme process buffer
372to scheme-debugger-mode , in which the evaluation commands are
373disabled, and the keys which normally self insert instead send
374themselves to the Scheme process. The command character ? will list
375the available commands.
376
377For older releases of Scheme, the major mode will be be
378scheme-interaction-mode , and the command characters must be sent as
379if they were expressions.
380
381Commands:
382Delete converts tabs to spaces as it moves back.
383Blank lines separate paragraphs. Semicolons start comments.
384\\{scheme-interaction-mode-map}
385
386Entry to this mode calls the value of scheme-interaction-mode-hook
387with no args, if that value is non-nil.
388 Likewise with the value of scheme-mode-hook.
389 scheme-interaction-mode-hook is called after scheme-mode-hook."
390 (interactive "P")
391 (if (not preserve)
392 (let ((previous-mode major-mode))
393 (kill-all-local-variables)
394 (make-local-variable 'xscheme-previous-mode)
395 (make-local-variable 'xscheme-buffer-name)
396 (make-local-variable 'xscheme-process-name)
397 (make-local-variable 'xscheme-previous-process-state)
398 (make-local-variable 'xscheme-runlight-string)
399 (make-local-variable 'xscheme-runlight)
400 (make-local-variable 'xscheme-last-input-end)
401 (setq xscheme-previous-mode previous-mode)
402 (let ((buffer (current-buffer)))
403 (setq xscheme-buffer-name (buffer-name buffer))
404 (setq xscheme-last-input-end (make-marker))
405 (let ((process (get-buffer-process buffer)))
406 (if process
407 (progn
408 (setq xscheme-process-name (process-name process))
409 (setq xscheme-previous-process-state
410 (cons (process-filter process)
411 (process-sentinel process)))
412 (xscheme-process-filter-initialize t)
413 (xscheme-modeline-initialize xscheme-buffer-name)
414 (set-process-sentinel process 'xscheme-process-sentinel)
415 (set-process-filter process 'xscheme-process-filter))
416 (setq xscheme-previous-process-state (cons nil nil)))))))
417 (scheme-interaction-mode-initialize)
418 (scheme-mode-variables)
9a969196 419 (run-mode-hooks 'scheme-mode-hook 'scheme-interaction-mode-hook))
c5c3d778
DL
420
421(defun exit-scheme-interaction-mode ()
422 "Take buffer out of scheme interaction mode"
423 (interactive)
424 (if (not (eq major-mode 'scheme-interaction-mode))
425 (error "Buffer not in scheme interaction mode"))
426 (let ((previous-state xscheme-previous-process-state))
427 (funcall xscheme-previous-mode)
428 (let ((process (get-buffer-process (current-buffer))))
429 (if process
430 (progn
431 (if (eq (process-filter process) 'xscheme-process-filter)
432 (set-process-filter process (car previous-state)))
433 (if (eq (process-sentinel process) 'xscheme-process-sentinel)
434 (set-process-sentinel process (cdr previous-state))))))))
435
f28d4b0f
JB
436(defvar scheme-interaction-mode-commands-alist nil)
437(defvar scheme-interaction-mode-map nil)
438
c5c3d778
DL
439(defun scheme-interaction-mode-initialize ()
440 (use-local-map scheme-interaction-mode-map)
441 (setq major-mode 'scheme-interaction-mode)
442 (setq mode-name "Scheme Interaction"))
443
444(defun scheme-interaction-mode-commands (keymap)
445 (let ((entries scheme-interaction-mode-commands-alist))
446 (while entries
447 (define-key keymap
448 (car (car entries))
449 (car (cdr (car entries))))
450 (setq entries (cdr entries)))))
451
f28d4b0f 452;; Initialize the command alist
c5c3d778
DL
453(setq scheme-interaction-mode-commands-alist
454 (append scheme-interaction-mode-commands-alist
455 '(("\C-c\C-m" xscheme-send-current-line)
456 ("\C-c\C-o" xscheme-delete-output)
457 ("\C-c\C-p" xscheme-send-proceed)
458 ("\C-c\C-y" xscheme-yank)
459 ("\ep" xscheme-yank-pop)
460 ("\en" xscheme-yank-push))))
461
f28d4b0f 462;; Initialize the mode map
c5c3d778
DL
463(if (not scheme-interaction-mode-map)
464 (progn
465 (setq scheme-interaction-mode-map (make-keymap))
466 (scheme-mode-commands scheme-interaction-mode-map)
467 (xscheme-interrupt-commands scheme-interaction-mode-map)
468 (xscheme-evaluation-commands scheme-interaction-mode-map)
469 (scheme-interaction-mode-commands scheme-interaction-mode-map)))
470
471(defun xscheme-enter-interaction-mode ()
472 (save-excursion
473 (set-buffer (xscheme-process-buffer))
474 (if (not (eq major-mode 'scheme-interaction-mode))
475 (if (eq major-mode 'scheme-debugger-mode)
476 (scheme-interaction-mode-initialize)
477 (scheme-interaction-mode t)))))
478
8cb95edf
SM
479(define-obsolete-function-alias 'advertised-xscheme-send-previous-expression
480 'xscheme-send-previous-expression "23.2")
c5c3d778
DL
481\f
482;;;; Debugger Mode
483
484(defun scheme-debugger-mode ()
485 "Major mode for executing the Scheme debugger.
486Like scheme-mode except that the evaluation commands
487are disabled, and characters that would normally be self inserting are
488sent to the Scheme process instead. Typing ? will show you which
489characters perform useful functions.
490
491Commands:
492\\{scheme-debugger-mode-map}"
eac9c0ef 493 (error "Invalid entry to scheme-debugger-mode"))
c5c3d778 494
f28d4b0f
JB
495(defvar scheme-debugger-mode-map nil)
496
c5c3d778
DL
497(defun scheme-debugger-mode-initialize ()
498 (use-local-map scheme-debugger-mode-map)
499 (setq major-mode 'scheme-debugger-mode)
500 (setq mode-name "Scheme Debugger"))
501
502(defun scheme-debugger-mode-commands (keymap)
f28d4b0f 503 (let ((char ?\s))
c5c3d778
DL
504 (while (< char 127)
505 (define-key keymap (char-to-string char) 'scheme-debugger-self-insert)
506 (setq char (1+ char)))))
507
f28d4b0f 508;; Initialize the debugger mode map
c5c3d778
DL
509(if (not scheme-debugger-mode-map)
510 (progn
511 (setq scheme-debugger-mode-map (make-keymap))
512 (scheme-mode-commands scheme-debugger-mode-map)
513 (xscheme-interrupt-commands scheme-debugger-mode-map)
514 (scheme-debugger-mode-commands scheme-debugger-mode-map)))
515
516(defun scheme-debugger-self-insert ()
517 "Transmit this character to the Scheme process."
518 (interactive)
1ba983e8 519 (xscheme-send-char last-command-event))
c5c3d778
DL
520
521(defun xscheme-enter-debugger-mode (prompt-string)
522 (save-excursion
523 (set-buffer (xscheme-process-buffer))
524 (if (not (eq major-mode 'scheme-debugger-mode))
525 (progn
526 (if (not (eq major-mode 'scheme-interaction-mode))
527 (scheme-interaction-mode t))
528 (scheme-debugger-mode-initialize)))))
529
530(defun xscheme-debugger-mode-p ()
531 (let ((buffer (xscheme-process-buffer)))
532 (and buffer
533 (save-excursion
534 (set-buffer buffer)
535 (eq major-mode 'scheme-debugger-mode)))))
536\f
537;;;; Evaluation Commands
538
539(defun xscheme-send-string (&rest strings)
540 "Send the string arguments to the Scheme process.
541The strings are concatenated and terminated by a newline."
542 (cond ((not (xscheme-process-running-p))
543 (if (yes-or-no-p "The Scheme process has died. Reset it? ")
544 (progn
545 (reset-scheme)
546 (xscheme-wait-for-process)
547 (xscheme-send-string-1 strings))))
548 ((xscheme-debugger-mode-p) (error "No sends allowed in debugger mode"))
549 ((and (not xscheme-allow-pipelined-evaluation)
550 xscheme-running-p)
551 (error "No sends allowed while Scheme running"))
552 (t (xscheme-send-string-1 strings))))
553
554(defun xscheme-send-string-1 (strings)
555 (let ((string (apply 'concat strings)))
556 (xscheme-send-string-2 string)
557 (if (eq major-mode 'scheme-interaction-mode)
558 (xscheme-insert-expression string))))
559
560(defun xscheme-send-string-2 (string)
561 (let ((process (get-process xscheme-process-name)))
562 (process-send-string process (concat string "\n"))
563 (if (xscheme-process-buffer-current-p)
564 (set-marker (process-mark process) (point)))))
565
566(defun xscheme-select-process-buffer ()
567 "Select the Scheme process buffer and move to its output point."
568 (interactive)
569 (let ((process
570 (or (get-process xscheme-process-name)
571 (error "No scheme process"))))
572 (let ((buffer (or (process-buffer process) (error "No process buffer"))))
573 (let ((window (get-buffer-window buffer)))
574 (if window
575 (select-window window)
576 (switch-to-buffer buffer))
577 (goto-char (process-mark process))))))
578\f
579;;;; Scheme expressions ring
580
581(defun xscheme-insert-expression (string)
662705b1
KS
582 (setq xscheme-expressions-ring-yank-pointer
583 (add-to-history 'xscheme-expressions-ring string
584 xscheme-expressions-ring-max)))
c5c3d778
DL
585
586(defun xscheme-rotate-yank-pointer (arg)
587 "Rotate the yanking point in the kill ring."
588 (interactive "p")
589 (let ((length (length xscheme-expressions-ring)))
590 (if (zerop length)
591 (error "Scheme expression ring is empty")
592 (setq xscheme-expressions-ring-yank-pointer
593 (let ((index
594 (% (+ arg
595 (- length
596 (length xscheme-expressions-ring-yank-pointer)))
597 length)))
598 (nthcdr (if (< index 0)
599 (+ index length)
600 index)
601 xscheme-expressions-ring))))))
602
603(defun xscheme-yank (&optional arg)
604 "Insert the most recent expression at point.
605With just C-U as argument, same but put point in front (and mark at end).
606With argument n, reinsert the nth most recently sent expression.
607See also the commands \\[xscheme-yank-pop] and \\[xscheme-yank-push]."
608 (interactive "*P")
609 (xscheme-rotate-yank-pointer (if (listp arg) 0
610 (if (eq arg '-) -1
611 (1- arg))))
612 (push-mark (point))
613 (insert (car xscheme-expressions-ring-yank-pointer))
614 (if (consp arg)
615 (exchange-point-and-mark)))
616
617;; Old name, to avoid errors in users' init files.
618(fset 'xscheme-yank-previous-send
619 'xscheme-yank)
620
621(defun xscheme-yank-pop (arg)
622 "Insert or replace a just-yanked expression with an older expression.
623If the previous command was not a yank, it yanks.
624Otherwise, the region contains a stretch of reinserted
625expression. yank-pop deletes that text and inserts in its
626place a different expression.
627
628With no argument, the next older expression is inserted.
629With argument n, the n'th older expression is inserted.
630If n is negative, this is a more recent expression.
631
632The sequence of expressions wraps around, so that after the oldest one
633comes the newest one."
634 (interactive "*p")
635 (setq this-command 'xscheme-yank)
636 (if (not (eq last-command 'xscheme-yank))
637 (progn
638 (xscheme-yank)
639 (setq arg (- arg 1))))
640 (if (not (= arg 0))
641 (let ((before (< (point) (mark))))
642 (delete-region (point) (mark))
643 (xscheme-rotate-yank-pointer arg)
644 (set-mark (point))
645 (insert (car xscheme-expressions-ring-yank-pointer))
646 (if before (exchange-point-and-mark)))))
647
648(defun xscheme-yank-push (arg)
649 "Insert or replace a just-yanked expression with a more recent expression.
650If the previous command was not a yank, it yanks.
651Otherwise, the region contains a stretch of reinserted
652expression. yank-pop deletes that text and inserts in its
653place a different expression.
654
655With no argument, the next more recent expression is inserted.
656With argument n, the n'th more recent expression is inserted.
657If n is negative, a less recent expression is used.
658
659The sequence of expressions wraps around, so that after the oldest one
660comes the newest one."
661 (interactive "*p")
662 (xscheme-yank-pop (- 0 arg)))
663\f
664(defun xscheme-send-region (start end)
665 "Send the current region to the Scheme process.
666The region is sent terminated by a newline."
667 (interactive "r")
668 (if (xscheme-process-buffer-current-p)
669 (progn
670 (goto-char end)
671 (if (not (bolp))
672 (insert-before-markers ?\n))
673 (set-marker (process-mark (get-process xscheme-process-name))
674 (point))
675 (set-marker xscheme-last-input-end (point))))
676 (xscheme-send-string (buffer-substring start end)))
677
678(defun xscheme-send-definition ()
679 "Send the current definition to the Scheme process.
680If the current line begins with a non-whitespace character,
681parse an expression from the beginning of the line and send that instead."
682 (interactive)
683 (let ((start nil) (end nil))
684 (save-excursion
685 (end-of-defun)
686 (setq end (point))
687 (if (re-search-backward "^\\s(" nil t)
688 (setq start (point))
689 (error "Can't find definition")))
690 (xscheme-send-region start end)))
691
692(defun xscheme-send-next-expression ()
693 "Send the expression to the right of `point' to the Scheme process."
694 (interactive)
695 (let ((start (point)))
696 (xscheme-send-region start (save-excursion (forward-sexp) (point)))))
697
698(defun xscheme-send-previous-expression ()
699 "Send the expression to the left of `point' to the Scheme process."
700 (interactive)
701 (let ((end (point)))
702 (xscheme-send-region (save-excursion (backward-sexp) (point)) end)))
703\f
704(defun xscheme-send-current-line ()
705 "Send the current line to the Scheme process.
706Useful for working with debugging Scheme under adb."
707 (interactive)
708 (let ((line
709 (save-excursion
710 (beginning-of-line)
711 (let ((start (point)))
712 (end-of-line)
713 (buffer-substring start (point))))))
714 (end-of-line)
715 (insert ?\n)
716 (xscheme-send-string-2 line)))
717
718(defun xscheme-send-buffer ()
719 "Send the current buffer to the Scheme process."
720 (interactive)
721 (if (xscheme-process-buffer-current-p)
722 (error "Not allowed to send this buffer's contents to Scheme"))
723 (xscheme-send-region (point-min) (point-max)))
724
725(defun xscheme-send-char (char)
726 "Prompt for a character and send it to the Scheme process."
727 (interactive "cCharacter to send: ")
728 (process-send-string xscheme-process-name (char-to-string char)))
729
730(defun xscheme-delete-output ()
731 "Delete all output from interpreter since last input."
732 (interactive)
733 (let ((proc (get-buffer-process (current-buffer))))
734 (save-excursion
735 (goto-char (process-mark proc))
736 (re-search-backward
737 "^;\\(Unspecified return value$\\|Value\\( [0-9]+\\)?: \\|\\(Abort\\|Up\\|Quit\\)!$\\)"
738 xscheme-last-input-end
739 t)
740 (forward-line 0)
741 (if (< (marker-position xscheme-last-input-end) (point))
742 (progn
743 (delete-region xscheme-last-input-end (point))
744 (insert-before-markers "*** output flushed ***\n"))))))
745\f
746;;;; Interrupts
747
748(defun xscheme-send-breakpoint-interrupt ()
749 "Cause the Scheme process to enter a breakpoint."
750 (interactive)
751 (xscheme-send-interrupt ?b nil))
752
753(defun xscheme-send-proceed ()
754 "Cause the Scheme process to proceed from a breakpoint."
755 (interactive)
756 (process-send-string xscheme-process-name "(proceed)\n"))
757
f28d4b0f
JB
758(defconst xscheme-control-g-message-string
759 "Sending C-G interrupt to Scheme...")
760
c5c3d778
DL
761(defun xscheme-send-control-g-interrupt ()
762 "Cause the Scheme processor to halt and flush input.
763Control returns to the top level rep loop."
764 (interactive)
765 (let ((inhibit-quit t))
766 (cond ((not xscheme-control-g-synchronization-p)
767 (interrupt-process xscheme-process-name))
768 ((save-excursion
769 (set-buffer xscheme-buffer-name)
770 xscheme-control-g-disabled-p)
771 (message "Relax..."))
772 (t
773 (save-excursion
774 (set-buffer xscheme-buffer-name)
775 (setq xscheme-control-g-disabled-p t))
776 (message xscheme-control-g-message-string)
777 (interrupt-process xscheme-process-name)
778 (sleep-for 0.1)
779 (xscheme-send-char 0)))))
780
c5c3d778
DL
781(defun xscheme-send-control-u-interrupt ()
782 "Cause the Scheme process to halt, returning to previous rep loop."
783 (interactive)
784 (xscheme-send-interrupt ?u t))
785
786(defun xscheme-send-control-x-interrupt ()
787 "Cause the Scheme process to halt, returning to current rep loop."
788 (interactive)
789 (xscheme-send-interrupt ?x t))
790
791;;; This doesn't really work right -- Scheme just gobbles the first
792;;; character in the input. There is no way for us to guarantee that
793;;; the argument to this procedure is the first char unless we put
794;;; some kind of marker in the input stream.
795
796(defun xscheme-send-interrupt (char mark-p)
797 "Send a ^A type interrupt to the Scheme process."
798 (interactive "cInterrupt character to send: ")
799 (quit-process xscheme-process-name)
800 (sleep-for 0.1)
801 (xscheme-send-char char)
802 (if (and mark-p xscheme-control-g-synchronization-p)
803 (xscheme-send-char 0)))
804\f
c5c3d778
DL
805;;;; Basic Process Control
806
807(defun xscheme-start-process (command-line the-process the-buffer)
808 (let ((buffer (get-buffer-create the-buffer)))
809 (let ((process (get-buffer-process buffer)))
810 (save-excursion
811 (set-buffer buffer)
812 (if (and process (memq (process-status process) '(run stop)))
813 (set-marker (process-mark process) (point-max))
814 (progn (if process (delete-process process))
815 (goto-char (point-max))
816 (scheme-interaction-mode nil)
817 (setq xscheme-process-name the-process)
818 (if (bobp)
819 (insert-before-markers
820 (substitute-command-keys xscheme-startup-message)))
821 (setq process
822 (let ((process-connection-type nil))
823 (apply 'start-process
824 (cons the-process
825 (cons buffer
826 (xscheme-parse-command-line
827 command-line))))))
828 (if (not (equal (process-name process) the-process))
829 (setq xscheme-process-name (process-name process)))
830 (if (not (equal (buffer-name buffer) the-buffer))
831 (setq xscheme-buffer-name (buffer-name buffer)))
832 (message "Starting process %s in buffer %s"
833 xscheme-process-name
834 xscheme-buffer-name)
835 (set-marker (process-mark process) (point-max))
836 (xscheme-process-filter-initialize t)
837 (xscheme-modeline-initialize xscheme-buffer-name)
838 (set-process-sentinel process 'xscheme-process-sentinel)
839 (set-process-filter process 'xscheme-process-filter)
840 (run-hooks 'xscheme-start-hook)))))
841 buffer))
842
843(defun xscheme-parse-command-line (string)
844 (setq string (substitute-in-file-name string))
845 (let ((start 0)
846 (result '()))
847 (while start
848 (let ((index (string-match "[ \t]" string start)))
849 (setq start
850 (cond ((not index)
851 (setq result
852 (cons (substring string start)
853 result))
854 nil)
855 ((= index start)
856 (string-match "[^ \t]" string start))
857 (t
858 (setq result
859 (cons (substring string start index)
860 result))
861 (1+ index))))))
862 (nreverse result)))
863\f
864(defun xscheme-wait-for-process ()
865 (sleep-for 2)
866 (while xscheme-running-p
867 (sleep-for 1)))
868
869(defun xscheme-process-running-p ()
e7f767c2 870 "True if there is a Scheme process whose status is `run'."
c5c3d778
DL
871 (let ((process (get-process xscheme-process-name)))
872 (and process
873 (eq (process-status process) 'run))))
874
875(defun xscheme-process-buffer ()
876 (let ((process (get-process xscheme-process-name)))
877 (and process (process-buffer process))))
878
879(defun xscheme-process-buffer-window ()
880 (let ((buffer (xscheme-process-buffer)))
881 (and buffer (get-buffer-window buffer))))
882
883(defun xscheme-process-buffer-current-p ()
e7f767c2 884 "True if the current buffer is the Scheme process buffer."
c5c3d778
DL
885 (eq (xscheme-process-buffer) (current-buffer)))
886\f
f28d4b0f
JB
887;;;; Process Filter Operations
888
889(defvar xscheme-process-filter-alist
890 '((?A xscheme-eval
891 xscheme-process-filter:string-action-noexcursion)
892 (?D xscheme-enter-debugger-mode
893 xscheme-process-filter:string-action)
894 (?E xscheme-eval
895 xscheme-process-filter:string-action)
896 (?P xscheme-set-prompt-variable
897 xscheme-process-filter:string-action)
898 (?R xscheme-enter-interaction-mode
899 xscheme-process-filter:simple-action)
900 (?b xscheme-start-gc
901 xscheme-process-filter:simple-action)
902 (?c xscheme-unsolicited-read-char
903 xscheme-process-filter:simple-action)
904 (?e xscheme-finish-gc
905 xscheme-process-filter:simple-action)
906 (?f xscheme-exit-input-wait
907 xscheme-process-filter:simple-action)
908 (?g xscheme-enable-control-g
909 xscheme-process-filter:simple-action)
910 (?i xscheme-prompt-for-expression
911 xscheme-process-filter:string-action)
912 (?m xscheme-message
913 xscheme-process-filter:string-action)
914 (?n xscheme-prompt-for-confirmation
915 xscheme-process-filter:string-action)
916 (?o xscheme-output-goto
917 xscheme-process-filter:simple-action)
918 (?p xscheme-set-prompt
919 xscheme-process-filter:string-action)
920 (?s xscheme-enter-input-wait
921 xscheme-process-filter:simple-action)
922 (?v xscheme-write-value
923 xscheme-process-filter:string-action)
924 (?w xscheme-cd
925 xscheme-process-filter:string-action)
926 (?z xscheme-display-process-buffer
927 xscheme-process-filter:simple-action))
928 "Table used to decide how to handle process filter commands.
929Value is a list of entries, each entry is a list of three items.
930
931The first item is the character that the process filter dispatches on.
932The second item is the action to be taken, a function.
933The third item is the handler for the entry, a function.
934
935When the process filter sees a command whose character matches a
936particular entry, it calls the handler with two arguments: the action
937and the string containing the rest of the process filter's input
938stream. It is the responsibility of the handler to invoke the action
939with the appropriate arguments, and to reenter the process filter with
940the remaining input.")
941\f
c5c3d778
DL
942;;;; Process Filter
943
944(defun xscheme-process-sentinel (proc reason)
945 (let* ((buffer (process-buffer proc))
946 (name (buffer-name buffer)))
947 (save-excursion
948 (set-buffer buffer)
949 (xscheme-process-filter-initialize (eq reason 'run))
950 (if (not (eq reason 'run))
951 (progn
952 (setq scheme-mode-line-process "")
953 (setq xscheme-mode-string "no process")
954 (if (equal name (default-value 'xscheme-buffer-name))
955 (setq-default xscheme-runlight ""))))
956 (if (and (not (memq reason '(run stop)))
957 xscheme-signal-death-message)
958 (progn
959 (beep)
960 (message
961"The Scheme process has died! Do M-x reset-scheme to restart it"))))))
962
963(defun xscheme-process-filter-initialize (running-p)
964 (setq xscheme-process-filter-state 'idle)
965 (setq xscheme-running-p running-p)
966 (setq xscheme-control-g-disabled-p nil)
967 (setq xscheme-allow-output-p t)
968 (setq xscheme-prompt "")
969 (if running-p
970 (let ((name (buffer-name (current-buffer))))
971 (setq scheme-mode-line-process '(": " xscheme-runlight-string))
972 (xscheme-modeline-initialize name)
973 (if (equal name (default-value 'xscheme-buffer-name))
974 (setq-default xscheme-runlight default-xscheme-runlight))))
975 (if (or (eq xscheme-runlight default-xscheme-runlight)
976 (equal xscheme-runlight ""))
977 (setq xscheme-runlight (list ": " 'xscheme-buffer-name ": " "?")))
978 (rplaca (nthcdr 3 xscheme-runlight)
979 (if running-p "?" "no process")))
980
981(defun xscheme-process-filter (proc string)
982 (let ((xscheme-filter-input string)
983 (call-noexcursion nil))
984 (while xscheme-filter-input
985 (setq call-noexcursion nil)
986 (save-excursion
987 (set-buffer (process-buffer proc))
988 (cond ((eq xscheme-process-filter-state 'idle)
989 (let ((start (string-match "\e" xscheme-filter-input)))
990 (if start
991 (progn
992 (xscheme-process-filter-output
993 (substring xscheme-filter-input 0 start))
994 (setq xscheme-filter-input
995 (substring xscheme-filter-input (1+ start)))
996 (setq xscheme-process-filter-state 'reading-type))
997 (let ((string xscheme-filter-input))
998 (setq xscheme-filter-input nil)
999 (xscheme-process-filter-output string)))))
1000 ((eq xscheme-process-filter-state 'reading-type)
1001 (if (zerop (length xscheme-filter-input))
1002 (setq xscheme-filter-input nil)
1003 (let ((char (aref xscheme-filter-input 0)))
1004 (setq xscheme-filter-input
1005 (substring xscheme-filter-input 1))
1006 (let ((entry (assoc char xscheme-process-filter-alist)))
1007 (if entry
1008 (funcall (nth 2 entry) (nth 1 entry))
1009 (progn
1010 (xscheme-process-filter-output ?\e char)
1011 (setq xscheme-process-filter-state 'idle)))))))
1012 ((eq xscheme-process-filter-state 'reading-string)
1013 (let ((start (string-match "\e" xscheme-filter-input)))
1014 (if start
1015 (let ((string
1016 (concat xscheme-string-accumulator
1017 (substring xscheme-filter-input 0 start))))
1018 (setq xscheme-filter-input
1019 (substring xscheme-filter-input (1+ start)))
1020 (setq xscheme-process-filter-state 'idle)
1021 (if (listp xscheme-string-receiver)
1022 (progn
1023 (setq xscheme-string-receiver
1024 (car xscheme-string-receiver))
1025 (setq call-noexcursion string))
1026 (funcall xscheme-string-receiver string)))
1027 (progn
1028 (setq xscheme-string-accumulator
1029 (concat xscheme-string-accumulator
1030 xscheme-filter-input))
1031 (setq xscheme-filter-input nil)))))
1032 (t
1033 (error "Scheme process filter -- bad state"))))
1034 (if call-noexcursion
1035 (funcall xscheme-string-receiver call-noexcursion)))))
1036\f
1037;;;; Process Filter Output
1038
1039(defun xscheme-process-filter-output (&rest args)
1040 (if xscheme-allow-output-p
1041 (let ((string (apply 'concat args)))
1042 (save-excursion
1043 (xscheme-goto-output-point)
1044 (let ((old-point (point)))
1045 (while (string-match "\\(\007\\|\f\\)" string)
1046 (let ((start (match-beginning 0))
1047 (end (match-end 0)))
1048 (insert-before-markers (substring string 0 start))
1049 (if (= ?\f (aref string start))
1050 (progn
1051 (if (not (bolp))
1052 (insert-before-markers ?\n))
1053 (insert-before-markers ?\f))
1054 (beep))
1055 (setq string (substring string (1+ start)))))
1056 (insert-before-markers string)
1057 (if (and xscheme-last-input-end
1058 (equal (marker-position xscheme-last-input-end) (point)))
1059 (set-marker xscheme-last-input-end old-point)))))))
1060
1061(defun xscheme-guarantee-newlines (n)
1062 (if xscheme-allow-output-p
1063 (save-excursion
1064 (xscheme-goto-output-point)
1065 (let ((stop nil))
1066 (while (and (not stop)
1067 (bolp))
1068 (setq n (1- n))
1069 (if (bobp)
1070 (setq stop t)
1071 (backward-char))))
1072 (xscheme-goto-output-point)
1073 (while (> n 0)
1074 (insert-before-markers ?\n)
1075 (setq n (1- n))))))
1076
1077(defun xscheme-goto-output-point ()
1078 (let ((process (get-process xscheme-process-name)))
1079 (set-buffer (process-buffer process))
1080 (goto-char (process-mark process))))
1081
1082(defun xscheme-modeline-initialize (name)
1083 (setq xscheme-runlight-string "")
1084 (if (equal name (default-value 'xscheme-buffer-name))
1085 (setq-default xscheme-runlight-string ""))
1086 (setq xscheme-mode-string "")
1087 (setq mode-line-buffer-identification
1088 (list (concat name ": ")
1089 'xscheme-mode-string)))
1090
1091(defun xscheme-set-runlight (runlight)
1092 (setq xscheme-runlight-string runlight)
1093 (if (equal (buffer-name (current-buffer))
1094 (default-value 'xscheme-buffer-name))
1095 (setq-default xscheme-runlight-string runlight))
1096 (rplaca (nthcdr 3 xscheme-runlight) runlight)
1097 (force-mode-line-update t))
1098\f
c5c3d778
DL
1099(defun xscheme-process-filter:simple-action (action)
1100 (setq xscheme-process-filter-state 'idle)
1101 (funcall action))
1102
1103(defun xscheme-process-filter:string-action (action)
1104 (setq xscheme-string-receiver action)
1105 (setq xscheme-string-accumulator "")
1106 (setq xscheme-process-filter-state 'reading-string))
1107
1108(defun xscheme-process-filter:string-action-noexcursion (action)
1109 (xscheme-process-filter:string-action (cons action nil)))
1110
1111(defconst xscheme-runlight:running "run"
1112 "The character displayed when the Scheme process is running.")
1113
1114(defconst xscheme-runlight:input "input"
1115 "The character displayed when the Scheme process is waiting for input.")
1116
1117(defconst xscheme-runlight:gc "gc"
1118 "The character displayed when the Scheme process is garbage collecting.")
1119
1120(defun xscheme-start-gc ()
1121 (xscheme-set-runlight xscheme-runlight:gc))
1122
1123(defun xscheme-finish-gc ()
1124 (xscheme-set-runlight
1125 (if xscheme-running-p xscheme-runlight:running xscheme-runlight:input)))
1126
1127(defun xscheme-enter-input-wait ()
1128 (xscheme-set-runlight xscheme-runlight:input)
1129 (setq xscheme-control-g-disabled-p nil)
1130 (setq xscheme-running-p nil))
1131
1132(defun xscheme-exit-input-wait ()
1133 (xscheme-set-runlight xscheme-runlight:running)
1134 (setq xscheme-running-p t))
1135
1136(defun xscheme-enable-control-g ()
1137 (setq xscheme-control-g-disabled-p nil)
1138 (if (string= (current-message) xscheme-control-g-message-string)
1139 (message nil)))
1140
1141(defun xscheme-display-process-buffer ()
1142 (let ((window (or (xscheme-process-buffer-window)
1143 (display-buffer (xscheme-process-buffer)))))
1144 (save-window-excursion
1145 (select-window window)
1146 (xscheme-goto-output-point)
1147 (if (xscheme-debugger-mode-p)
1148 (xscheme-enter-interaction-mode)))))
1149
1150(defun xscheme-unsolicited-read-char ()
1151 nil)
1152\f
1153(defun xscheme-eval (string)
1154 (eval (car (read-from-string string))))
1155
1156(defun xscheme-message (string)
1157 (if (not (zerop (length string)))
1158 (xscheme-write-message-1 string (format ";%s" string))))
1159
1160(defun xscheme-write-value (string)
1161 (if (zerop (length string))
1162 (xscheme-write-message-1 "(no value)" ";Unspecified return value")
1163 (xscheme-write-message-1 string (format ";Value: %s" string))))
1164
1165(defun xscheme-write-message-1 (message-string output-string)
1166 (let* ((process (get-process xscheme-process-name))
1167 (window (get-buffer-window (process-buffer process))))
1168 (if (or (not window)
1169 (not (pos-visible-in-window-p (process-mark process)
1170 window)))
1171 (message "%s" message-string)))
1172 (xscheme-guarantee-newlines 1)
1173 (xscheme-process-filter-output output-string))
1174
1175(defun xscheme-set-prompt-variable (string)
1176 (setq xscheme-prompt string))
1177
1178(defun xscheme-set-prompt (string)
1179 (setq xscheme-prompt string)
1180 (xscheme-guarantee-newlines 2)
1181 (setq xscheme-mode-string (xscheme-coerce-prompt string))
1182 (force-mode-line-update t))
1183
1184(defun xscheme-output-goto ()
1185 (xscheme-goto-output-point)
1186 (xscheme-guarantee-newlines 2))
1187
1188(defun xscheme-coerce-prompt (string)
1189 (if (string-match "^[0-9]+ \\[[^]]+\\] " string)
1190 (let ((end (match-end 0)))
1191 (xscheme-process-filter-output (substring string end))
1192 (substring string 0 (- end 1)))
1193 string))
1194
1195(defun xscheme-cd (directory-string)
1196 (save-excursion
1197 (set-buffer (xscheme-process-buffer))
1198 (cd directory-string)))
1199\f
1200(defun xscheme-prompt-for-confirmation (prompt-string)
1201 (xscheme-send-char (if (y-or-n-p prompt-string) ?y ?n)))
1202
c5c3d778
DL
1203(defvar xscheme-prompt-for-expression-map nil)
1204(if (not xscheme-prompt-for-expression-map)
1205 (progn
1206 (setq xscheme-prompt-for-expression-map
1207 (copy-keymap minibuffer-local-map))
1208 (substitute-key-definition 'exit-minibuffer
1209 'xscheme-prompt-for-expression-exit
1210 xscheme-prompt-for-expression-map)))
1211
f28d4b0f
JB
1212(defun xscheme-prompt-for-expression (prompt-string)
1213 (xscheme-send-string-2
1214 (read-from-minibuffer prompt-string nil xscheme-prompt-for-expression-map)))
1215
c5c3d778
DL
1216(defun xscheme-prompt-for-expression-exit ()
1217 (interactive)
1218 (if (eq (xscheme-region-expression-p (point-min) (point-max)) 'one)
1219 (exit-minibuffer)
1220 (error "input must be a single, complete expression")))
1221
1222(defun xscheme-region-expression-p (start end)
1223 (save-excursion
1224 (let ((old-syntax-table (syntax-table)))
1225 (unwind-protect
1226 (progn
1227 (set-syntax-table scheme-mode-syntax-table)
1228 (let ((state (parse-partial-sexp start end)))
1229 (and (zerop (car state)) ;depth = 0
1230 (nth 2 state) ;last-sexp exists, i.e. >= 1 sexps
1231 (let ((state (parse-partial-sexp start (nth 2 state))))
1232 (if (nth 2 state) 'many 'one)))))
1233 (set-syntax-table old-syntax-table)))))
1234
1235(provide 'xscheme)
1236
cbee283d 1237;; arch-tag: cfc14adc-2917-409e-ad16-432e8d0017de
c5c3d778 1238;;; xscheme.el ends here