annotate lisp/=mim-mode.el @ 317:18554fcbc0b6

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Mon, 08 Jul 1991 22:34:33 +0000
parents 2d06c35d1c03
children 4cd7543be581
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
229
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 ;; Mim (MDL in MDL) mode.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2 ;; Copyright (C) 1985 Free Software Foundation, Inc.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3 ;; Principal author K. Shane Hartman
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5 ;; This file is part of GNU Emacs.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 ;; it under the terms of the GNU General Public License as published by
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 ;; the Free Software Foundation; either version 1, or (at your option)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 ;; any later version.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 ;; GNU Emacs is distributed in the hope that it will be useful,
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 ;; GNU General Public License for more details.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 (provide 'mim-mode)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 (autoload 'fast-syntax-check-mim "mim-syntax"
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 "Checks Mim syntax quickly.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 Answers correct or incorrect, cannot point out the error context."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 t)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 (autoload 'slow-syntax-check-mim "mim-syntax"
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 "Check Mim syntax slowly.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 Points out the context of the error, if the syntax is incorrect."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 t)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 (defvar mim-mode-hysterical-bindings t
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 "*Non-nil means bind list manipulation commands to Meta keys as well as
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 Control-Meta keys for historical reasons. Otherwise, only the latter keys
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 are bound.")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 (defvar mim-mode-map nil)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 (defvar mim-mode-syntax-table nil)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 (if mim-mode-syntax-table
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 ()
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 (let ((i -1))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 (setq mim-mode-syntax-table (make-syntax-table))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 (while (< i ?\ )
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 (modify-syntax-entry (setq i (1+ i)) " " mim-mode-syntax-table))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 (while (< i 127)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 (modify-syntax-entry (setq i (1+ i)) "_ " mim-mode-syntax-table))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 (setq i (1- ?a))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 (while (< i ?z)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 (modify-syntax-entry (setq i (1+ i)) "w " mim-mode-syntax-table))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 (setq i (1- ?A))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 (while (< i ?Z)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 (modify-syntax-entry (setq i (1+ i)) "w " mim-mode-syntax-table))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 (setq i (1- ?0))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 (while (< i ?9)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 (modify-syntax-entry (setq i (1+ i)) "w " mim-mode-syntax-table))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 (modify-syntax-entry ?: " " mim-mode-syntax-table) ; make : symbol delimiter
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 (modify-syntax-entry ?, "' " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 (modify-syntax-entry ?. "' " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 (modify-syntax-entry ?' "' " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 (modify-syntax-entry ?` "' " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 (modify-syntax-entry ?~ "' " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 (modify-syntax-entry ?\; "' " mim-mode-syntax-table) ; comments are prefixed objects
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 (modify-syntax-entry ?# "' " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 (modify-syntax-entry ?% "' " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 (modify-syntax-entry ?! "' " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 (modify-syntax-entry ?\" "\" " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 (modify-syntax-entry ?\\ "\\ " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 (modify-syntax-entry ?\( "\() " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 (modify-syntax-entry ?\< "\(> " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 (modify-syntax-entry ?\{ "\(} " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 (modify-syntax-entry ?\[ "\(] " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 (modify-syntax-entry ?\) "\)( " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 (modify-syntax-entry ?\> "\)< " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 (modify-syntax-entry ?\} "\){ " mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 (modify-syntax-entry ?\] "\)[ " mim-mode-syntax-table)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 (defconst mim-whitespace "\000- ")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 (defvar mim-mode-hook nil
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 "*User function run after mim mode initialization. Usage:
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 \(setq mim-mode-hook '(lambda () ... your init forms ...)).")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 (define-abbrev-table 'mim-mode-abbrev-table nil)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 (defconst indent-mim-function 'indent-mim-function
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 "Controls (via properties) indenting of special forms.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 \(put 'FOO 'indent-mim-function n\), integer n, means lines inside
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 <FOO ...> will be indented n spaces from start of form.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 \(put 'FOO 'indent-mim-function 'DEFINE\) is like above but means use
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 value of mim-body-indent as offset from start of form.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 \(put 'FOO 'indent-mim-function <cons>\) where <cons> is a list or pointted list
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 of integers, means indent each form in <FOO ...> by the amount specified
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 in <cons>. When <cons> is exhausted, indent remaining forms by
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 `mim-body-indent' unless <cons> is a pointed list, in which case the last
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 cdr is used. Confused? Here is an example:
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 \(put 'FROBIT 'indent-mim-function '\(4 2 . 1\)\)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 <FROBIT
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 <CHOMP-IT>
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 <CHOMP-SOME-MORE>
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 <DIGEST>
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 <BELCH>
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 ...>
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 Finally, the property can be a function name (read the code).")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 (defvar indent-mim-comment t
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 "*Non-nil means indent string comments.")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 (defvar mim-body-indent 2
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 "*Amount to indent in special forms which have DEFINE property on
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 `indent-mim-function'.")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 (defvar indent-mim-arglist t
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 "*nil means indent arglists like ordinary lists.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 t means strings stack under start of arglist and variables stack to
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 right of them. Otherwise, strings stack under last string (or start
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 of arglist if none) and variables stack to right of them.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 Examples (for values 'stack, t, nil):
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 \(FOO \"OPT\" BAR \(FOO \"OPT\" BAR \(FOO \"OPT\" BAR
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 BAZ MUMBLE BAZ MUMBLE BAZ MUMBLE
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 \"AUX\" \"AUX\" \"AUX\"
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 BLETCH ... BLETCH ... BLETCH ...")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 (put 'DEFINE 'indent-mim-function 'DEFINE)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 (put 'DEFMAC 'indent-mim-function 'DEFINE)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 (put 'BIND 'indent-mim-function 'DEFINE)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 (put 'PROG 'indent-mim-function 'DEFINE)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 (put 'REPEAT 'indent-mim-function 'DEFINE)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 (put 'CASE 'indent-mim-function 'DEFINE)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 (put 'FUNCTION 'indent-mim-function 'DEFINE)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 (put 'MAPF 'indent-mim-function 'DEFINE)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 (put 'MAPR 'indent-mim-function 'DEFINE)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 (put 'UNWIND 'indent-mim-function (cons (* 2 mim-body-indent) mim-body-indent))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 (defvar mim-down-parens-only t
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 "*nil means treat ADECLs and ATOM trailers like structures when
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 moving down a level of structure.")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 (defvar mim-stop-for-slop t
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 "*Non-nil means {next previous}-mim-object consider any
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 non-whitespace character in column 0 to be a toplevel object, otherwise
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 only open paren syntax characters will be considered.")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 (fset 'mdl-mode 'mim-mode)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 (defun mim-mode ()
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 "Major mode for editing Mim (MDL in MDL) code.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 Commands:
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 If value of `mim-mode-hysterical-bindings' is non-nil, then following
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 commands are assigned to escape keys as well (e.g. ESC f = ESC C-f).
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 The default action is bind the escape keys.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 \\{mim-mode-map}
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 Other Commands:
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 Use \\[describe-function] to obtain documentation.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 replace-in-mim-object find-mim-definition fast-syntax-check-mim
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 slow-syntax-check-mim backward-down-mim-object forward-up-mim-object
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 Variables:
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 Use \\[describe-variable] to obtain documentation.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 mim-mode-hook indent-mim-comment indent-mim-arglist indent-mim-function
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 mim-body-indent mim-down-parens-only mim-stop-for-slop
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 mim-mode-hysterical-bindings
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 Entry to this mode calls the value of mim-mode-hook if non-nil."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 (interactive)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 (kill-all-local-variables)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 (if (not mim-mode-map)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 (progn
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 (setq mim-mode-map (make-sparse-keymap))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 (define-key mim-mode-map "\e\^o" 'open-mim-line)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 (define-key mim-mode-map "\e\^q" 'indent-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 (define-key mim-mode-map "\e\^p" 'previous-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 (define-key mim-mode-map "\e\^n" 'next-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 (define-key mim-mode-map "\e\^a" 'beginning-of-DEFINE)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 (define-key mim-mode-map "\e\^e" 'end-of-DEFINE)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 (define-key mim-mode-map "\e\^t" 'transpose-mim-objects)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 (define-key mim-mode-map "\e\^u" 'backward-up-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 (define-key mim-mode-map "\e\^d" 'forward-down-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 (define-key mim-mode-map "\e\^h" 'mark-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 (define-key mim-mode-map "\e\^k" 'forward-kill-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 (define-key mim-mode-map "\e\^f" 'forward-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 (define-key mim-mode-map "\e\^b" 'backward-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 (define-key mim-mode-map "\e^" 'raise-mim-line)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 (define-key mim-mode-map "\e\\" 'fixup-whitespace)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 (define-key mim-mode-map "\177" 'backward-delete-char-untabify)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 (define-key mim-mode-map "\e\177" 'backward-kill-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 (define-key mim-mode-map "\^j" 'newline-and-mim-indent)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 (define-key mim-mode-map "\e;" 'begin-mim-comment)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 (define-key mim-mode-map "\t" 'indent-mim-line)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 (define-key mim-mode-map "\e\t" 'indent-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 (if (not mim-mode-hysterical-bindings)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 nil
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 ;; i really hate this but too many people are accustomed to these.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 (define-key mim-mode-map "\e!" 'line-to-top-of-window)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 (define-key mim-mode-map "\eo" 'open-mim-line)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 (define-key mim-mode-map "\ep" 'previous-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 (define-key mim-mode-map "\en" 'next-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 (define-key mim-mode-map "\ea" 'beginning-of-DEFINE)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 (define-key mim-mode-map "\ee" 'end-of-DEFINE)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 (define-key mim-mode-map "\et" 'transpose-mim-objects)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 (define-key mim-mode-map "\eu" 'backward-up-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 (define-key mim-mode-map "\ed" 'forward-down-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 (define-key mim-mode-map "\ek" 'forward-kill-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 (define-key mim-mode-map "\ef" 'forward-mim-object)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 (define-key mim-mode-map "\eb" 'backward-mim-object))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 (use-local-map mim-mode-map)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 (set-syntax-table mim-mode-syntax-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 (make-local-variable 'paragraph-start)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 (setq paragraph-start (concat "^$\\|" page-delimiter))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 (make-local-variable 'paragraph-separate)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 (setq paragraph-separate paragraph-start)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 (make-local-variable 'paragraph-ignore-fill-prefix)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 (setq paragraph-ignore-fill-prefix t)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 ;; Most people use string comments.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 (make-local-variable 'comment-start)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 (setq comment-start ";\"")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 (make-local-variable 'comment-start-skip)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 (setq comment-start-skip ";\"")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 (make-local-variable 'comment-end)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 (setq comment-end "\"")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 (make-local-variable 'comment-column)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 (setq comment-column 40)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 (make-local-variable 'comment-indent-hook)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 (setq comment-indent-hook 'indent-mim-comment)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 ;; tell generic indenter how to indent.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 (make-local-variable 'indent-line-function)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 (setq indent-line-function 'indent-mim-line)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 ;; look for that paren
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 (make-local-variable 'blink-matching-paren-distance)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 (setq blink-matching-paren-distance nil)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 ;; so people who dont like tabs can turn them off locally in indenter.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 (make-local-variable 'indent-tabs-mode)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 (setq indent-tabs-mode t)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 (setq local-abbrev-table mim-mode-abbrev-table)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 (setq major-mode 'mim-mode)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 (setq mode-name "Mim")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 (run-hooks 'mim-mode-hook))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 (defun line-to-top-of-window ()
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 "Move current line to top of window."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 (interactive) ; for lazy people
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 (recenter 0))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 (defun forward-mim-object (arg)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 "Move forward across Mim object.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 With ARG, move forward that many objects."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 (interactive "p")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 ;; this function is wierd because it emulates the behavior of the old
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 ;; (gosling) mim-mode - if the arg is 1 and we are `inside' an ADECL,
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 ;; more than one character into the ATOM part and not sitting on the
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 ;; colon, then we move to the DECL part (just past colon) instead of
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 ;; the end of the object (the entire ADECL). otherwise, ADECL's are
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 ;; atomic objects. likewise for ATOM trailers.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 (if (= (abs arg) 1)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 (if (inside-atom-p)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 ;; Move to end of ATOM or to trailer (!) or to ADECL (:).
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 (forward-sexp arg)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 ;; Either scan an sexp or move over one bracket.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 (forward-mim-objects arg t))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 ;; in the multi-object case, don't perform any magic.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 ;; treats ATOM trailers and ADECLs atomically, stops at unmatched
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 ;; brackets with error.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 (forward-mim-objects arg)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 (defun inside-atom-p ()
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 ;; Returns t iff inside an atom (takes account of trailers)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 (let ((c1 (preceding-char))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 (c2 (following-char)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 (and (or (= (char-syntax c1) ?w) (= (char-syntax c1) ?_) (= c1 ?!))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 (or (= (char-syntax c2) ?w) (= (char-syntax c2) ?_) (= c2 ?!)))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 (defun forward-mim-objects (arg &optional skip-bracket-p)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 ;; Move over arg objects ignoring ADECLs and trailers. If
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 ;; skip-bracket-p is non-nil, then move over one bracket on error.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 (let ((direction (sign arg)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 (condition-case conditions
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 (while (/= arg 0)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 (forward-sexp direction)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 (if (not (inside-adecl-or-trailer-p direction))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 (setq arg (- arg direction))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 (error (if (not skip-bracket-p)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 (signal 'error (cdr conditions))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 (skip-mim-whitespace direction)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 (goto-char (+ (point) direction)))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 ;; If we moved too far move back to first interesting character.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 (if (= (point) (buffer-end direction)) (skip-mim-whitespace (- direction)))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 (defun backward-mim-object (&optional arg)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 "Move backward across Mim object.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 With ARG, move backward that many objects."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 (interactive "p")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 (forward-mim-object (if arg (- arg) -1)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 (defun mark-mim-object (&optional arg)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 "Mark following Mim object.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 With ARG, mark that many following (preceding, ARG < 0) objects."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 (interactive "p")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 (push-mark (save-excursion (forward-mim-object (or arg 1)) (point))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 (defun forward-kill-mim-object (&optional arg)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 "Kill following Mim object.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 With ARG, kill that many objects."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 (interactive "*p")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 (kill-region (point) (progn (forward-mim-object (or arg 1)) (point))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 (defun backward-kill-mim-object (&optional arg)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 "Kill preceding Mim object.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 With ARG, kill that many objects."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 (interactive "*p")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 (forward-kill-mim-object (- (or arg 1))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 (defun raise-mim-line (&optional arg)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 "Raise following line, fixing up whitespace at join.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 With ARG raise that many following lines.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 A negative ARG will raise current line and previous lines."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 (interactive "*p")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 (let* ((increment (sign (or arg (setq arg 1))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 (direction (if (> arg 0) 1 0)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 (save-excursion
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 (while (/= arg 0)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 ;; move over eol and kill it
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 (forward-line direction)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 (delete-region (point) (1- (point)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 (fixup-whitespace)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 (setq arg (- arg increment))))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 (defun forward-down-mim-object (&optional arg)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 "Move down a level of Mim structure forwards.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 With ARG, move down that many levels forwards (backwards, ARG < 0)."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 (interactive "p")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 ;; another wierdo - going down `inside' an ADECL or ATOM trailer
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 ;; depends on the value of mim-down-parens-only. if nil, treat
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 ;; ADECLs and trailers as structured objects.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 (let ((direction (sign (or arg (setq arg 1)))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 (if (and (= (abs arg) 1) (not mim-down-parens-only))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 (goto-char
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 (save-excursion
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 (skip-mim-whitespace direction)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 (if (> direction 0) (re-search-forward "\\s'*"))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 (or (and (let ((c (next-char direction)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 (or (= (char-syntax c) ?_)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 (= (char-syntax c) ?w)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 (progn (forward-sexp direction)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 (if (inside-adecl-or-trailer-p direction)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 (point))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 (scan-lists (point) direction -1)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 (buffer-end direction))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 (while (/= arg 0)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 (goto-char (or (scan-lists (point) direction -1) (buffer-end direction)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 (setq arg (- arg direction))))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 (defun backward-down-mim-object (&optional arg)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 "Move down a level of Mim structure backwards.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 With ARG, move down that many levels backwards (forwards, ARG < 0)."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 (interactive "p")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 (forward-down-mim-object (if arg (- arg) -1)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 (defun forward-up-mim-object (&optional arg)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 "Move up a level of Mim structure forwards
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 With ARG, move up that many levels forwards (backwards, ARG < 0)."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 (interactive "p")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 (let ((direction (sign (or arg (setq arg 1)))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 (while (/= arg 0)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 (goto-char (or (scan-lists (point) direction 1) (buffer-end arg)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 (setq arg (- arg direction)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 (if (< direction 0) (backward-prefix-chars))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 (defun backward-up-mim-object (&optional arg)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 "Move up a level of Mim structure backwards
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 With ARG, move up that many levels backwards (forwards, ARG > 0)."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 (interactive "p")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 (forward-up-mim-object (if arg (- arg) -1)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 (defun replace-in-mim-object (old new)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 "Replace string in following Mim object."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 (interactive "*sReplace in object: \nsReplace %s with: ")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 (save-restriction
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 (narrow-to-region (point) (save-excursion (forward-mim-object 1) (point)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 (replace-string old new)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 (defun transpose-mim-objects (&optional arg)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 "Transpose Mim objects around point.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 With ARG, transpose preceding object that many times with following objects.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 A negative ARG will transpose backwards."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 (interactive "*p")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 (transpose-subr 'forward-mim-object (or arg 1)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 (defun beginning-of-DEFINE (&optional arg move)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 "Move backward to beginning of surrounding or previous toplevel Mim form.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 With ARG, do it that many times. Stops at last toplevel form seen if buffer
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 end is reached."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 (interactive "p")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 (let ((direction (sign (or arg (setq arg 1)))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 (if (not move) (setq move t))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 (if (< direction 0) (goto-char (1+ (point))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 (while (and (/= arg 0) (re-search-backward "^<" nil move direction))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 (setq arg (- arg direction)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 (if (< direction 0)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 (goto-char (1- (point))))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 (defun end-of-DEFINE (&optional arg)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 "Move forward to end of surrounding or next toplevel mim form.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 With ARG, do it that many times. Stops at end of last toplevel form seen
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 if buffer end is reached."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 (interactive "p")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 (if (not arg) (setq arg 1))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 (if (< arg 0)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 (beginning-of-DEFINE (- (1- arg)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 (if (not (looking-at "^<")) (setq arg (1+ arg)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 (beginning-of-DEFINE (- arg) 'move)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 (beginning-of-DEFINE 1))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 (forward-mim-object 1)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 (forward-line 1))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 (defun next-mim-object (&optional arg)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 "Move to beginning of next toplevel Mim object.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 With ARG, do it that many times. Stops at last object seen if buffer end
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 is reached."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 (interactive "p")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 (let ((search-string (if mim-stop-for-slop "^\\S " "^\\s("))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 (direction (sign (or arg (setq arg 1)))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 (if (> direction 0)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 (goto-char (1+ (point)))) ; no error if end of buffer
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 (while (and (/= arg 0)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 (re-search-forward search-string nil t direction))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 (setq arg (- arg direction)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 (if (> direction 0)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 (goto-char (1- (point)))) ; no error if beginning of buffer
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 ;; scroll to top of window if moving forward and end not visible.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 (if (not (or (< direction 0)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 (save-excursion (forward-mim-object 1)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 (pos-visible-in-window-p (point)))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 (recenter 0))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 (defun previous-mim-object (&optional arg)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 "Move to beginning of previous toplevel Mim object.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 With ARG do it that many times. Stops at last object seen if buffer end
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 is reached."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 (interactive "p")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 (next-mim-object (- (or arg 1))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 (defun calculate-mim-indent (&optional parse-start)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 "Calculate indentation for Mim line. Returns column."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 (save-excursion ; some excursion, huh, toto?
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 (beginning-of-line)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 (let ((indent-point (point)) retry state containing-sexp last-sexp
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 desired-indent start peek where paren-depth)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 (if parse-start
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 (goto-char parse-start) ; should be containing environment
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 (catch 'from-the-top
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 ;; find a place to start parsing. going backwards is fastest.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 ;; forward-sexp signals error on encountering unmatched open.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 (setq retry t)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 (while retry
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457 (condition-case nil (forward-sexp -1) (error (setq retry nil)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458 (if (looking-at ".?[ \t]*\"")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 ;; cant parse backward in presence of strings, go forward.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 (progn
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461 (goto-char indent-point)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 (re-search-backward "^\\s(" nil 'move 1) ; to top of object
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 (throw 'from-the-top nil)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464 (setq retry (and retry (/= (current-column) 0))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 (skip-chars-backward mim-whitespace)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466 (if (not (bobp)) (forward-char -1)) ; onto unclosed open
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 (backward-prefix-chars)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468 ;; find outermost containing sexp if we started inside an sexp.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 (while (< (point) indent-point)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 (setq state (parse-partial-sexp (point) indent-point 0)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 ;; find usual column to indent under (not in string or toplevel).
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 ;; on termination, state will correspond to containing environment
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 ;; (if retry is nil), where will be position of character to indent
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474 ;; under normally, and desired-indent will be the column to indent to
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 ;; except if inside form, string, or at toplevel. point will be in
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 ;; in column to indent to unless inside string.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477 (setq retry t)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
478 (while (and retry (setq paren-depth (car state)) (> paren-depth 0))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
479 ;; find innermost containing sexp.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
480 (setq retry nil)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
481 (setq last-sexp (car (nthcdr 2 state)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
482 (setq containing-sexp (car (cdr state)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
483 (goto-char (1+ containing-sexp)) ; to last unclosed open
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
484 (if (and last-sexp (> last-sexp (point)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485 ;; is the last sexp a containing sexp?
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486 (progn (setq peek (parse-partial-sexp last-sexp indent-point 0))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 (if (setq retry (car (cdr peek))) (setq state peek))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488 (if retry
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
489 nil
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 (setq where (1+ containing-sexp)) ; innermost containing sexp
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 (goto-char where)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492 (cond
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
493 ((not last-sexp) ; indent-point after bracket
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
494 (setq desired-indent (current-column)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
495 ((= (preceding-char) ?\<) ; it's a form
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496 (cond ((> (progn (forward-sexp 1) (point)) last-sexp)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497 (goto-char where)) ; only one frob
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
498 ((> (save-excursion (forward-line 1) (point)) last-sexp)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
499 (skip-chars-forward " \t") ; last-sexp is on same line
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
500 (setq where (point))) ; as containing-sexp
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
501 ((progn
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
502 (goto-char last-sexp)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
503 (beginning-of-line)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
504 (parse-partial-sexp (point) last-sexp 0 t)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
505 (or (= (point) last-sexp)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
506 (save-excursion
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507 (= (car (parse-partial-sexp (point) last-sexp 0))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508 0))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
509 (backward-prefix-chars) ; last-sexp 1st on line or 1st
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 (setq where (point))) ; frob on that line level 0
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511 (t (goto-char where)))) ; punt, should never occur
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 ((and indent-mim-arglist ; maybe hack arglist
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513 (= (preceding-char) ?\() ; its a list
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 (save-excursion ; look for magic atoms
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
515 (setq peek 0) ; using peek as counter
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
516 (forward-char -1) ; back over containing paren
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
517 (while (and (< (setq peek (1+ peek)) 6)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
518 (condition-case nil
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
519 (progn (forward-sexp -1) t)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
520 (error nil))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
521 (and (< peek 6) (looking-at "DEFINE\\|DEFMAC\\|FUNCTION"))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
522 ;; frobs stack under strings they belong to or under first
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
523 ;; frob to right of strings they belong to unless luser has
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
524 ;; frob (non-string) on preceding line with different
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
525 ;; indentation. strings stack under start of arglist unless
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526 ;; mim-indent-arglist is not t, in which case they stack
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527 ;; under the last string, if any, else the start of the arglist.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
528 (let ((eol 0) last-string)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
529 (while (< (point) last-sexp) ; find out where the strings are
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 (skip-chars-forward mim-whitespace last-sexp)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
531 (if (> (setq start (point)) eol)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532 (progn ; simultaneously keeping track
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
533 (setq where (min where start))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
534 (end-of-line) ; of indentation of first frob
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535 (setq eol (point)) ; on each line
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 (goto-char start)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537 (if (= (following-char) ?\")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
538 (progn (setq last-string (point))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
539 (forward-sexp 1)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
540 (if (= last-string last-sexp)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
541 (setq where last-sexp)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542 (skip-chars-forward mim-whitespace last-sexp)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
543 (setq where (point))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
544 (forward-sexp 1)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
545 (goto-char indent-point) ; if string is first on
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546 (skip-chars-forward " \t" (point-max)) ; line we are indenting, it
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
547 (if (= (following-char) ?\") ; goes under arglist start
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
548 (if (and last-string (not (equal indent-mim-arglist t)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
549 (setq where last-string) ; or under last string.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
550 (setq where (1+ containing-sexp)))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551 (goto-char where)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
552 (setq desired-indent (current-column)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
553 (t ; plain vanilla structure
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
554 (cond ((> (save-excursion (forward-line 1) (point)) last-sexp)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555 (skip-chars-forward " \t") ; last-sexp is on same line
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
556 (setq where (point))) ; as containing-sexp
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
557 ((progn
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
558 (goto-char last-sexp)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
559 (beginning-of-line)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
560 (parse-partial-sexp (point) last-sexp 0 t)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
561 (or (= (point) last-sexp)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
562 (save-excursion
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563 (= (car (parse-partial-sexp (point) last-sexp 0))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
564 0))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
565 (backward-prefix-chars) ; last-sexp 1st on line or 1st
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
566 (setq where (point))) ; frob on that line level 0
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
567 (t (goto-char where))) ; punt, should never occur
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
568 (setq desired-indent (current-column))))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
569 ;; state is innermost containing environment unless toplevel or string.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
570 (if (car (nthcdr 3 state)) ; inside string
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571 (progn
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 (if last-sexp ; string must be next
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
573 (progn (goto-char last-sexp)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
574 (forward-sexp 1)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
575 (search-forward "\"")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
576 (forward-char -1))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
577 (goto-char indent-point) ; toplevel string, look for it
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
578 (re-search-backward "[^\\]\"")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
579 (forward-char 1))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
580 (setq start (point)) ; opening double quote
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
581 (skip-chars-backward " \t")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
582 (backward-prefix-chars)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
583 ;; see if the string is really a comment.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
584 (if (and (looking-at ";[ \t]*\"") indent-mim-comment)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
585 ;; it's a comment, line up under the start unless disabled.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
586 (goto-char (1+ start))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
587 ;; it's a string, dont mung the indentation.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
588 (goto-char indent-point)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
589 (skip-chars-forward " \t"))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
590 (setq desired-indent (current-column))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
591 ;; point is sitting in usual column to indent to and if retry is nil
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
592 ;; then state corresponds to containing environment. if desired
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
593 ;; indentation not determined, we are inside a form, so call hook.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
594 (or desired-indent
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
595 (and indent-mim-function
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
596 (not retry)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
597 (setq desired-indent
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
598 (funcall indent-mim-function state indent-point)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
599 (setq desired-indent (current-column)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
600 (goto-char indent-point) ; back to where we started
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
601 desired-indent))) ; return column to indent to
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
602
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
603 (defun indent-mim-function (state indent-point)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
604 "Compute indentation for Mim special forms. Returns column or nil."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
605 (let ((containing-sexp (car (cdr state))) (current-indent (point)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
606 (save-excursion
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
607 (goto-char (1+ containing-sexp))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
608 (backward-prefix-chars)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
609 ;; make sure we are looking at a symbol. if so, see if it is a special
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
610 ;; symbol. if so, add the special indentation to the indentation of
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
611 ;; the start of the special symbol, unless the property is not
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
612 ;; an integer and not nil (in this case, call the property, it must
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
613 ;; be a function which returns the appropriate indentation or nil and
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
614 ;; does not change the buffer).
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
615 (if (looking-at "\\sw\\|\\s_")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
616 (let* ((start (current-column))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
617 (function
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
618 (intern-soft (buffer-substring (point)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
619 (progn (forward-sexp 1)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
620 (point)))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
621 (method (get function 'indent-mim-function)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
622 (if (or (if (equal method 'DEFINE) (setq method mim-body-indent))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
623 (integerp method))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
624 ;; only use method if its first line after containing-sexp.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
625 ;; we could have done this in calculate-mim-indent, but someday
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
626 ;; someone might want to format frobs in a special form based
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
627 ;; on position instead of indenting uniformly (like lisp if),
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
628 ;; so preserve right for posterity. if not first line,
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
629 ;; calculate-mim-indent already knows right indentation -
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
630 ;; give luser chance to change indentation manually by changing
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
631 ;; 1st line after containing-sexp.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
632 (if (> (progn (forward-line 1) (point)) (car (nthcdr 2 state)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
633 (+ method start))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
634 (goto-char current-indent)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
635 (if (consp method)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
636 ;; list or pointted list of explicit indentations
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
637 (indent-mim-offset state indent-point)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
638 (if (and (symbolp method) (fboundp method))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
639 ;; luser function - s/he better know what's going on.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
640 ;; should take state and indent-point as arguments - for
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
641 ;; description of state, see parse-partial-sexp
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
642 ;; documentation the function is guaranteed the following:
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
643 ;; (1) state describes the closest surrounding form,
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
644 ;; (2) indent-point is the beginning of the line being
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
645 ;; indented, (3) point points to char in column that would
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
646 ;; normally be used for indentation, (4) function is bound
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
647 ;; to the special ATOM. See indent-mim-offset for example
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
648 ;; of a special function.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
649 (funcall method state indent-point)))))))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
650
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
651 (defun indent-mim-offset (state indent-point)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
652 ;; offset forms explicitly according to list of indentations.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
653 (let ((mim-body-indent mim-body-indent)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
654 (indentations (get function 'indent-mim-function))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
655 (containing-sexp (car (cdr state)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
656 (last-sexp (car (nthcdr 2 state)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
657 indentation)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
658 (goto-char (1+ containing-sexp))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
659 ;; determine wheich of the indentations to use.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
660 (while (and (< (point) indent-point)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
661 (condition-case nil
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
662 (progn (forward-sexp 1)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
663 (parse-partial-sexp (point) indent-point 1 t))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
664 (error nil)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
665 (skip-chars-backward " \t")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
666 (backward-prefix-chars)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
667 (if (= (following-char) ?\;)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
668 nil ; ignore comments
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
669 (setq indentation (car indentations))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
670 (if (integerp (setq indentations (cdr indentations)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
671 ;; if last cdr is integer, that is indentation to use for all
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
672 ;; all the rest of the forms.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
673 (progn (setq mim-body-indent indentations)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
674 (setq indentations nil)))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
675 (goto-char (1+ containing-sexp))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
676 (+ (current-column) (or indentation mim-body-indent))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
677
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
678 (defun indent-mim-comment (&optional start)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
679 "Indent a one line (string) Mim comment following object, if any."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
680 (let* ((old-point (point)) (eol (progn (end-of-line) (point))) state last-sexp)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
681 ;; this function assumes that comment indenting is enabled. it is caller's
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
682 ;; responsibility to check the indent-mim-comment flag before calling.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
683 (beginning-of-line)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
684 (catch 'no-comment
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
685 (setq state (parse-partial-sexp (point) eol))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
686 ;; determine if there is an existing regular comment. a `regular'
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
687 ;; comment is defined as a commented string which is the last thing
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
688 ;; on the line and does not extend beyond the end of the line.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
689 (if (or (not (setq last-sexp (car (nthcdr 2 state))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
690 (car (nthcdr 3 state)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
691 ;; empty line or inside string (multiple line).
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
692 (throw 'no-comment nil))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
693 ;; could be a comment, but make sure its not the only object.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
694 (beginning-of-line)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
695 (parse-partial-sexp (point) eol 0 t)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
696 (if (= (point) last-sexp)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
697 ;; only one object on line
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
698 (throw 'no-comment t))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
699 (goto-char last-sexp)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
700 (skip-chars-backward " \t")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
701 (backward-prefix-chars)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
702 (if (not (looking-at ";[ \t]*\""))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
703 ;; aint no comment
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
704 (throw 'no-comment nil))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
705 ;; there is an existing regular comment
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
706 (delete-horizontal-space)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
707 ;; move it to comment-column if possible else to tab-stop
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
708 (if (< (current-column) comment-column)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
709 (indent-to comment-column)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
710 (tab-to-tab-stop)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
711 (goto-char old-point)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
712
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
713 (defun indent-mim-line ()
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
714 "Indent line of Mim code."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
715 (interactive "*")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
716 (let* ((position (- (point-max) (point)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
717 (bol (progn (beginning-of-line) (point)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
718 (indent (calculate-mim-indent)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
719 (skip-chars-forward " \t")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
720 (if (/= (current-column) indent)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
721 (progn (delete-region bol (point)) (indent-to indent)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
722 (if (> (- (point-max) position) (point)) (goto-char (- (point-max) position)))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
723
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
724 (defun newline-and-mim-indent ()
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
725 "Insert newline at point and indent."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
726 (interactive "*")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
727 ;; commented code would correct indentation of line in arglist which
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
728 ;; starts with string, but it would indent every line twice. luser can
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
729 ;; just say tab after typing string to get same effect.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
730 ;(if indent-mim-arglist (indent-mim-line))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
731 (newline)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
732 (indent-mim-line))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
733
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
734 (defun open-mim-line (&optional lines)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
735 "Insert newline before point and indent.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
736 With ARG insert that many newlines."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
737 (interactive "*p")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
738 (beginning-of-line)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
739 (let ((indent (calculate-mim-indent)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
740 (while (> lines 0)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
741 (newline)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
742 (forward-line -1)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
743 (indent-to indent)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
744 (setq lines (1- lines)))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
745
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
746 (defun indent-mim-object (&optional dont-indent-first-line)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
747 "Indent object following point and all lines contained inside it.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
748 With ARG, idents only contained lines (skips first line)."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
749 (interactive "*P")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
750 (let (end bol indent start)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
751 (save-excursion (parse-partial-sexp (point) (point-max) 0 t)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
752 (setq start (point))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
753 (forward-sexp 1)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
754 (setq end (- (point-max) (point))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
755 (save-excursion
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
756 (if (not dont-indent-first-line) (indent-mim-line))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
757 (while (progn (forward-line 1) (> (- (point-max) (point)) end))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
758 (setq indent (calculate-mim-indent start))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
759 (setq bol (point))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
760 (skip-chars-forward " \t")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
761 (if (/= indent (current-column))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
762 (progn (delete-region bol (point)) (indent-to indent)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
763 (if indent-mim-comment (indent-mim-comment))))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
764
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
765 (defun find-mim-definition (name)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
766 "Search for definition of function, macro, or gfcn.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
767 You need type only enough of the name to be unambiguous."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
768 (interactive "sName: ")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
769 (let (where)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
770 (save-excursion
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
771 (goto-char (point-min))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
772 (condition-case nil
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
773 (progn
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
774 (re-search-forward
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
775 (concat "^<\\(DEFINE\\|\\DEFMAC\\|FCN\\|GFCN\\)\\([ \t]*\\)"
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
776 name))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
777 (setq where (point)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
778 (error (error "Can't find %s" name))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
779 (if where
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
780 (progn (push-mark)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
781 (goto-char where)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
782 (beginning-of-line)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
783 (recenter 0)))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
784
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
785 (defun begin-mim-comment ()
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
786 "Move to existing comment or insert empty comment."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
787 (interactive "*")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
788 (let* ((eol (progn (end-of-line) (point)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
789 (bol (progn (beginning-of-line) (point))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
790 ;; check for existing comment first.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
791 (if (re-search-forward ";[ \t]*\"" eol t)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
792 ;; found it. indent if desired and go there.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
793 (if indent-mim-comment
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
794 (let ((where (- (point-max) (point))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
795 (indent-mim-comment)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
796 (goto-char (- (point-max) where))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
797 ;; nothing there, make a comment.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
798 (let (state last-sexp)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
799 ;; skip past all the sexps on the line
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
800 (goto-char bol)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
801 (while (and (equal (car (setq state (parse-partial-sexp (point) eol 0)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
802 0)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
803 (car (nthcdr 2 state)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
804 (setq last-sexp (car (nthcdr 2 state))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
805 (if (car (nthcdr 3 state))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
806 nil ; inside a string, punt
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
807 (delete-region (point) eol) ; flush trailing whitespace
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
808 (if (and (not last-sexp) (equal (car state) 0))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
809 (indent-to (calculate-mim-indent)) ; empty, indent like code
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
810 (if (> (current-column) comment-column) ; indent to comment column
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
811 (tab-to-tab-stop) ; unless past it, else to
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
812 (indent-to comment-column))) ; tab-stop
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
813 ;; if luser changes comment-{start end} to something besides semi
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
814 ;; followed by zero or more whitespace characters followed by string
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
815 ;; delimiters, the code above fails to find existing comments, but as
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
816 ;; taa says, `let the losers lose'.
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
817 (insert comment-start)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
818 (save-excursion (insert comment-end)))))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
819
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
820 (defun skip-mim-whitespace (direction)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
821 (if (>= direction 0)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
822 (skip-chars-forward mim-whitespace (point-max))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
823 (skip-chars-backward mim-whitespace (point-min))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
824
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
825 (defun inside-adecl-or-trailer-p (direction)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
826 (if (>= direction 0)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
827 (looking-at ":\\|!-")
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
828 (or (= (preceding-char) ?:)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
829 (looking-at "!-"))))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
830
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
831 (defun sign (n)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
832 "Returns -1 if N < 0, else 1."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
833 (if (>= n 0) 1 -1))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
834
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
835 (defun abs (n)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
836 "Returns the absolute value of N."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
837 (if (>= n 0) n (- n)))
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
838
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
839 (defun next-char (direction)
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
840 "Returns preceding-char if DIRECTION < 0, otherwise following-char."
2d06c35d1c03 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
841 (if (>= direction 0) (following-char) (preceding-char)))