annotate lisp/modes/scheme.el @ 0:376386a54a3c r19-14

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