annotate lisp/packages/xscheme.el @ 16:0293115a14e9 r19-15b91

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