annotate lisp/progmodes/scheme.el @ 6711:f464d8689cb3

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