0
|
1 ;;; scheme.el --- Scheme mode, and its idiosyncratic commands.
|
|
2
|
|
3 ;; Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
|
2
|
4
|
|
5 ;; Author: Bill Rozas <jinz@prep.ai.mit.edu>
|
|
6 ;; Keywords: languages, lisp
|
0
|
7
|
|
8 ;; This file is part of XEmacs.
|
|
9
|
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
11 ;; under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 ;; General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
|
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
2
|
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
23 ;; 02111-1307, USA.
|
0
|
24
|
2
|
25 ;;; Synched up with: FSF 19.34.
|
0
|
26
|
2
|
27 ;;; Commentary:
|
|
28
|
|
29 ;; Adapted from Lisp mode by Bill Rozas, jinx@prep.
|
0
|
30 ;; Initially a query replace of Lisp mode, except for the indentation
|
|
31 ;; of special forms. Probably the code should be merged at some point
|
|
32 ;; so that there is sharing between both libraries.
|
|
33
|
2
|
34 ;;; Code:
|
0
|
35
|
|
36 (defvar scheme-mode-syntax-table nil "")
|
|
37 (if (not scheme-mode-syntax-table)
|
|
38 (let ((i 0))
|
|
39 (setq scheme-mode-syntax-table (make-syntax-table))
|
|
40 (set-syntax-table scheme-mode-syntax-table)
|
|
41
|
|
42 ;; Default is atom-constituent.
|
|
43 (while (< i 256)
|
|
44 (modify-syntax-entry i "_ ")
|
|
45 (setq i (1+ i)))
|
|
46
|
|
47 ;; Word components.
|
|
48 (setq i ?0)
|
|
49 (while (<= i ?9)
|
|
50 (modify-syntax-entry i "w ")
|
|
51 (setq i (1+ i)))
|
|
52 (setq i ?A)
|
|
53 (while (<= i ?Z)
|
|
54 (modify-syntax-entry i "w ")
|
|
55 (setq i (1+ i)))
|
|
56 (setq i ?a)
|
|
57 (while (<= i ?z)
|
|
58 (modify-syntax-entry i "w ")
|
|
59 (setq i (1+ i)))
|
|
60
|
|
61 ;; Whitespace
|
|
62 (modify-syntax-entry ?\t " ")
|
|
63 (modify-syntax-entry ?\n "> ")
|
|
64 (modify-syntax-entry ?\f " ")
|
|
65 (modify-syntax-entry ?\r " ")
|
|
66 (modify-syntax-entry ? " ")
|
|
67
|
|
68 ;; These characters are delimiters but otherwise undefined.
|
|
69 ;; Brackets and braces balance for editing convenience.
|
|
70 (modify-syntax-entry ?[ "(] ")
|
|
71 (modify-syntax-entry ?] ")[ ")
|
|
72 (modify-syntax-entry ?{ "(} ")
|
|
73 (modify-syntax-entry ?} "){ ")
|
|
74 (modify-syntax-entry ?\| " 23")
|
|
75
|
|
76 ;; Other atom delimiters
|
|
77 (modify-syntax-entry ?\( "() ")
|
|
78 (modify-syntax-entry ?\) ")( ")
|
|
79 (modify-syntax-entry ?\; "< ")
|
|
80 (modify-syntax-entry ?\" "\" ")
|
|
81 (modify-syntax-entry ?' " p")
|
|
82 (modify-syntax-entry ?` " p")
|
|
83
|
|
84 ;; Special characters
|
|
85 (modify-syntax-entry ?, "_ p")
|
|
86 (modify-syntax-entry ?@ "_ p")
|
|
87 (modify-syntax-entry ?# "_ p14")
|
|
88 (modify-syntax-entry ?\\ "\\ ")))
|
|
89
|
|
90 (defvar scheme-mode-abbrev-table nil "")
|
|
91 (define-abbrev-table 'scheme-mode-abbrev-table ())
|
|
92
|
|
93 (defun scheme-mode-variables ()
|
|
94 (set-syntax-table scheme-mode-syntax-table)
|
|
95 (setq local-abbrev-table scheme-mode-abbrev-table)
|
|
96 (make-local-variable 'paragraph-start)
|
2
|
97 (setq paragraph-start (concat "$\\|" page-delimiter))
|
0
|
98 (make-local-variable 'paragraph-separate)
|
|
99 (setq paragraph-separate paragraph-start)
|
|
100 (make-local-variable 'paragraph-ignore-fill-prefix)
|
|
101 (setq paragraph-ignore-fill-prefix t)
|
|
102 (make-local-variable 'indent-line-function)
|
|
103 (setq indent-line-function 'scheme-indent-line)
|
2
|
104 (make-local-variable 'parse-sexp-ignore-comments)
|
|
105 (setq parse-sexp-ignore-comments t)
|
0
|
106 (make-local-variable 'comment-start)
|
|
107 (setq comment-start ";")
|
|
108 (make-local-variable 'comment-start-skip)
|
2
|
109 ;; Look within the line for a ; following an even number of backslashes
|
|
110 ;; after either a non-backslash or the line beginning.
|
|
111 (setq comment-start-skip "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+[ \t]*")
|
0
|
112 (make-local-variable 'comment-column)
|
|
113 (setq comment-column 40)
|
2
|
114 (make-local-variable 'comment-indent-function)
|
|
115 (setq comment-indent-function 'scheme-comment-indent)
|
|
116 (make-local-variable 'parse-sexp-ignore-comments)
|
|
117 (setq parse-sexp-ignore-comments t)
|
0
|
118 (setq mode-line-process '("" scheme-mode-line-process)))
|
|
119
|
|
120 (defvar scheme-mode-line-process "")
|
|
121
|
|
122 (defun scheme-mode-commands (map)
|
|
123 (define-key map "\t" 'scheme-indent-line)
|
|
124 (define-key map "\177" 'backward-delete-char-untabify)
|
|
125 (define-key map "\e\C-q" 'scheme-indent-sexp))
|
|
126
|
|
127 (defvar scheme-mode-map nil)
|
|
128 (if (not scheme-mode-map)
|
|
129 (progn
|
|
130 (setq scheme-mode-map (make-sparse-keymap))
|
|
131 (scheme-mode-commands scheme-mode-map)))
|
|
132
|
|
133 ;;;###autoload
|
|
134 (defun scheme-mode ()
|
|
135 "Major mode for editing Scheme code.
|
|
136 Editing commands are similar to those of lisp-mode.
|
|
137
|
|
138 In addition, if an inferior Scheme process is running, some additional
|
|
139 commands will be defined, for evaluating expressions and controlling
|
|
140 the interpreter, and the state of the process will be displayed in the
|
|
141 modeline of all Scheme buffers. The names of commands that interact
|
|
142 with the Scheme process start with \"xscheme-\". For more information
|
|
143 see the documentation for xscheme-interaction-mode.
|
|
144
|
|
145 Commands:
|
|
146 Delete converts tabs to spaces as it moves back.
|
|
147 Blank lines separate paragraphs. Semicolons start comments.
|
|
148 \\{scheme-mode-map}
|
|
149 Entry to this mode calls the value of scheme-mode-hook
|
|
150 if that value is non-nil."
|
|
151 (interactive)
|
|
152 (kill-all-local-variables)
|
|
153 (scheme-mode-initialize)
|
|
154 (scheme-mode-variables)
|
|
155 (run-hooks 'scheme-mode-hook))
|
|
156
|
|
157 (defun scheme-mode-initialize ()
|
|
158 (use-local-map scheme-mode-map)
|
|
159 (setq major-mode 'scheme-mode)
|
|
160 (setq mode-name "Scheme"))
|
|
161
|
|
162 (defvar scheme-mit-dialect t
|
|
163 "If non-nil, scheme mode is specialized for MIT Scheme.
|
|
164 Set this to nil if you normally use another dialect.")
|
|
165
|
|
166 (defun scheme-comment-indent (&optional pos)
|
|
167 (save-excursion
|
|
168 (if pos (goto-char pos))
|
|
169 (cond ((looking-at ";;;") (current-column))
|
|
170 ((looking-at ";;")
|
|
171 (let ((tem (calculate-scheme-indent)))
|
|
172 (if (listp tem) (car tem) tem)))
|
|
173 (t
|
|
174 (skip-chars-backward " \t")
|
|
175 (max (if (bolp) 0 (1+ (current-column)))
|
|
176 comment-column)))))
|
|
177
|
|
178 (defvar scheme-indent-offset nil "")
|
|
179 (defvar scheme-indent-function 'scheme-indent-function "")
|
|
180
|
|
181 (defun scheme-indent-line (&optional whole-exp)
|
|
182 "Indent current line as Scheme code.
|
|
183 With argument, indent any additional lines of the same expression
|
|
184 rigidly along with this one."
|
|
185 (interactive "P")
|
|
186 (let ((indent (calculate-scheme-indent)) shift-amt beg end
|
|
187 (pos (- (point-max) (point))))
|
|
188 (beginning-of-line)
|
|
189 (setq beg (point))
|
|
190 (skip-chars-forward " \t")
|
|
191 (if (looking-at "[ \t]*;;;")
|
|
192 ;; Don't alter indentation of a ;;; comment line.
|
|
193 nil
|
|
194 (if (listp indent) (setq indent (car indent)))
|
|
195 (setq shift-amt (- indent (current-column)))
|
|
196 (if (zerop shift-amt)
|
|
197 nil
|
|
198 (delete-region beg (point))
|
|
199 (indent-to indent))
|
|
200 ;; If initial point was within line's indentation,
|
|
201 ;; position after the indentation. Else stay at same point in text.
|
|
202 (if (> (- (point-max) pos) (point))
|
|
203 (goto-char (- (point-max) pos)))
|
|
204 ;; If desired, shift remaining lines of expression the same amount.
|
|
205 (and whole-exp (not (zerop shift-amt))
|
|
206 (save-excursion
|
|
207 (goto-char beg)
|
|
208 (forward-sexp 1)
|
|
209 (setq end (point))
|
|
210 (goto-char beg)
|
|
211 (forward-line 1)
|
|
212 (setq beg (point))
|
|
213 (> end beg))
|
|
214 (indent-code-rigidly beg end shift-amt)))))
|
|
215
|
|
216 (defun calculate-scheme-indent (&optional parse-start)
|
|
217 "Return appropriate indentation for current line as scheme code.
|
|
218 In usual case returns an integer: the column to indent to.
|
|
219 Can instead return a list, whose car is the column to indent to.
|
|
220 This means that following lines at the same level of indentation
|
|
221 should not necessarily be indented the same way.
|
|
222 The second element of the list is the buffer position
|
|
223 of the start of the containing expression."
|
|
224 (save-excursion
|
|
225 (beginning-of-line)
|
|
226 (let ((indent-point (point)) state paren-depth desired-indent (retry t)
|
|
227 last-sexp containing-sexp first-sexp-list-p)
|
|
228 (if parse-start
|
|
229 (goto-char parse-start)
|
|
230 (beginning-of-defun))
|
|
231 ;; Find outermost containing sexp
|
|
232 (while (< (point) indent-point)
|
|
233 (setq state (parse-partial-sexp (point) indent-point 0)))
|
|
234 ;; Find innermost containing sexp
|
|
235 (while (and retry (setq paren-depth (car state)) (> paren-depth 0))
|
|
236 (setq retry nil)
|
|
237 (setq last-sexp (nth 2 state))
|
|
238 (setq containing-sexp (car (cdr state)))
|
|
239 ;; Position following last unclosed open.
|
|
240 (goto-char (1+ containing-sexp))
|
|
241 ;; Is there a complete sexp since then?
|
|
242 (if (and last-sexp (> last-sexp (point)))
|
|
243 ;; Yes, but is there a containing sexp after that?
|
|
244 (let ((peek (parse-partial-sexp last-sexp indent-point 0)))
|
|
245 (if (setq retry (car (cdr peek))) (setq state peek))))
|
|
246 (if (not retry)
|
|
247 ;; Innermost containing sexp found
|
|
248 (progn
|
|
249 (goto-char (1+ containing-sexp))
|
|
250 (if (not last-sexp)
|
|
251 ;; indent-point immediately follows open paren.
|
|
252 ;; Don't call hook.
|
|
253 (setq desired-indent (current-column))
|
|
254 ;; Move to first sexp after containing open paren
|
|
255 (parse-partial-sexp (point) last-sexp 0 t)
|
|
256 (setq first-sexp-list-p (looking-at "\\s("))
|
|
257 (cond
|
|
258 ((> (save-excursion (forward-line 1) (point))
|
|
259 last-sexp)
|
|
260 ;; Last sexp is on same line as containing sexp.
|
|
261 ;; It's almost certainly a function call.
|
|
262 (parse-partial-sexp (point) last-sexp 0 t)
|
|
263 (if (/= (point) last-sexp)
|
|
264 ;; Indent beneath first argument or, if only one sexp
|
|
265 ;; on line, indent beneath that.
|
|
266 (progn (forward-sexp 1)
|
|
267 (parse-partial-sexp (point) last-sexp 0 t)))
|
|
268 (backward-prefix-chars))
|
|
269 (t
|
|
270 ;; Indent beneath first sexp on same line as last-sexp.
|
|
271 ;; Again, it's almost certainly a function call.
|
|
272 (goto-char last-sexp)
|
|
273 (beginning-of-line)
|
|
274 (parse-partial-sexp (point) last-sexp 0 t)
|
|
275 (backward-prefix-chars)))))))
|
|
276 ;; If looking at a list, don't call hook.
|
|
277 (if first-sexp-list-p
|
|
278 (setq desired-indent (current-column)))
|
|
279 ;; Point is at the point to indent under unless we are inside a string.
|
2
|
280 ;; Call indentation hook except when overridden by scheme-indent-offset
|
0
|
281 ;; or if the desired indentation has already been computed.
|
|
282 (cond ((car (nthcdr 3 state))
|
|
283 ;; Inside a string, don't change indentation.
|
|
284 (goto-char indent-point)
|
|
285 (skip-chars-forward " \t")
|
|
286 (setq desired-indent (current-column)))
|
|
287 ((and (integerp scheme-indent-offset) containing-sexp)
|
|
288 ;; Indent by constant offset
|
|
289 (goto-char containing-sexp)
|
|
290 (setq desired-indent (+ scheme-indent-offset (current-column))))
|
|
291 ((not (or desired-indent
|
|
292 (and (boundp 'scheme-indent-function)
|
|
293 scheme-indent-function
|
|
294 (not retry)
|
|
295 (setq desired-indent
|
|
296 (funcall scheme-indent-function
|
|
297 indent-point state)))))
|
|
298 ;; Use default indentation if not computed yet
|
|
299 (setq desired-indent (current-column))))
|
|
300 desired-indent)))
|
|
301
|
|
302 (defun scheme-indent-function (indent-point state)
|
|
303 (let ((normal-indent (current-column)))
|
|
304 (save-excursion
|
|
305 (goto-char (1+ (car (cdr state))))
|
|
306 (re-search-forward "\\sw\\|\\s_")
|
|
307 (if (/= (point) (car (cdr state)))
|
|
308 (let ((function (buffer-substring (progn (forward-char -1) (point))
|
|
309 (progn (forward-sexp 1) (point))))
|
|
310 method)
|
|
311 ;; Who cares about this, really?
|
|
312 ;(if (not (string-match "\\\\\\||" function)))
|
|
313 (setq function (downcase function))
|
|
314 (setq method (get (intern-soft function) 'scheme-indent-function))
|
|
315 (cond ((integerp method)
|
|
316 (scheme-indent-specform method state indent-point))
|
|
317 (method
|
|
318 (funcall method state indent-point))
|
|
319 ((and (> (length function) 3)
|
|
320 (string-equal (substring function 0 3) "def"))
|
|
321 (scheme-indent-defform state indent-point))))))))
|
|
322
|
|
323 (defvar scheme-body-indent 2 "")
|
|
324
|
|
325 (defun scheme-indent-specform (count state indent-point)
|
|
326 (let ((containing-form-start (car (cdr state))) (i count)
|
|
327 body-indent containing-form-column)
|
|
328 ;; Move to the start of containing form, calculate indentation
|
|
329 ;; to use for non-distinguished forms (> count), and move past the
|
|
330 ;; function symbol. scheme-indent-function guarantees that there is at
|
|
331 ;; least one word or symbol character following open paren of containing
|
|
332 ;; form.
|
|
333 (goto-char containing-form-start)
|
|
334 (setq containing-form-column (current-column))
|
|
335 (setq body-indent (+ scheme-body-indent containing-form-column))
|
|
336 (forward-char 1)
|
|
337 (forward-sexp 1)
|
|
338 ;; Now find the start of the last form.
|
|
339 (parse-partial-sexp (point) indent-point 1 t)
|
|
340 (while (and (< (point) indent-point)
|
|
341 (condition-case nil
|
|
342 (progn
|
|
343 (setq count (1- count))
|
|
344 (forward-sexp 1)
|
|
345 (parse-partial-sexp (point) indent-point 1 t))
|
|
346 (error nil))))
|
|
347 ;; Point is sitting on first character of last (or count) sexp.
|
|
348 (cond ((> count 0)
|
|
349 ;; A distinguished form. Use double scheme-body-indent.
|
|
350 (list (+ containing-form-column (* 2 scheme-body-indent))
|
|
351 containing-form-start))
|
|
352 ;; A non-distinguished form. Use body-indent if there are no
|
|
353 ;; distinguished forms and this is the first undistinguished
|
|
354 ;; form, or if this is the first undistinguished form and
|
|
355 ;; the preceding distinguished form has indentation at least
|
|
356 ;; as great as body-indent.
|
|
357 ((and (= count 0)
|
|
358 (or (= i 0)
|
|
359 (<= body-indent normal-indent)))
|
|
360 body-indent)
|
|
361 (t
|
|
362 normal-indent))))
|
|
363
|
|
364 (defun scheme-indent-defform (state indent-point)
|
|
365 (goto-char (car (cdr state)))
|
|
366 (forward-line 1)
|
|
367 (if (> (point) (car (cdr (cdr state))))
|
|
368 (progn
|
|
369 (goto-char (car (cdr state)))
|
|
370 (+ scheme-body-indent (current-column)))))
|
|
371
|
|
372 ;;; Let is different in Scheme
|
|
373
|
|
374 (defun would-be-symbol (string)
|
|
375 (not (string-equal (substring string 0 1) "(")))
|
|
376
|
|
377 (defun next-sexp-as-string ()
|
|
378 ;; Assumes that protected by a save-excursion
|
|
379 (forward-sexp 1)
|
|
380 (let ((the-end (point)))
|
|
381 (backward-sexp 1)
|
|
382 (buffer-substring (point) the-end)))
|
|
383
|
|
384 ;; This is correct but too slow.
|
|
385 ;; The one below works almost always.
|
|
386 ;;(defun scheme-let-indent (state indent-point)
|
|
387 ;; (if (would-be-symbol (next-sexp-as-string))
|
|
388 ;; (scheme-indent-specform 2 state indent-point)
|
|
389 ;; (scheme-indent-specform 1 state indent-point)))
|
|
390
|
|
391 (defun scheme-let-indent (state indent-point)
|
|
392 (skip-chars-forward " \t")
|
2
|
393 (if (looking-at "[-a-zA-Z0-9+*/?!@$%^&_:~]")
|
0
|
394 (scheme-indent-specform 2 state indent-point)
|
|
395 (scheme-indent-specform 1 state indent-point)))
|
|
396
|
|
397 ;; (put 'begin 'scheme-indent-function 0), say, causes begin to be indented
|
|
398 ;; like defun if the first form is placed on the next line, otherwise
|
|
399 ;; it is indented like any other form (i.e. forms line up under first).
|
|
400
|
|
401 (put 'begin 'scheme-indent-function 0)
|
|
402 (put 'case 'scheme-indent-function 1)
|
|
403 (put 'delay 'scheme-indent-function 0)
|
|
404 (put 'do 'scheme-indent-function 2)
|
|
405 (put 'lambda 'scheme-indent-function 1)
|
|
406 (put 'let 'scheme-indent-function 'scheme-let-indent)
|
|
407 (put 'let* 'scheme-indent-function 1)
|
|
408 (put 'letrec 'scheme-indent-function 1)
|
|
409 (put 'sequence 'scheme-indent-function 0)
|
|
410
|
|
411 (put 'call-with-input-file 'scheme-indent-function 1)
|
|
412 (put 'with-input-from-file 'scheme-indent-function 1)
|
|
413 (put 'with-input-from-port 'scheme-indent-function 1)
|
|
414 (put 'call-with-output-file 'scheme-indent-function 1)
|
|
415 (put 'with-output-to-file 'scheme-indent-function 1)
|
|
416 (put 'with-output-to-port 'scheme-indent-function 1)
|
|
417
|
|
418 ;;;; MIT Scheme specific indentation.
|
|
419
|
|
420 (if scheme-mit-dialect
|
|
421 (progn
|
|
422 (put 'fluid-let 'scheme-indent-function 1)
|
|
423 (put 'in-package 'scheme-indent-function 1)
|
|
424 (put 'let-syntax 'scheme-indent-function 1)
|
|
425 (put 'local-declare 'scheme-indent-function 1)
|
|
426 (put 'macro 'scheme-indent-function 1)
|
|
427 (put 'make-environment 'scheme-indent-function 0)
|
|
428 (put 'named-lambda 'scheme-indent-function 1)
|
|
429 (put 'using-syntax 'scheme-indent-function 1)
|
|
430
|
|
431 (put 'with-input-from-string 'scheme-indent-function 1)
|
|
432 (put 'with-output-to-string 'scheme-indent-function 0)
|
|
433 (put 'with-values 'scheme-indent-function 1)
|
|
434
|
|
435 (put 'syntax-table-define 'scheme-indent-function 2)
|
|
436 (put 'list-transform-positive 'scheme-indent-function 1)
|
|
437 (put 'list-transform-negative 'scheme-indent-function 1)
|
|
438 (put 'list-search-positive 'scheme-indent-function 1)
|
|
439 (put 'list-search-negative 'scheme-indent-function 1)
|
|
440
|
|
441 (put 'access-components 'scheme-indent-function 1)
|
|
442 (put 'assignment-components 'scheme-indent-function 1)
|
|
443 (put 'combination-components 'scheme-indent-function 1)
|
|
444 (put 'comment-components 'scheme-indent-function 1)
|
|
445 (put 'conditional-components 'scheme-indent-function 1)
|
|
446 (put 'disjunction-components 'scheme-indent-function 1)
|
|
447 (put 'declaration-components 'scheme-indent-function 1)
|
|
448 (put 'definition-components 'scheme-indent-function 1)
|
|
449 (put 'delay-components 'scheme-indent-function 1)
|
|
450 (put 'in-package-components 'scheme-indent-function 1)
|
|
451 (put 'lambda-components 'scheme-indent-function 1)
|
|
452 (put 'lambda-components* 'scheme-indent-function 1)
|
|
453 (put 'lambda-components** 'scheme-indent-function 1)
|
|
454 (put 'open-block-components 'scheme-indent-function 1)
|
|
455 (put 'pathname-components 'scheme-indent-function 1)
|
|
456 (put 'procedure-components 'scheme-indent-function 1)
|
|
457 (put 'sequence-components 'scheme-indent-function 1)
|
|
458 (put 'unassigned\?-components 'scheme-indent-function 1)
|
|
459 (put 'unbound\?-components 'scheme-indent-function 1)
|
|
460 (put 'variable-components 'scheme-indent-function 1)))
|
|
461
|
|
462 (defun scheme-indent-sexp ()
|
|
463 "Indent each line of the list starting just after point."
|
|
464 (interactive)
|
|
465 (let ((indent-stack (list nil)) (next-depth 0) bol
|
|
466 outer-loop-done inner-loop-done state this-indent)
|
|
467 (save-excursion (forward-sexp 1))
|
|
468 (save-excursion
|
|
469 (setq outer-loop-done nil)
|
|
470 (while (not outer-loop-done)
|
|
471 (setq last-depth next-depth
|
|
472 innerloop-done nil)
|
|
473 (while (and (not innerloop-done)
|
|
474 (not (setq outer-loop-done (eobp))))
|
|
475 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
|
|
476 nil nil state))
|
|
477 (setq next-depth (car state))
|
|
478 (if (car (nthcdr 4 state))
|
|
479 (progn (indent-for-comment)
|
|
480 (end-of-line)
|
|
481 (setcar (nthcdr 4 state) nil)))
|
|
482 (if (car (nthcdr 3 state))
|
|
483 (progn
|
|
484 (forward-line 1)
|
|
485 (setcar (nthcdr 5 state) nil))
|
|
486 (setq innerloop-done t)))
|
|
487 (if (setq outer-loop-done (<= next-depth 0))
|
|
488 nil
|
|
489 (while (> last-depth next-depth)
|
|
490 (setq indent-stack (cdr indent-stack)
|
|
491 last-depth (1- last-depth)))
|
|
492 (while (< last-depth next-depth)
|
|
493 (setq indent-stack (cons nil indent-stack)
|
|
494 last-depth (1+ last-depth)))
|
|
495 (forward-line 1)
|
|
496 (setq bol (point))
|
|
497 (skip-chars-forward " \t")
|
|
498 (if (or (eobp) (looking-at "[;\n]"))
|
|
499 nil
|
|
500 (if (and (car indent-stack)
|
|
501 (>= (car indent-stack) 0))
|
|
502 (setq this-indent (car indent-stack))
|
|
503 (let ((val (calculate-scheme-indent
|
|
504 (if (car indent-stack) (- (car indent-stack))))))
|
|
505 (if (integerp val)
|
|
506 (setcar indent-stack
|
|
507 (setq this-indent val))
|
2
|
508 (if (cdr val)
|
|
509 (setcar indent-stack (- (car (cdr val)))))
|
0
|
510 (setq this-indent (car val)))))
|
|
511 (if (/= (current-column) this-indent)
|
|
512 (progn (delete-region bol (point))
|
|
513 (indent-to this-indent)))))))))
|
2
|
514
|
|
515 (provide 'scheme)
|
|
516
|
|
517 ;;; scheme.el ends here
|