This file is indexed.

/usr/share/emacs/site-lisp/gambc/gambit.el is in gambc 4.2.8-1.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
;;; -*- Mode:Emacs-Lisp -*-
;;; gambit.el --- Run Gambit in an [X]Emacs buffer

;; Copyright (c) 1997-2004 Marc Feeley & Michael Sperber

;; Authors: Marc Feeley <feeley@iro.umontreal.ca>
;;          Mike Sperber <sperber@informatik.uni-tuebingen.de>
;; Keywords: processes, lisp

;; To use this package, make sure this file is accessible from your
;; load-path and that the following lines are in your ".emacs" file:
;;
;; (autoload 'gambit-inferior-mode "gambit" "Hook Gambit mode into cmuscheme.")
;; (autoload 'gambit-mode "gambit" "Hook Gambit mode into scheme.")
;; (add-hook 'inferior-scheme-mode-hook (function gambit-inferior-mode))
;; (add-hook 'scheme-mode-hook (function gambit-mode))
;; (setq scheme-program-name "gsi -:t")
;;
;; Alternatively, if you don't mind always loading this package,
;; you can simply add this line to your ".emacs" file:
;;
;; (require 'gambit)
;;
;; You can then start Gambit with "M-x run-scheme".
;;
;; When Gambit signals an error, Emacs will intercept the location
;; information in the error message and automatically open a buffer
;; highlighting the error.
;;
;; The continuation of the error can be inspected with the "C-c ["
;; (crawl towards older frames) and "C-c ]" (crawl towards newer
;; frames).  For each new frame visited, Emacs will highlight the
;; expression associated with the frame.
;;
;; "C-c c", "C-c s" and "C-c l" can be used to send the commands
;; ",c", ",s" and ",l" respectively to Gambit.  This is convenient for
;; single-stepping a program.
;;
;; "C-c _" can be used to delete the last popup window that was
;; created to highlight a Scheme expression.

;;;----------------------------------------------------------------------------

;; User overridable parameters.

(defvar scheme-program-name "gsi -:d-")

(defvar gambit-repl-command-prefix "\C-c"
  "Emacs keybinding prefix for Gambit REPL's commands.")

(defvar gambit-highlight-color "gold"
  "Color of the overlay for highlighting Scheme expressions.")

(defvar gambit-highlight-face
  (let ((face 'gambit-highlight-face))
    (condition-case nil
        (progn
          (make-face face)
          (if (x-display-color-p)
              (set-face-background face gambit-highlight-color)
              (progn
                ;(make-face-bold face)
                (set-face-underline-p face t))))
        (error (setq face nil)))
    face)
  "Face of overlay for highlighting Scheme expressions.")

(defvar gambit-new-window-height 6
  "Height of a window opened to highlight a Scheme expression.")

(defvar gambit-move-to-highlighted (not gambit-highlight-face)
  "Flag to move to window opened to highlight a Scheme expression.")

;;;----------------------------------------------------------------------------

;; These must be loaded first because we redefine some of the
;; functions they contain.

(require 'scheme)
(require 'cmuscheme)

;;;----------------------------------------------------------------------------

(defun gambit-indent-function (indent-point state)
  (let ((normal-indent (current-column)))
    (goto-char (1+ (elt state 1)))
    (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
    (if (and (elt state 2)
             (not (looking-at "\\sw\\|\\s_")))
        ;; car of form doesn't seem to be a a symbol
        (progn
          (if (not (> (save-excursion (forward-line 1) (point))
                      calculate-lisp-indent-last-sexp))
              (progn (goto-char calculate-lisp-indent-last-sexp)
                     (beginning-of-line)
                     (parse-partial-sexp (point)
                                         calculate-lisp-indent-last-sexp 0 t)))
          ;; Indent under the list or under the first sexp on the same
          ;; line as calculate-lisp-indent-last-sexp.  Note that first
          ;; thing on that line has to be complete sexp since we are
          ;; inside the innermost containing sexp.
          (backward-prefix-chars)
          (current-column))
      (let ((function (buffer-substring (point)
                                        (progn (forward-sexp 1) (point))))
            method)
        (setq method (or (gambit-indent-method function)
                         (get (intern-soft function) 'scheme-indent-function)
                         (get (intern-soft function) 'scheme-indent-hook)))
        (cond ((or (eq method 'defun)
                   (and (null method)
                        (> (length function) 3)
                        (string-match "\\`def" function)))
               (lisp-indent-defform state indent-point))
              ((integerp method)
               (lisp-indent-specform method state
                                     indent-point normal-indent))
              (method
                (funcall method state indent-point normal-indent)))))))

(defun gambit-indent-method (function)
  (let ((method nil)
        (alist gambit-indent-regexp-alist))
    (while (and (not method) (not (null alist)))
      (let* ((regexp (car alist))
             (x (string-match (car regexp) function)))
        (if x
            (setq method (cdr regexp)))
        (setq alist (cdr alist))))
    method))

(set lisp-indent-function 'gambit-indent-function)

(defvar gambit-indent-regexp-alist
  '(
    ("^declare$"               . defun)
    ("^##declare$"             . defun)
    ("^##define"               . defun)
    ("^macro-check"            . defun)
    ("^macro-force-vars$"      . defun)
    ("^macro-number-dispatch$" . defun)
   ))

;;;----------------------------------------------------------------------------

;; Portable functions for FSF Emacs and Xemacs.

(defun window-top-edge (window)
  (if (fboundp 'window-edges)
      (car (cdr (window-edges window)))
      (car (cdr (window-pixel-edges window)))))

;; Xemacs calls its overlays "extents", so we have to use them to emulate 
;; overlays on Xemacs.  Some versions of Xemacs have the portability package
;; "overlays.el" for this, so we could simply do:
;;
;; (condition-case nil ; load "overlay.el" if we have it
;;     (require 'overlay)
;;   (error nil))
;;
;; Unfortunately some versions of Xemacs don't have this package so
;; we explicitly define an interface to extents.

(if (not (fboundp 'make-overlay))
    (defun make-overlay (start end)
      (make-extent start end)))

(if (not (fboundp 'overlay-put))
    (defun overlay-put (overlay prop val)
      (set-extent-property overlay prop val)))

(if (not (fboundp 'move-overlay))
    (defun move-overlay (overlay start end buffer)
      (set-extent-endpoints overlay start end buffer)))

;;;----------------------------------------------------------------------------

;; Redefine the function scheme-send-region from `cmuscheme' so
;; that we can keep track of all text sent to Gambit's stdin.

(defun scheme-send-region (start end)
  "Send the current region to the inferior Scheme process."
  (interactive "r")
  (scheme-send-string (buffer-substring start end)))

(defun scheme-send-string (str)
  "Send a string to the inferior Scheme process."
  (let* ((clean-str (gambit-string-terminate-with-newline str))
         (proc (scheme-proc))
         (pmark (process-mark proc))
         (buffer (get-buffer scheme-buffer))
         (old-buffer (current-buffer)))
    (set-buffer buffer)
    (goto-char pmark)
    (set-marker comint-last-input-start (point))
    (insert clean-str)
    (set-marker pmark (point))
    (gambit-input-sender proc clean-str)
    (set-buffer old-buffer)))

(defun gambit-input-sender (proc str)
  (let ((clean-str (gambit-string-terminate-with-newline str)))
    (gambit-register-input clean-str)
    (gambit-make-read-only (current-buffer) (point-max))
    (gambit-unhighlight)
    (comint-send-string proc clean-str)))

(defun gambit-register-input (str)
  (let ((marker (make-marker)))
    (set-marker marker comint-last-input-start)
    (setq gambit-input-line-marker-alist
          (cons (cons gambit-input-line-count
                      marker)
                gambit-input-line-marker-alist))
    (setq gambit-input-line-count
          (+ gambit-input-line-count
             (gambit-string-count-lines str)))))

(defun gambit-make-read-only (buffer end)
  ' ; disable read-only interaction, cause it doesn't work!
  (progn
    (put-text-property 1 end 'front-sticky '(read-only) buffer)
    (put-text-property 1 end 'rear-nonsticky '(read-only) buffer)
    (put-text-property 1 end 'read-only t buffer)))

;;;----------------------------------------------------------------------------

(defun gambit-load-file (file-name)
  "Load a Scheme file FILE-NAME into the inferior Scheme process."
  (interactive (comint-get-source "Load Scheme file: " scheme-prev-l/c-dir/file
                                  scheme-source-modes t)) ; T because LOAD
                                                          ; needs an exact name
  (comint-check-source file-name) ; Check to see if buffer needs saved.
  (setq scheme-prev-l/c-dir/file (cons (file-name-directory    file-name)
                                       (file-name-nondirectory file-name)))
  (scheme-send-string (concat "(load \"" file-name "\"\)\n")))

(defun gambit-compile-file (file-name)
  "Compile a Scheme file FILE-NAME in the inferior Scheme process."
  (interactive (comint-get-source "Compile Scheme file: "
                                  scheme-prev-l/c-dir/file
                                  scheme-source-modes
                                  nil)) ; NIL because COMPILE doesn't
                                        ; need an exact name.
  (comint-check-source file-name) ; Check to see if buffer needs saved.
  (setq scheme-prev-l/c-dir/file (cons (file-name-directory    file-name)
                                       (file-name-nondirectory file-name)))
  (scheme-send-string (concat "(compile-file \"" file-name "\"\)\n")))

;;;----------------------------------------------------------------------------

;; Buffer local variables of the Gambit inferior process(es).

(defvar gambit-input-line-count nil
  "Line number as seen by the Gambit process.")

(defvar gambit-input-line-marker-alist nil
  "Alist of line numbers of input blocks and markers.")

(defvar gambit-last-output-marker nil
  "Points to the last character output by the Gambit process.")

;;;----------------------------------------------------------------------------

;; Utilities

(defun gambit-string-count-lines (str)
  "Returns number of complete lines in string."
  (let ((n 0)
        (start 0))
    (while (string-match "\n" str start)
      (setq n (+ n 1))
      (setq start (match-end 0)))
    n))

(defun gambit-string-terminate-with-newline (str)
  "Adds a newline at end of string if it doesn't already have one."
  (let ((len (length str)))
    (if (or (= len 0)
            (not (equal (aref str (- len 1)) ?\n)))
        (concat str "\n")
        str)))

;;;----------------------------------------------------------------------------

;; Define keys for single stepping and continuation crawling.

(defun gambit-step-continuation ()
  (interactive)
  (scheme-send-string "#||#,s;"))

(defun gambit-leap-continuation ()
  (interactive)
  (scheme-send-string "#||#,l;"))

(defun gambit-continue ()
  (interactive)
  (scheme-send-string "#||#,c;"))

(defun gambit-environment ()
  (interactive)
  (scheme-send-string "#||#,e;"))

(defun gambit-backtrace ()
  (interactive)
  (scheme-send-string "#||#,b;"))

(defun gambit-crawl-backtrace-newer ()
  (interactive)
  (scheme-send-string "#||#,-;"))
  
(defun gambit-crawl-backtrace-older ()
  (interactive)
  (scheme-send-string "#||#,+;"))

(defun gambit-kill-last-popup ()
  (interactive)
  (let ((windows gambit-popups))
    (while (not (null windows))
      (let ((window (car windows)))
        (setq windows (cdr windows))
        (if (and window
                 (window-live-p window))
            (progn
              (setq gambit-popups windows)
              (setq windows nil)
              (delete-window window)))))))

(defun gambit-add-popup (popup)
  (setq gambit-popups
        (cons popup (gambit-gc-popups gambit-popups))))

(defun gambit-gc-popups (popups)
  (cond ((null popups)
         '())
        ((window-live-p (car popups))
         (cons (car popups) (gambit-gc-popups (cdr popups))))
        (t
         (gambit-gc-popups (cdr popups)))))

(defvar gambit-popups nil)

;;;----------------------------------------------------------------------------

;; Procedures to intercept and process the location information output
;; by Gambit.

(defun gambit-output-filter (str)
  (let* ((buffer
          (current-buffer))
         (output-marker
          (process-mark (get-buffer-process buffer)))
         (locat
          (if (string-match "\n" str) ; match only after end of line is seen
              (let* ((end
                      (save-excursion
                        (goto-char output-marker)
                        (beginning-of-line)
                        (point)))
                     (start
                      (save-excursion
                        (goto-char (+ gambit-last-output-marker 1))
                        (beginning-of-line)
                        (point))))
                (gambit-extract-location
                 (buffer-substring start end)))
              nil)))
    (gambit-make-read-only buffer output-marker)
    (set-marker gambit-last-output-marker (- output-marker 1))
    (let* ((windows
            (gambit-windows-displaying-buffer buffer))
           (initially-selected-window
            (selected-window)))
      (if (not (null windows))
          (save-excursion
            (set-buffer buffer)
            (select-window (car windows))
            (goto-char output-marker)
            (if (not (pos-visible-in-window-p))
                (recenter -1))
            (select-window initially-selected-window))))
    (if locat
        (gambit-highlight-location locat))))

(defun gambit-extract-location (str)
  (let ((location nil)
        (alist gambit-location-regexp-alist))
    (while (and (not location) (not (null alist)))
      (let* ((regexp (car alist))
             (x (string-match (car regexp) str)))
        (if x
            (let* ((pos1 (nth 1 regexp))
                   (pos2 (nth 2 regexp))
                   (pos3 (nth 3 regexp))
                   (name (substring str
                                    (match-beginning pos1)
                                    (match-end pos1)))
                   (line (substring str
                                    (match-beginning pos2)
                                    (match-end pos2)))
                   (column (substring str
                                      (match-beginning pos3)
                                      (match-end pos3))))
              (setq location (list (read name) (read line) (read column)))))
        (setq alist (cdr alist))))
    location))

(defvar gambit-location-regexp-alist
  '(("\\(\\\"\\(\\\\\\\\\\|\\\\\"\\|[^\\\"\n]\\)+\\\"\\)@\\([0-9]+\\)\\.\\([0-9]+\\)[^0-9]" 1 3 4)
    ("\\((console)\\)@\\([0-9]+\\)\\.\\([0-9]+\\)[^0-9]" 1 2 3)
    ("\\((stdin)\\)@\\([0-9]+\\)\\.\\([0-9]+\\)[^0-9]" 1 2 3)))

(defun gambit-closest-non-following (line alist)
  (let ((closest nil))
    (while (not (null alist))
      (let ((x (car alist)))
        (if (and (<= (car x) line)
                 (or (not closest)
                     (> (car x) (car closest))))
            (setq closest x))
        (setq alist (cdr alist))))
    closest))

(defun gambit-highlight-location (locat)

  ; invariant: the current buffer is the Scheme buffer

  (let ((name (car locat))
        (line (car (cdr locat)))
        (column (car (cdr (cdr locat)))))
    (cond ((or (equal name '(console))
               (equal name '(stdin)))
           (let ((closest
                  (gambit-closest-non-following
                   line
                   gambit-input-line-marker-alist)))
             (if closest
                 (let ((n (- line (car closest))))
                   (gambit-highlight-expression
                    (current-buffer)
                    (save-excursion
                      (goto-char (cdr closest))
                      (if (> n 0) (forward-line n))
                      (forward-char (- column 1))
                      (point)))))))
          ((stringp name)
           (let ((buffer (find-file-noselect name)))
             (if buffer
                 (gambit-highlight-expression
                  buffer
                  (save-excursion
                    (set-buffer buffer)
                    (goto-line line)
                    (forward-char (- column 1))
                    (point)))))))))

(defun gambit-highlight-expression (location-buffer pos)

"Highlight the expression at a specific location in a buffer.

The location buffer is the one that contains the location to
highlight and `pos' points to the first character of the
expression in the buffer.  If the location buffer is not visible
then we must display it in a window.  We also have to make sure
the highlighted expression is visible, which may require the
window to be scrolled.

Our approach is simple: if the location buffer is not visible or
it is the Scheme buffer and it is only displayed in the selected
window, then we split one of the windows in 2 and use the bottom
window to display the location buffer.  The window chosen is
preferentially the topmost window displaying the Scheme buffer,
otherwise it is the selected window.  Before we do the split, we
enlarge the window if it is too small."

  (let* ((location-windows
          (gambit-windows-displaying-buffer location-buffer))
         (initially-selected-window
          (selected-window)))

    ; "location-windows" is the list of windows containing
    ; the location buffer.

    (if (or (null location-windows)
            (and (eq location-buffer (get-buffer scheme-buffer))
                 (eq initially-selected-window (car location-windows))
                 (null (cdr location-windows))))

        (let* ((scheme-windows
                (gambit-windows-displaying-buffer (get-buffer scheme-buffer)))
               (window-to-split
                (if (null scheme-windows)
                    initially-selected-window
                    (car scheme-windows)))
               (height
                (window-height window-to-split)))
          (select-window window-to-split)
          (if (< height (* 2 gambit-new-window-height))
              (enlarge-window
               (- (* 2 gambit-new-window-height)
                  height)))
          (let ((bottom-window
                 (split-window
                  window-to-split
                  (- (window-height window-to-split)
                     gambit-new-window-height))))
            (gambit-add-popup bottom-window)
            (select-window bottom-window)
            (switch-to-buffer location-buffer)))

        (select-window (car (reverse location-windows))))

    ; Highlight the expression in the location buffer.

    (save-excursion
      (set-buffer (window-buffer (selected-window)))
      (goto-char pos)
      (if (not (pos-visible-in-window-p))
          (recenter (- (/ (window-height) 2) 1)))
      (gambit-highlight-region
       location-buffer
       pos
       (progn
         (condition-case nil
           (forward-sexp) ; we assume this uses the same syntax as Gambit
           (error ; if forward-sexp fails with this condition name
            (forward-char 1)))
         (point)))
      (goto-char pos))

    (if (not (eq initially-selected-window (selected-window)))
        (progn
          (goto-char pos)
          (if (not gambit-move-to-highlighted)
              (select-window initially-selected-window))))))

(defun gambit-windows-displaying-buffer (buffer)
  (let ((windows '()))
    (walk-windows (function
                   (lambda (w)
                     (if (eq buffer (window-buffer w))
                         (setq windows (cons w windows)))))
                  t
                  'visible)
    (sort windows
          (function
           (lambda (w1 w2)
             (< (window-top-edge w1)
                (window-top-edge w2)))))))

(defvar gambit-highlight-overlay
  (let ((ovl (make-overlay (point-min) (point-min))))
    (overlay-put ovl 'face gambit-highlight-face)
    ovl)
  "Overlay for highlighting Scheme expressions.")

(defun gambit-highlight-region (buffer start end)
  (if gambit-highlight-overlay
      (move-overlay gambit-highlight-overlay start end buffer)))

(defun gambit-unhighlight ()
  (gambit-highlight-region (get-buffer scheme-buffer) 1 1))

;;;----------------------------------------------------------------------------

(defun gambit-install-comment-syntax ()
  "Configure #| ... |# comments."
  ;; XEmacs 19 and beyond use 8-bit modify-syntax-entry flags.
  ;; Emacs 19 uses a 1-bit flag.  We will have to set up our
  ;; syntax tables differently to handle this.
  ;; Stolen from CC Mode.
  (let ((table (copy-syntax-table))
        entry)
    (modify-syntax-entry ?a ". 12345678" table)
    (cond
     ;; XEmacs 19, and beyond Emacs 19.34
     ((arrayp table)
      (setq entry (aref table ?a))
      ;; In Emacs, table entries are cons cells
      (if (consp entry) (setq entry (car entry))))
     ;; XEmacs 20
     ((fboundp 'get-char-table) (setq entry (get-char-table ?a table)))
     ;; before and including Emacs 19.34
     ((and (fboundp 'char-table-p)
           (char-table-p table))
      (setq entry (car (char-table-range table [?a]))))
     ;; incompatible
     (t (error "Gambit mode is incompatible with this version of Emacs")))
    (if (= (logand (lsh entry -16) 255) 255)
        (progn
          ;; XEmacs 19 & 20
          (modify-syntax-entry ?# "(#58" scheme-mode-syntax-table)
          (modify-syntax-entry ?| ". 67" scheme-mode-syntax-table))
      ;; Emacs 19 & 20
      (modify-syntax-entry ?# "_ 14" scheme-mode-syntax-table)
      (modify-syntax-entry ?| "\" 23" scheme-mode-syntax-table))))

(defun gambit-extend-mode-map (map)
  (define-key map [(f8)]  'gambit-continue)
  (define-key map [(f9)]  'gambit-crawl-backtrace-newer)
  (define-key map [(f10)] 'gambit-crawl-backtrace-older)
  (define-key map [(f11)] 'gambit-step-continuation)
  (define-key map [(f12)] 'gambit-leap-continuation)

  (define-key map "\C-c\C-l" 'gambit-load-file)
  (define-key map "\C-c\C-k" 'gambit-compile-file)

  (let ((prefix gambit-repl-command-prefix))
    (define-key map (concat prefix "c") 'gambit-continue)
    (define-key map (concat prefix "]") 'gambit-crawl-backtrace-newer)
    (define-key map (concat prefix "[") 'gambit-crawl-backtrace-older)
    (define-key map (concat prefix "s") 'gambit-step-continuation)
    (define-key map (concat prefix "l") 'gambit-leap-continuation)
    (define-key map (concat prefix "_") 'gambit-kill-last-popup)))

(defun gambit-inferior-mode ()

  (gambit-install-comment-syntax)
  (gambit-extend-mode-map inferior-scheme-mode-map)

  (make-local-variable 'gambit-input-line-count)
  (setq gambit-input-line-count 1)

  (make-local-variable 'gambit-input-line-marker-alist)
  (setq gambit-input-line-marker-alist '())

  (make-local-variable 'gambit-last-output-marker)
  (setq gambit-last-output-marker (make-marker))
  (set-marker gambit-last-output-marker 0)

  (setq comint-input-sender (function gambit-input-sender))

  (add-hook 'comint-output-filter-functions
            (function gambit-output-filter)
            t
            t)) ; hook is buffer-local

(defun gambit-mode ()
  (gambit-install-comment-syntax)
  (gambit-extend-mode-map scheme-mode-map))

;;(autoload 'gambit-inferior-mode "gambit" "Hook Gambit mode into cmuscheme.")
;;(autoload 'gambit-mode "gambit" "Hook Gambit mode into scheme.")
(add-hook 'inferior-scheme-mode-hook (function gambit-inferior-mode))
(add-hook 'scheme-mode-hook (function gambit-mode))

(provide 'gambit)

;;;----------------------------------------------------------------------------