annotate lisp/progmodes/scheme.el @ 16177:da1a2b74d099 libc-960913

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