annotate lisp/progmodes/scheme.el @ 12419:818d7bcf63b0

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