annotate lisp/modes/scheme.el @ 80:1ce6082ce73f r20-0b90

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