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