annotate lisp/packages/xscheme.el @ 12:bcdc7deadc19 r19-15b7

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