annotate lisp/modes/scheme.el @ 173:8eaf7971accc r20-3b13

Import from CVS: tag r20-3b13
author cvs
date Mon, 13 Aug 2007 09:49:09 +0200
parents 28f395d8dc7a
children
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 "\e\C-q" 'scheme-indent-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (defvar scheme-mode-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (if (not scheme-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (setq scheme-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (scheme-mode-commands scheme-mode-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (defun scheme-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 "Major mode for editing Scheme code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 Editing commands are similar to those of lisp-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 In addition, if an inferior Scheme process is running, some additional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 commands will be defined, for evaluating expressions and controlling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 the interpreter, and the state of the process will be displayed in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 modeline of all Scheme buffers. The names of commands that interact
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 with the Scheme process start with \"xscheme-\". For more information
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 see the documentation for xscheme-interaction-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 Commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 Delete converts tabs to spaces as it moves back.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 Blank lines separate paragraphs. Semicolons start comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 \\{scheme-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 Entry to this mode calls the value of scheme-mode-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 if that value is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (scheme-mode-initialize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (scheme-mode-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (run-hooks 'scheme-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (defun scheme-mode-initialize ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (use-local-map scheme-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (setq major-mode 'scheme-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (setq mode-name "Scheme"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (defvar scheme-mit-dialect t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 "If non-nil, scheme mode is specialized for MIT Scheme.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 Set this to nil if you normally use another dialect.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (defun scheme-comment-indent (&optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (if pos (goto-char pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (cond ((looking-at ";;;") (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ((looking-at ";;")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (let ((tem (calculate-scheme-indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (if (listp tem) (car tem) tem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (max (if (bolp) 0 (1+ (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 comment-column)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (defvar scheme-indent-offset nil "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (defvar scheme-indent-function 'scheme-indent-function "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (defun scheme-indent-line (&optional whole-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 "Indent current line as Scheme code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 With argument, indent any additional lines of the same expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 rigidly along with this one."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (let ((indent (calculate-scheme-indent)) shift-amt beg end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (pos (- (point-max) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (if (looking-at "[ \t]*;;;")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; Don't alter indentation of a ;;; comment line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (if (listp indent) (setq indent (car indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (setq shift-amt (- indent (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (if (zerop shift-amt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (delete-region beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (indent-to indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;; If initial point was within line's indentation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ;; position after the indentation. Else stay at same point in text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (if (> (- (point-max) pos) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (goto-char (- (point-max) pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; If desired, shift remaining lines of expression the same amount.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (and whole-exp (not (zerop shift-amt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (> end beg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (indent-code-rigidly beg end shift-amt)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (defun calculate-scheme-indent (&optional parse-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 "Return appropriate indentation for current line as scheme code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 In usual case returns an integer: the column to indent to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 Can instead return a list, whose car is the column to indent to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 This means that following lines at the same level of indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 should not necessarily be indented the same way.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 The second element of the list is the buffer position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 of the start of the containing expression."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (let ((indent-point (point)) state paren-depth desired-indent (retry t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 last-sexp containing-sexp first-sexp-list-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (if parse-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (goto-char parse-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (beginning-of-defun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;; Find outermost containing sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (while (< (point) indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (setq state (parse-partial-sexp (point) indent-point 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ;; Find innermost containing sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (while (and retry (setq paren-depth (car state)) (> paren-depth 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (setq retry nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (setq last-sexp (nth 2 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (setq containing-sexp (car (cdr state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 ;; Position following last unclosed open.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (goto-char (1+ containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;; Is there a complete sexp since then?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (if (and last-sexp (> last-sexp (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;; Yes, but is there a containing sexp after that?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (let ((peek (parse-partial-sexp last-sexp indent-point 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (if (setq retry (car (cdr peek))) (setq state peek))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (if (not retry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;; Innermost containing sexp found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (goto-char (1+ containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (if (not last-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 ;; indent-point immediately follows open paren.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 ;; Don't call hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (setq desired-indent (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ;; Move to first sexp after containing open paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (parse-partial-sexp (point) last-sexp 0 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (setq first-sexp-list-p (looking-at "\\s("))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ((> (save-excursion (forward-line 1) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 last-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ;; Last sexp is on same line as containing sexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;; It's almost certainly a function call.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (parse-partial-sexp (point) last-sexp 0 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (if (/= (point) last-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; Indent beneath first argument or, if only one sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;; on line, indent beneath that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (progn (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (parse-partial-sexp (point) last-sexp 0 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (backward-prefix-chars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ;; Indent beneath first sexp on same line as last-sexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;; Again, it's almost certainly a function call.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (goto-char last-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (parse-partial-sexp (point) last-sexp 0 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (backward-prefix-chars)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ;; If looking at a list, don't call hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (if first-sexp-list-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (setq desired-indent (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;; 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
279 ;; Call indentation hook except when overridden by scheme-indent-offset
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ;; or if the desired indentation has already been computed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (cond ((car (nthcdr 3 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 ;; Inside a string, don't change indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (setq desired-indent (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ((and (integerp scheme-indent-offset) containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ;; Indent by constant offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (setq desired-indent (+ scheme-indent-offset (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 ((not (or desired-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (and (boundp 'scheme-indent-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 scheme-indent-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (not retry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (setq desired-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (funcall scheme-indent-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 indent-point state)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ;; Use default indentation if not computed yet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (setq desired-indent (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 desired-indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (defun scheme-indent-function (indent-point state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (let ((normal-indent (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (goto-char (1+ (car (cdr state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (re-search-forward "\\sw\\|\\s_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (if (/= (point) (car (cdr state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (let ((function (buffer-substring (progn (forward-char -1) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (progn (forward-sexp 1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 ;; Who cares about this, really?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ;(if (not (string-match "\\\\\\||" function)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (setq function (downcase function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (setq method (get (intern-soft function) 'scheme-indent-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (cond ((integerp method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (scheme-indent-specform method state indent-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (method
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (funcall method state indent-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 ((and (> (length function) 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (string-equal (substring function 0 3) "def"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (scheme-indent-defform state indent-point))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (defvar scheme-body-indent 2 "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (defun scheme-indent-specform (count state indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (let ((containing-form-start (car (cdr state))) (i count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 body-indent containing-form-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ;; Move to the start of containing form, calculate indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 ;; to use for non-distinguished forms (> count), and move past the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 ;; function symbol. scheme-indent-function guarantees that there is at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 ;; least one word or symbol character following open paren of containing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 ;; form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (goto-char containing-form-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (setq containing-form-column (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (setq body-indent (+ scheme-body-indent containing-form-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 ;; Now find the start of the last form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (parse-partial-sexp (point) indent-point 1 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (while (and (< (point) indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (setq count (1- count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (parse-partial-sexp (point) indent-point 1 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (error nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 ;; Point is sitting on first character of last (or count) sexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (cond ((> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 ;; A distinguished form. Use double scheme-body-indent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (list (+ containing-form-column (* 2 scheme-body-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 containing-form-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 ;; A non-distinguished form. Use body-indent if there are no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 ;; distinguished forms and this is the first undistinguished
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ;; form, or if this is the first undistinguished form and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 ;; the preceding distinguished form has indentation at least
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 ;; as great as body-indent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 ((and (= count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (or (= i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (<= body-indent normal-indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 body-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 normal-indent))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (defun scheme-indent-defform (state indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (goto-char (car (cdr state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (if (> (point) (car (cdr (cdr state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (goto-char (car (cdr state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (+ scheme-body-indent (current-column)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 ;;; Let is different in Scheme
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (defun would-be-symbol (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (not (string-equal (substring string 0 1) "(")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (defun next-sexp-as-string ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 ;; Assumes that protected by a save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (let ((the-end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (buffer-substring (point) the-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 ;; This is correct but too slow.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 ;; The one below works almost always.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 ;;(defun scheme-let-indent (state indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 ;; (if (would-be-symbol (next-sexp-as-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 ;; (scheme-indent-specform 2 state indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 ;; (scheme-indent-specform 1 state indent-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (defun scheme-let-indent (state indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (skip-chars-forward " \t")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
392 (if (looking-at "[-a-zA-Z0-9+*/?!@$%^&_:~]")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (scheme-indent-specform 2 state indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (scheme-indent-specform 1 state indent-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ;; (put 'begin 'scheme-indent-function 0), say, causes begin to be indented
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 ;; like defun if the first form is placed on the next line, otherwise
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 ;; 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
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (put 'begin 'scheme-indent-function 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (put 'case 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (put 'delay 'scheme-indent-function 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (put 'do 'scheme-indent-function 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (put 'lambda 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (put 'let 'scheme-indent-function 'scheme-let-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (put 'let* 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (put 'letrec 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (put 'sequence 'scheme-indent-function 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (put 'call-with-input-file 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (put 'with-input-from-file 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (put 'with-input-from-port 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (put 'call-with-output-file 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (put 'with-output-to-file 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (put 'with-output-to-port 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 ;;;; MIT Scheme specific indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (if scheme-mit-dialect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (put 'fluid-let 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (put 'in-package 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (put 'let-syntax 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (put 'local-declare 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (put 'macro 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (put 'make-environment 'scheme-indent-function 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (put 'named-lambda 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (put 'using-syntax 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (put 'with-input-from-string 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (put 'with-output-to-string 'scheme-indent-function 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (put 'with-values 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (put 'syntax-table-define 'scheme-indent-function 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (put 'list-transform-positive 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (put 'list-transform-negative 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (put 'list-search-positive 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (put 'list-search-negative 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (put 'access-components 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (put 'assignment-components 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (put 'combination-components 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (put 'comment-components 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (put 'conditional-components 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (put 'disjunction-components 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (put 'declaration-components 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (put 'definition-components 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (put 'delay-components 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (put 'in-package-components 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (put 'lambda-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 'open-block-components 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (put 'pathname-components 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (put 'procedure-components 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (put 'sequence-components 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (put 'unassigned\?-components 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (put 'unbound\?-components 'scheme-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (put 'variable-components 'scheme-indent-function 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (defun scheme-indent-sexp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 "Indent each line of the list starting just after point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (let ((indent-stack (list nil)) (next-depth 0) bol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 outer-loop-done inner-loop-done state this-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (save-excursion (forward-sexp 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (setq outer-loop-done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (while (not outer-loop-done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (setq last-depth next-depth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 innerloop-done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (while (and (not innerloop-done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (not (setq outer-loop-done (eobp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 nil nil state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (setq next-depth (car state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (if (car (nthcdr 4 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (progn (indent-for-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (setcar (nthcdr 4 state) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (if (car (nthcdr 3 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (progn
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 (setcar (nthcdr 5 state) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (setq innerloop-done t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (if (setq outer-loop-done (<= next-depth 0))
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 (while (> last-depth next-depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (setq indent-stack (cdr indent-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 last-depth (1- last-depth)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (while (< last-depth next-depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (setq indent-stack (cons nil indent-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 last-depth (1+ last-depth)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (setq bol (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (if (or (eobp) (looking-at "[;\n]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (if (and (car indent-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (>= (car indent-stack) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (setq this-indent (car indent-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (let ((val (calculate-scheme-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (if (car indent-stack) (- (car indent-stack))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (if (integerp val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (setcar indent-stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (setq this-indent val))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
507 (if (cdr val)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
508 (setcar indent-stack (- (car (cdr val)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (setq this-indent (car val)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (if (/= (current-column) this-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (progn (delete-region bol (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (indent-to this-indent)))))))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
513
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
514 (provide 'scheme)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
515
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
516 ;;; scheme.el ends here