annotate lisp/progmodes/scheme.el @ 14638:46556543f4e6

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