annotate lisp/=mim-mode.el @ 6895:4b8dc0a39b47

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