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