(simula-font-lock-syntactic-keywords): New var.
[bpt/emacs.git] / lisp / progmodes / scheme.el
CommitLineData
e8af40ee 1;;; scheme.el --- Scheme (and DSSSL) editing mode
c88ab9ce 2
22dcd0d1 3;; Copyright (C) 1986, 87, 88, 97, 1998 Free Software Foundation, Inc.
3a801d0c 4
4228277d 5;; Author: Bill Rozas <jinx@martigny.ai.mit.edu>
d575e99d 6;; Adapted-by: Dave Love <d.love@dl.ac.uk>
d7b4d18f 7;; Keywords: languages, lisp
e5167999 8
ac5b21ac
RS
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
e5167999 13;; the Free Software Foundation; either version 2, or (at your option)
ac5b21ac
RS
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
b578f267
EN
22;; along with GNU Emacs; see the file COPYING. If not, write to the
23;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24;; Boston, MA 02111-1307, USA.
ac5b21ac 25
e5167999 26;;; Commentary:
ac5b21ac 27
1367ff3a
RS
28;; The major mode for editing Scheme-type Lisp code, very similar to
29;; the Lisp mode documented in the Emacs manual. `dsssl-mode' is a
30;; variant of scheme-mode for editing DSSSL specifications for SGML
31;; documents. [As of Apr 1997, some pointers for DSSSL may be found,
32;; for instance, at <URL:http://www.sil.org/sgml/related.html#dsssl>.]
33;; All these Lisp-ish modes vary basically in details of the language
34;; syntax they highlight/indent/index, but dsssl-mode uses "^;;;" as
35;; the page-delimiter since ^L isn't normally a legal SGML character.
36;;
37;; For interacting with a Scheme interpreter See also `run-scheme' in
38;; the `cmuscheme' package and also the implementation-specific
39;; `xscheme' package.
ac5b21ac 40
2b20743d
DL
41;; Here's a recipe to generate a TAGS file for DSSSL, by the way:
42;; etags --lang=scheme --regex='/[ \t]*(\(mode\|element\)[ \t
43;; ]+\([^ \t(
44;; ]+\)/\2/' --regex='/[ \t]*(element[ \t
45;; ]*([^)]+[ \t
46;; ]+\([^)]+\)[ \t
47;; ]*)/\1/' --regex='/(declare[^ \t
48;; ]*[ \t
49;; ]+\([^ \t
50;; ]+\)/\1/' "$@"
51
e5167999 52;;; Code:
ac5b21ac 53\f
1367ff3a
RS
54(require 'lisp-mode)
55
d17f0db5 56(defvar scheme-mode-syntax-table nil)
ac5b21ac
RS
57(if (not scheme-mode-syntax-table)
58 (let ((i 0))
59 (setq scheme-mode-syntax-table (make-syntax-table))
60 (set-syntax-table scheme-mode-syntax-table)
61
62 ;; Default is atom-constituent.
63 (while (< i 256)
64 (modify-syntax-entry i "_ ")
65 (setq i (1+ i)))
66
67 ;; Word components.
68 (setq i ?0)
69 (while (<= i ?9)
70 (modify-syntax-entry i "w ")
71 (setq i (1+ i)))
72 (setq i ?A)
73 (while (<= i ?Z)
74 (modify-syntax-entry i "w ")
75 (setq i (1+ i)))
76 (setq i ?a)
77 (while (<= i ?z)
78 (modify-syntax-entry i "w ")
79 (setq i (1+ i)))
80
81 ;; Whitespace
82 (modify-syntax-entry ?\t " ")
83 (modify-syntax-entry ?\n "> ")
84 (modify-syntax-entry ?\f " ")
85 (modify-syntax-entry ?\r " ")
86 (modify-syntax-entry ? " ")
87
88 ;; These characters are delimiters but otherwise undefined.
89 ;; Brackets and braces balance for editing convenience.
1367ff3a
RS
90 (modify-syntax-entry ?\[ "(] ")
91 (modify-syntax-entry ?\] ")[ ")
ac5b21ac
RS
92 (modify-syntax-entry ?{ "(} ")
93 (modify-syntax-entry ?} "){ ")
94 (modify-syntax-entry ?\| " 23")
95
96 ;; Other atom delimiters
97 (modify-syntax-entry ?\( "() ")
98 (modify-syntax-entry ?\) ")( ")
99 (modify-syntax-entry ?\; "< ")
100 (modify-syntax-entry ?\" "\" ")
101 (modify-syntax-entry ?' " p")
102 (modify-syntax-entry ?` " p")
103
104 ;; Special characters
105 (modify-syntax-entry ?, "_ p")
106 (modify-syntax-entry ?@ "_ p")
107 (modify-syntax-entry ?# "_ p14")
108 (modify-syntax-entry ?\\ "\\ ")))
109\f
d17f0db5 110(defvar scheme-mode-abbrev-table nil)
ac5b21ac
RS
111(define-abbrev-table 'scheme-mode-abbrev-table ())
112
1367ff3a 113(defvar scheme-imenu-generic-expression
d17f0db5 114 '((nil
d575e99d 115 "^(define\\(\\|-\\(generic\\(\\|-procedure\\)\\|method\\)\\)*\\s-+(?\\(\\sw+\\)" 4)
d17f0db5 116 ("Types"
d575e99d 117 "^(define-class\\s-+(?\\(\\sw+\\)" 1)
93a7d76f 118 ("Macros"
d575e99d 119 "^(\\(defmacro\\|define-macro\\|define-syntax\\)\\s-+(?\\(\\sw+\\)" 2))
1367ff3a
RS
120 "Imenu generic expression for Scheme mode. See `imenu-generic-expression'.")
121
ac5b21ac
RS
122(defun scheme-mode-variables ()
123 (set-syntax-table scheme-mode-syntax-table)
124 (setq local-abbrev-table scheme-mode-abbrev-table)
125 (make-local-variable 'paragraph-start)
53e84345 126 (setq paragraph-start (concat "$\\|" page-delimiter))
ac5b21ac
RS
127 (make-local-variable 'paragraph-separate)
128 (setq paragraph-separate paragraph-start)
129 (make-local-variable 'paragraph-ignore-fill-prefix)
130 (setq paragraph-ignore-fill-prefix t)
1367ff3a
RS
131 (make-local-variable 'fill-paragraph-function)
132 (setq fill-paragraph-function 'lisp-fill-paragraph)
133 ;; Adaptive fill mode gets in the way of auto-fill,
134 ;; and should make no difference for explicit fill
135 ;; because lisp-fill-paragraph should do the job.
136 (make-local-variable 'adaptive-fill-mode)
137 (setq adaptive-fill-mode nil)
761aea38
RS
138 (make-local-variable 'normal-auto-fill-function)
139 (setq normal-auto-fill-function 'lisp-mode-auto-fill)
ac5b21ac 140 (make-local-variable 'indent-line-function)
1367ff3a 141 (setq indent-line-function 'lisp-indent-line)
446e6a14
KH
142 (make-local-variable 'parse-sexp-ignore-comments)
143 (setq parse-sexp-ignore-comments t)
1367ff3a
RS
144 (make-local-variable 'outline-regexp)
145 (setq outline-regexp ";;; \\|(....")
ac5b21ac
RS
146 (make-local-variable 'comment-start)
147 (setq comment-start ";")
148 (make-local-variable 'comment-start-skip)
a24c42f7
MB
149 ;; Look within the line for a ; following an even number of backslashes
150 ;; after either a non-backslash or the line beginning.
151 (setq comment-start-skip "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+[ \t]*")
ac5b21ac
RS
152 (make-local-variable 'comment-column)
153 (setq comment-column 40)
e41b2db1 154 (make-local-variable 'comment-indent-function)
1367ff3a 155 (setq comment-indent-function 'lisp-comment-indent)
2441d53d
RS
156 (make-local-variable 'parse-sexp-ignore-comments)
157 (setq parse-sexp-ignore-comments t)
1367ff3a
RS
158 (make-local-variable 'lisp-indent-function)
159 (set lisp-indent-function 'scheme-indent-function)
160 (setq mode-line-process '("" scheme-mode-line-process))
1b9a1e9d 161 (set (make-local-variable 'imenu-case-fold-search) t)
c0b08eb0 162 (setq imenu-generic-expression scheme-imenu-generic-expression)
1b9a1e9d
DL
163 (set (make-local-variable 'imenu-syntax-alist)
164 '(("+-*/.<>=?!$%_&~^:" . "w")))
d17f0db5 165 (make-local-variable 'font-lock-defaults)
22dcd0d1
DL
166 (setq font-lock-defaults
167 '((scheme-font-lock-keywords
168 scheme-font-lock-keywords-1 scheme-font-lock-keywords-2)
169 nil t (("+-*/.<>=!?$%_&~^:" . "w")) beginning-of-defun
170 (font-lock-mark-block-function . mark-defun))))
ac5b21ac
RS
171
172(defvar scheme-mode-line-process "")
173
ece8c34d 174(defvar scheme-mode-map nil
d3461e8f 175 "Keymap for Scheme mode.
ece8c34d
DL
176All commands in `lisp-mode-shared-map' are inherited by this map.")
177
178(unless scheme-mode-map
179 (let ((map (make-sparse-keymap "Scheme")))
180 (setq scheme-mode-map (make-sparse-keymap))
181 (set-keymap-parent scheme-mode-map lisp-mode-shared-map)
182 (define-key scheme-mode-map [menu-bar] (make-sparse-keymap))
183 (define-key scheme-mode-map [menu-bar scheme]
184 (cons "Scheme" map))
185 (define-key map [run-scheme] '("Run Inferior Scheme" . run-scheme))
186 (define-key map [uncomment-region]
187 '("Uncomment Out Region" . (lambda (beg end)
188 (interactive "r")
189 (comment-region beg end '(4)))))
190 (define-key map [comment-region] '("Comment Out Region" . comment-region))
191 (define-key map [indent-region] '("Indent Region" . indent-region))
192 (define-key map [indent-line] '("Indent Line" . lisp-indent-line))
193 (put 'comment-region 'menu-enable 'mark-active)
194 (put 'uncomment-region 'menu-enable 'mark-active)
195 (put 'indent-region 'menu-enable 'mark-active)))
1367ff3a
RS
196
197;; Used by cmuscheme
ac5b21ac 198(defun scheme-mode-commands (map)
48879301 199 ;;(define-key map "\t" 'indent-for-tab-command) ; default
ac5b21ac 200 (define-key map "\177" 'backward-delete-char-untabify)
48879301 201 (define-key map "\e\C-q" 'indent-sexp))
ac5b21ac 202\f
e2ab0aa6 203;;;###autoload
ac5b21ac
RS
204(defun scheme-mode ()
205 "Major mode for editing Scheme code.
d17f0db5 206Editing commands are similar to those of `lisp-mode'.
ac5b21ac
RS
207
208In addition, if an inferior Scheme process is running, some additional
209commands will be defined, for evaluating expressions and controlling
210the interpreter, and the state of the process will be displayed in the
211modeline of all Scheme buffers. The names of commands that interact
1b9a1e9d
DL
212with the Scheme process start with \"xscheme-\" if you use the MIT
213Scheme-specific `xscheme' package; for more information see the
214documentation for `xscheme-interaction-mode'. Use \\[run-scheme] to
215start an inferior Scheme using the more general `cmuscheme' package.
ac5b21ac
RS
216
217Commands:
218Delete converts tabs to spaces as it moves back.
219Blank lines separate paragraphs. Semicolons start comments.
220\\{scheme-mode-map}
d17f0db5 221Entry to this mode calls the value of `scheme-mode-hook'
ac5b21ac
RS
222if that value is non-nil."
223 (interactive)
224 (kill-all-local-variables)
225 (scheme-mode-initialize)
226 (scheme-mode-variables)
227 (run-hooks 'scheme-mode-hook))
228
229(defun scheme-mode-initialize ()
230 (use-local-map scheme-mode-map)
231 (setq major-mode 'scheme-mode)
232 (setq mode-name "Scheme"))
233
48879301
RS
234(defgroup scheme nil
235 "Editing Scheme code"
236 :group 'lisp)
237
238(defcustom scheme-mit-dialect t
ac5b21ac 239 "If non-nil, scheme mode is specialized for MIT Scheme.
48879301
RS
240Set this to nil if you normally use another dialect."
241 :type 'boolean
242 :group 'scheme)
1367ff3a 243
48879301 244(defcustom dsssl-sgml-declaration
1367ff3a
RS
245 "<!DOCTYPE style-sheet PUBLIC \"-//James Clark//DTD DSSSL Style Sheet//EN\">
246"
48879301 247 "*An SGML declaration for the DSSSL file.
2b20743d 248If it is defined as a string this will be inserted into an empty buffer
d17f0db5 249which is in `dsssl-mode'. It is typically James Clark's style-sheet
48879301 250doctype, as required for Jade."
d17f0db5 251 :type '(choice (string :tag "Specified string")
2b20743d
DL
252 (const :tag "None" :value nil))
253 :group 'scheme)
254
255(defcustom scheme-mode-hook nil
d17f0db5 256 "Normal hook run when entering `scheme-mode'.
2b20743d
DL
257See `run-hooks'."
258 :type 'hook
259 :group 'scheme)
260
261(defcustom dsssl-mode-hook nil
d17f0db5 262 "Normal hook run when entering `dsssl-mode'.
2b20743d
DL
263See `run-hooks'."
264 :type 'hook
48879301 265 :group 'scheme)
1367ff3a 266
f7a6110d
DL
267;; This is shared by cmuscheme and xscheme.
268(defcustom scheme-program-name "scheme"
269 "*Program invoked by the `run-scheme' command."
270 :type 'string
271 :group 'scheme)
272
1367ff3a
RS
273(defvar dsssl-imenu-generic-expression
274 ;; Perhaps this should also look for the style-sheet DTD tags. I'm
275 ;; not sure it's the best way to organize it; perhaps one type
276 ;; should be at the first level, though you don't see this anyhow if
277 ;; it gets split up.
d17f0db5 278 '(("Defines"
d575e99d 279 "^(define\\s-+(?\\(\\sw+\\)" 1)
93a7d76f 280 ("Modes"
d575e99d 281 "^\\s-*(mode\\s-+\\(\\(\\sw\\|\\s-\\)+\\)" 1)
93a7d76f 282 ("Elements"
1367ff3a 283 ;; (element foo ...) or (element (foo bar ...) ...)
26d05e22 284 ;; Fixme: Perhaps it should do `root'.
d575e99d 285 "^\\s-*(element\\s-+(?\\(\\(\\sw\\|\\s-\\)+\\))?" 1)
d17f0db5 286 ("Declarations"
d575e99d 287 "^(declare\\(-\\sw+\\)+\\>\\s-+\\(\\sw+\\)" 2))
1367ff3a
RS
288 "Imenu generic expression for DSSSL mode. See `imenu-generic-expression'.")
289
22dcd0d1
DL
290(defconst scheme-font-lock-keywords-1
291 (eval-when-compile
292 (list
293 ;;
294 ;; Declarations. Hannes Haug <hannes.haug@student.uni-tuebingen.de> says
295 ;; this works for SOS, STklos, SCOOPS, Meroon and Tiny CLOS.
405ff5ea 296 (list (concat "(\\(define\\*?\\("
22dcd0d1 297 ;; Function names.
405ff5ea 298 "\\(\\|-public\\|-method\\|-generic\\(-procedure\\)?\\)\\|"
22dcd0d1 299 ;; Macro names, as variable names. A bit dubious, this.
1b9a1e9d 300 "\\(-syntax\\|-macro\\)\\|"
22dcd0d1
DL
301 ;; Class names.
302 "-class"
405ff5ea
RS
303 ;; Guile modules.
304 "\\|-module"
22dcd0d1
DL
305 "\\)\\)\\>"
306 ;; Any whitespace and declared object.
307 "[ \t]*(?"
308 "\\(\\sw+\\)?")
309 '(1 font-lock-keyword-face)
310 '(6 (cond ((match-beginning 3) font-lock-function-name-face)
311 ((match-beginning 5) font-lock-variable-name-face)
312 (t font-lock-type-face))
313 nil t))
314 ))
315 "Subdued expressions to highlight in Scheme modes.")
316
317(defconst scheme-font-lock-keywords-2
318 (append scheme-font-lock-keywords-1
319 (eval-when-compile
320 (list
321 ;;
322 ;; Control structures.
323 (cons
324 (concat
325 "(" (regexp-opt
326 '("begin" "call-with-current-continuation" "call/cc"
327 "call-with-input-file" "call-with-output-file" "case" "cond"
328 "do" "else" "for-each" "if" "lambda"
329 "let" "let*" "let-syntax" "letrec" "letrec-syntax"
330 ;; Hannes Haug <hannes.haug@student.uni-tuebingen.de> wants:
331 "and" "or" "delay"
332 ;; Stefan Monnier <stefan.monnier@epfl.ch> says don't bother:
333 ;;"quasiquote" "quote" "unquote" "unquote-splicing"
334 "map" "syntax" "syntax-rules") t)
335 "\\>") 1)
336 ;;
337 ;; David Fox <fox@graphics.cs.nyu.edu> for SOS/STklos class specifiers.
338 '("\\<<\\sw+>\\>" . font-lock-type-face)
339 ;;
340 ;; Scheme `:' keywords as builtins.
341 '("\\<:\\sw+\\>" . font-lock-builtin-face)
342 )))
343 "Gaudy expressions to highlight in Scheme modes.")
344
345(defvar scheme-font-lock-keywords scheme-font-lock-keywords-1
346 "Default expressions to highlight in Scheme modes.")
347
1367ff3a
RS
348;;;###autoload
349(defun dsssl-mode ()
350 "Major mode for editing DSSSL code.
d17f0db5 351Editing commands are similar to those of `lisp-mode'.
1367ff3a
RS
352
353Commands:
354Delete converts tabs to spaces as it moves back.
355Blank lines separate paragraphs. Semicolons start comments.
356\\{scheme-mode-map}
22dcd0d1
DL
357Entering this mode runs the hooks `scheme-mode-hook' and then
358`dsssl-mode-hook' and inserts the value of `dsssl-sgml-declaration' if
359that variable's value is a string."
1367ff3a
RS
360 (interactive)
361 (kill-all-local-variables)
362 (use-local-map scheme-mode-map)
363 (scheme-mode-initialize)
1367ff3a
RS
364 (make-local-variable 'page-delimiter)
365 (setq page-delimiter "^;;;" ; ^L not valid SGML char
366 major-mode 'dsssl-mode
367 mode-name "DSSSL")
368 ;; Insert a suitable SGML declaration into an empty buffer.
369 (and (zerop (buffer-size))
26d05e22 370 (stringp dsssl-sgml-declaration)
1367ff3a
RS
371 (not buffer-read-only)
372 (insert dsssl-sgml-declaration))
1367ff3a 373 (scheme-mode-variables)
22dcd0d1
DL
374 (setq font-lock-defaults '(dsssl-font-lock-keywords
375 nil t (("+-*/.<>=?$%_&~^:" . "w"))
376 beginning-of-defun
377 (font-lock-mark-block-function . mark-defun)))
1b9a1e9d 378 (set (make-local-variable 'imenu-case-fold-search) nil)
c0b08eb0 379 (setq imenu-generic-expression dsssl-imenu-generic-expression)
1b9a1e9d
DL
380 (set (make-local-variable 'imenu-syntax-alist)
381 '(("+-*/.<>=?$%_&~^:" . "w")))
22dcd0d1
DL
382 (run-hooks 'scheme-mode-hook)
383 (run-hooks 'dsssl-mode-hook))
1367ff3a
RS
384
385;; Extra syntax for DSSSL. This isn't separated from Scheme, but
386;; shouldn't cause much trouble in scheme-mode.
387(put 'element 'scheme-indent-function 1)
388(put 'mode 'scheme-indent-function 1)
389(put 'with-mode 'scheme-indent-function 1)
2f5029f3 390(put 'make 'scheme-indent-function 1)
26d05e22
RS
391(put 'style 'scheme-indent-function 1)
392(put 'root 'scheme-indent-function 1)
1367ff3a
RS
393
394(defvar dsssl-font-lock-keywords
26d05e22
RS
395 (eval-when-compile
396 (list
397 ;; Similar to Scheme
398 (list "(\\(define\\(-\\w+\\)?\\)\\>[ ]*\\\((?\\)\\(\\sw+\\)\\>"
399 '(1 font-lock-keyword-face)
400 '(4 font-lock-function-name-face))
401 (cons
402 (concat "(\\("
403 ;; (make-regexp '("case" "cond" "else" "if" "lambda"
404 ;; "let" "let*" "letrec" "and" "or" "map" "with-mode"))
405 "and\\|c\\(ase\\|ond\\)\\|else\\|if\\|"
406 "l\\(ambda\\|et\\(\\|*\\|rec\\)\\)\\|map\\|or\\|with-mode"
407 "\\)\\>")
408 1)
409 ;; DSSSL syntax
410 '("(\\(element\\|mode\\|declare-\\w+\\)\\>[ ]*\\(\\sw+\\)"
411 (1 font-lock-keyword-face)
412 (2 font-lock-type-face))
413 '("(\\(element\\)\\>[ ]*(\\(\\S)+\\))"
414 (1 font-lock-keyword-face)
415 (2 font-lock-type-face))
883212ce 416 '("\\<\\sw+:\\>" . font-lock-constant-face) ; trailing `:' c.f. scheme
26d05e22
RS
417 ;; SGML markup (from sgml-mode) :
418 '("<\\([!?][-a-z0-9]+\\)" 1 font-lock-keyword-face)
419 '("<\\(/?[-a-z0-9]+\\)" 1 font-lock-function-name-face)))
1367ff3a
RS
420 "Default expressions to highlight in DSSSL mode.")
421
ac5b21ac 422\f
1367ff3a
RS
423(defvar calculate-lisp-indent-last-sexp)
424
425;; Copied from lisp-indent-function, but with gets of
426;; scheme-indent-{function,hook}.
ac5b21ac
RS
427(defun scheme-indent-function (indent-point state)
428 (let ((normal-indent (current-column)))
1367ff3a
RS
429 (goto-char (1+ (elt state 1)))
430 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
431 (if (and (elt state 2)
432 (not (looking-at "\\sw\\|\\s_")))
4696802b 433 ;; car of form doesn't seem to be a symbol
1367ff3a
RS
434 (progn
435 (if (not (> (save-excursion (forward-line 1) (point))
436 calculate-lisp-indent-last-sexp))
437 (progn (goto-char calculate-lisp-indent-last-sexp)
438 (beginning-of-line)
439 (parse-partial-sexp (point)
440 calculate-lisp-indent-last-sexp 0 t)))
441 ;; Indent under the list or under the first sexp on the same
442 ;; line as calculate-lisp-indent-last-sexp. Note that first
443 ;; thing on that line has to be complete sexp since we are
444 ;; inside the innermost containing sexp.
445 (backward-prefix-chars)
446 (current-column))
447 (let ((function (buffer-substring (point)
448 (progn (forward-sexp 1) (point))))
449 method)
450 (setq method (or (get (intern-soft function) 'scheme-indent-function)
451 (get (intern-soft function) 'scheme-indent-hook)))
452 (cond ((or (eq method 'defun)
453 (and (null method)
454 (> (length function) 3)
455 (string-match "\\`def" function)))
456 (lisp-indent-defform state indent-point))
457 ((integerp method)
458 (lisp-indent-specform method state
459 indent-point normal-indent))
460 (method
61185f42 461 (funcall method state indent-point normal-indent)))))))
1367ff3a 462
ac5b21ac
RS
463\f
464;;; Let is different in Scheme
465
466(defun would-be-symbol (string)
467 (not (string-equal (substring string 0 1) "(")))
468
469(defun next-sexp-as-string ()
d17f0db5 470 ;; Assumes that it is protected by a save-excursion
ac5b21ac
RS
471 (forward-sexp 1)
472 (let ((the-end (point)))
473 (backward-sexp 1)
474 (buffer-substring (point) the-end)))
475
476;; This is correct but too slow.
477;; The one below works almost always.
478;;(defun scheme-let-indent (state indent-point)
479;; (if (would-be-symbol (next-sexp-as-string))
480;; (scheme-indent-specform 2 state indent-point)
481;; (scheme-indent-specform 1 state indent-point)))
482
61185f42 483(defun scheme-let-indent (state indent-point normal-indent)
ac5b21ac 484 (skip-chars-forward " \t")
61361a07 485 (if (looking-at "[-a-zA-Z0-9+*/?!@$%^&_:~]")
61185f42
KH
486 (lisp-indent-specform 2 state indent-point normal-indent)
487 (lisp-indent-specform 1 state indent-point normal-indent)))
ac5b21ac
RS
488
489;; (put 'begin 'scheme-indent-function 0), say, causes begin to be indented
490;; like defun if the first form is placed on the next line, otherwise
491;; it is indented like any other form (i.e. forms line up under first).
492
493(put 'begin 'scheme-indent-function 0)
494(put 'case 'scheme-indent-function 1)
495(put 'delay 'scheme-indent-function 0)
496(put 'do 'scheme-indent-function 2)
497(put 'lambda 'scheme-indent-function 1)
498(put 'let 'scheme-indent-function 'scheme-let-indent)
499(put 'let* 'scheme-indent-function 1)
500(put 'letrec 'scheme-indent-function 1)
2b20743d
DL
501(put 'sequence 'scheme-indent-function 0) ; SICP, not r4rs
502(put 'let-syntax 'scheme-indent-function 1)
503(put 'letrec-syntax 'scheme-indent-function 1)
504(put 'syntax-rules 'scheme-indent-function 1)
0ec2c350 505(put 'syntax-case 'scheme-indent-function 2) ; not r5rs
ac5b21ac
RS
506
507(put 'call-with-input-file 'scheme-indent-function 1)
508(put 'with-input-from-file 'scheme-indent-function 1)
509(put 'with-input-from-port 'scheme-indent-function 1)
510(put 'call-with-output-file 'scheme-indent-function 1)
511(put 'with-output-to-file 'scheme-indent-function 1)
512(put 'with-output-to-port 'scheme-indent-function 1)
2b20743d
DL
513(put 'call-with-values 'scheme-indent-function 1) ; r5rs?
514(put 'dynamic-wind 'scheme-indent-function 3) ; r5rs?
ac5b21ac
RS
515\f
516;;;; MIT Scheme specific indentation.
517
518(if scheme-mit-dialect
519 (progn
520 (put 'fluid-let 'scheme-indent-function 1)
521 (put 'in-package 'scheme-indent-function 1)
ac5b21ac
RS
522 (put 'local-declare 'scheme-indent-function 1)
523 (put 'macro 'scheme-indent-function 1)
524 (put 'make-environment 'scheme-indent-function 0)
525 (put 'named-lambda 'scheme-indent-function 1)
526 (put 'using-syntax 'scheme-indent-function 1)
527
528 (put 'with-input-from-string 'scheme-indent-function 1)
529 (put 'with-output-to-string 'scheme-indent-function 0)
530 (put 'with-values 'scheme-indent-function 1)
531
532 (put 'syntax-table-define 'scheme-indent-function 2)
533 (put 'list-transform-positive 'scheme-indent-function 1)
534 (put 'list-transform-negative 'scheme-indent-function 1)
535 (put 'list-search-positive 'scheme-indent-function 1)
536 (put 'list-search-negative 'scheme-indent-function 1)
537
538 (put 'access-components 'scheme-indent-function 1)
539 (put 'assignment-components 'scheme-indent-function 1)
540 (put 'combination-components 'scheme-indent-function 1)
541 (put 'comment-components 'scheme-indent-function 1)
542 (put 'conditional-components 'scheme-indent-function 1)
543 (put 'disjunction-components 'scheme-indent-function 1)
544 (put 'declaration-components 'scheme-indent-function 1)
545 (put 'definition-components 'scheme-indent-function 1)
546 (put 'delay-components 'scheme-indent-function 1)
547 (put 'in-package-components 'scheme-indent-function 1)
548 (put 'lambda-components 'scheme-indent-function 1)
549 (put 'lambda-components* 'scheme-indent-function 1)
550 (put 'lambda-components** 'scheme-indent-function 1)
551 (put 'open-block-components 'scheme-indent-function 1)
552 (put 'pathname-components 'scheme-indent-function 1)
553 (put 'procedure-components 'scheme-indent-function 1)
554 (put 'sequence-components 'scheme-indent-function 1)
555 (put 'unassigned\?-components 'scheme-indent-function 1)
556 (put 'unbound\?-components 'scheme-indent-function 1)
557 (put 'variable-components 'scheme-indent-function 1)))
49116ac0
JB
558
559(provide 'scheme)
c88ab9ce
ER
560
561;;; scheme.el ends here