36
|
1 ;; Note: use
|
|
2 ;; (autoload 'icon-mode "icon" nil t)
|
|
3 ;; (setq auto-mode-alist (cons '("\\.icn$" . icon-mode) auto-mode-alist))
|
|
4 ;; if not permanently installed in your emacs
|
|
5
|
|
6 ;; Icon code editing commands for Emacs
|
|
7 ;; Derived from c-mode.el 15-Feb-89 Chris Smith convex!csmith
|
|
8 ;; Copyright (C) 1989 Free Software Foundation, Inc.
|
|
9
|
|
10 ;; This file is part of GNU Emacs.
|
|
11
|
|
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
13 ;; it under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 1, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 ;; GNU General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with GNU Emacs; see the file COPYING. If not, write to
|
|
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
25
|
|
26
|
|
27 (defvar icon-mode-abbrev-table nil
|
|
28 "Abbrev table in use in Icon-mode buffers.")
|
|
29 (define-abbrev-table 'icon-mode-abbrev-table ())
|
|
30
|
|
31 (defvar icon-mode-map ()
|
|
32 "Keymap used in Icon mode.")
|
|
33 (if icon-mode-map
|
|
34 ()
|
|
35 (setq icon-mode-map (make-sparse-keymap))
|
|
36 (define-key icon-mode-map "{" 'electric-icon-brace)
|
|
37 (define-key icon-mode-map "}" 'electric-icon-brace)
|
|
38 (define-key icon-mode-map "\e\C-h" 'mark-icon-function)
|
|
39 (define-key icon-mode-map "\e\C-a" 'beginning-of-icon-defun)
|
|
40 (define-key icon-mode-map "\e\C-e" 'end-of-icon-defun)
|
|
41 (define-key icon-mode-map "\e\C-q" 'indent-icon-exp)
|
|
42 (define-key icon-mode-map "\177" 'backward-delete-char-untabify)
|
|
43 (define-key icon-mode-map "\t" 'icon-indent-command))
|
|
44
|
|
45 (defvar icon-mode-syntax-table nil
|
|
46 "Syntax table in use in Icon-mode buffers.")
|
|
47
|
|
48 (if icon-mode-syntax-table
|
|
49 ()
|
|
50 (setq icon-mode-syntax-table (make-syntax-table))
|
|
51 (modify-syntax-entry ?\\ "\\" icon-mode-syntax-table)
|
|
52 (modify-syntax-entry ?# "<" icon-mode-syntax-table)
|
|
53 (modify-syntax-entry ?\n ">" icon-mode-syntax-table)
|
|
54 (modify-syntax-entry ?$ "." icon-mode-syntax-table)
|
|
55 (modify-syntax-entry ?/ "." icon-mode-syntax-table)
|
|
56 (modify-syntax-entry ?* "." icon-mode-syntax-table)
|
|
57 (modify-syntax-entry ?+ "." icon-mode-syntax-table)
|
|
58 (modify-syntax-entry ?- "." icon-mode-syntax-table)
|
|
59 (modify-syntax-entry ?= "." icon-mode-syntax-table)
|
|
60 (modify-syntax-entry ?% "." icon-mode-syntax-table)
|
|
61 (modify-syntax-entry ?< "." icon-mode-syntax-table)
|
|
62 (modify-syntax-entry ?> "." icon-mode-syntax-table)
|
|
63 (modify-syntax-entry ?& "." icon-mode-syntax-table)
|
|
64 (modify-syntax-entry ?| "." icon-mode-syntax-table)
|
|
65 (modify-syntax-entry ?\' "\"" icon-mode-syntax-table))
|
|
66
|
|
67 (defconst icon-indent-level 4
|
|
68 "*Indentation of Icon statements with respect to containing block.")
|
|
69 (defconst icon-brace-imaginary-offset 0
|
|
70 "*Imagined indentation of a Icon open brace that actually follows a statement.")
|
|
71 (defconst icon-brace-offset 0
|
|
72 "*Extra indentation for braces, compared with other text in same context.")
|
|
73 (defconst icon-continued-statement-offset 4
|
|
74 "*Extra indent for lines not starting new statements.")
|
|
75 (defconst icon-continued-brace-offset 0
|
|
76 "*Extra indent for substatements that start with open-braces.
|
|
77 This is in addition to icon-continued-statement-offset.")
|
|
78
|
|
79 (defconst icon-auto-newline nil
|
|
80 "*Non-nil means automatically newline before and after braces
|
|
81 inserted in Icon code.")
|
|
82
|
|
83 (defconst icon-tab-always-indent t
|
|
84 "*Non-nil means TAB in Icon mode should always reindent the current line,
|
|
85 regardless of where in the line point is when the TAB command is used.")
|
|
86
|
|
87 (defun icon-mode ()
|
|
88 "Major mode for editing Icon code.
|
|
89 Expression and list commands understand all Icon brackets.
|
|
90 Tab indents for Icon code.
|
|
91 Paragraphs are separated by blank lines only.
|
|
92 Delete converts tabs to spaces as it moves back.
|
|
93 \\{icon-mode-map}
|
|
94 Variables controlling indentation style:
|
|
95 icon-tab-always-indent
|
|
96 Non-nil means TAB in Icon mode should always reindent the current line,
|
|
97 regardless of where in the line point is when the TAB command is used.
|
|
98 icon-auto-newline
|
|
99 Non-nil means automatically newline before and after braces
|
|
100 inserted in Icon code.
|
|
101 icon-indent-level
|
|
102 Indentation of Icon statements within surrounding block.
|
|
103 The surrounding block's indentation is the indentation
|
|
104 of the line on which the open-brace appears.
|
|
105 icon-continued-statement-offset
|
|
106 Extra indentation given to a substatement, such as the
|
|
107 then-clause of an if or body of a while.
|
|
108 icon-continued-brace-offset
|
|
109 Extra indentation given to a brace that starts a substatement.
|
|
110 This is in addition to icon-continued-statement-offset.
|
|
111 icon-brace-offset
|
|
112 Extra indentation for line if it starts with an open brace.
|
|
113 icon-brace-imaginary-offset
|
|
114 An open brace following other text is treated as if it were
|
|
115 this far to the right of the start of its line.
|
|
116
|
|
117 Turning on Icon mode calls the value of the variable icon-mode-hook with no args,
|
|
118 if that value is non-nil."
|
|
119 (interactive)
|
|
120 (kill-all-local-variables)
|
|
121 (use-local-map icon-mode-map)
|
|
122 (setq major-mode 'icon-mode)
|
|
123 (setq mode-name "Icon")
|
|
124 (setq local-abbrev-table icon-mode-abbrev-table)
|
|
125 (set-syntax-table icon-mode-syntax-table)
|
|
126 (make-local-variable 'paragraph-start)
|
|
127 (setq paragraph-start (concat "^$\\|" page-delimiter))
|
|
128 (make-local-variable 'paragraph-separate)
|
|
129 (setq paragraph-separate paragraph-start)
|
|
130 (make-local-variable 'indent-line-function)
|
|
131 (setq indent-line-function 'icon-indent-line)
|
|
132 (make-local-variable 'require-final-newline)
|
|
133 (setq require-final-newline t)
|
|
134 (make-local-variable 'comment-start)
|
|
135 (setq comment-start "# ")
|
|
136 (make-local-variable 'comment-end)
|
|
137 (setq comment-end "")
|
|
138 (make-local-variable 'comment-column)
|
|
139 (setq comment-column 32)
|
|
140 (make-local-variable 'comment-start-skip)
|
|
141 (setq comment-start-skip "# *")
|
|
142 (make-local-variable 'comment-indent-hook)
|
|
143 (setq comment-indent-hook 'icon-comment-indent)
|
|
144 (run-hooks 'icon-mode-hook))
|
|
145
|
|
146 ;; This is used by indent-for-comment
|
|
147 ;; to decide how much to indent a comment in Icon code
|
|
148 ;; based on its context.
|
|
149 (defun icon-comment-indent ()
|
|
150 (if (looking-at "^#")
|
|
151 0
|
|
152 (save-excursion
|
|
153 (skip-chars-backward " \t")
|
|
154 (max (if (bolp) 0 (1+ (current-column)))
|
|
155 comment-column))))
|
|
156
|
|
157 (defun electric-icon-brace (arg)
|
|
158 "Insert character and correct line's indentation."
|
|
159 (interactive "P")
|
|
160 (let (insertpos)
|
|
161 (if (and (not arg)
|
|
162 (eolp)
|
|
163 (or (save-excursion
|
|
164 (skip-chars-backward " \t")
|
|
165 (bolp))
|
|
166 (if icon-auto-newline
|
|
167 (progn (icon-indent-line) (newline) t)
|
|
168 nil)))
|
|
169 (progn
|
|
170 (insert last-command-char)
|
|
171 (icon-indent-line)
|
|
172 (if icon-auto-newline
|
|
173 (progn
|
|
174 (newline)
|
|
175 ;; (newline) may have done auto-fill
|
|
176 (setq insertpos (- (point) 2))
|
|
177 (icon-indent-line)))
|
|
178 (save-excursion
|
|
179 (if insertpos (goto-char (1+ insertpos)))
|
|
180 (delete-char -1))))
|
|
181 (if insertpos
|
|
182 (save-excursion
|
|
183 (goto-char insertpos)
|
|
184 (self-insert-command (prefix-numeric-value arg)))
|
|
185 (self-insert-command (prefix-numeric-value arg)))))
|
|
186
|
|
187 (defun icon-indent-command (&optional whole-exp)
|
|
188 (interactive "P")
|
|
189 "Indent current line as Icon code, or in some cases insert a tab character.
|
|
190 If icon-tab-always-indent is non-nil (the default), always indent current line.
|
|
191 Otherwise, indent the current line only if point is at the left margin
|
|
192 or in the line's indentation; otherwise insert a tab.
|
|
193
|
|
194 A numeric argument, regardless of its value,
|
|
195 means indent rigidly all the lines of the expression starting after point
|
|
196 so that this line becomes properly indented.
|
|
197 The relative indentation among the lines of the expression are preserved."
|
|
198 (if whole-exp
|
|
199 ;; If arg, always indent this line as Icon
|
|
200 ;; and shift remaining lines of expression the same amount.
|
|
201 (let ((shift-amt (icon-indent-line))
|
|
202 beg end)
|
|
203 (save-excursion
|
|
204 (if icon-tab-always-indent
|
|
205 (beginning-of-line))
|
|
206 (setq beg (point))
|
|
207 (forward-sexp 1)
|
|
208 (setq end (point))
|
|
209 (goto-char beg)
|
|
210 (forward-line 1)
|
|
211 (setq beg (point)))
|
|
212 (if (> end beg)
|
|
213 (indent-code-rigidly beg end shift-amt "#")))
|
|
214 (if (and (not icon-tab-always-indent)
|
|
215 (save-excursion
|
|
216 (skip-chars-backward " \t")
|
|
217 (not (bolp))))
|
|
218 (insert-tab)
|
|
219 (icon-indent-line))))
|
|
220
|
|
221 (defun icon-indent-line ()
|
|
222 "Indent current line as Icon code.
|
|
223 Return the amount the indentation changed by."
|
|
224 (let ((indent (calculate-icon-indent nil))
|
|
225 beg shift-amt
|
|
226 (case-fold-search nil)
|
|
227 (pos (- (point-max) (point))))
|
|
228 (beginning-of-line)
|
|
229 (setq beg (point))
|
|
230 (cond ((eq indent nil)
|
|
231 (setq indent (current-indentation)))
|
|
232 ((eq indent t)
|
|
233 (setq indent (calculate-icon-indent-within-comment)))
|
|
234 ((looking-at "[ \t]*#")
|
|
235 (setq indent 0))
|
|
236 (t
|
|
237 (skip-chars-forward " \t")
|
|
238 (if (listp indent) (setq indent (car indent)))
|
|
239 (cond ((and (looking-at "else\\b")
|
|
240 (not (looking-at "else\\s_")))
|
|
241 (setq indent (save-excursion
|
|
242 (icon-backward-to-start-of-if)
|
|
243 (current-indentation))))
|
|
244 ((or (= (following-char) ?})
|
|
245 (looking-at "end\\b"))
|
|
246 (setq indent (- indent icon-indent-level)))
|
|
247 ((= (following-char) ?{)
|
|
248 (setq indent (+ indent icon-brace-offset))))))
|
|
249 (skip-chars-forward " \t")
|
|
250 (setq shift-amt (- indent (current-column)))
|
|
251 (if (zerop shift-amt)
|
|
252 (if (> (- (point-max) pos) (point))
|
|
253 (goto-char (- (point-max) pos)))
|
|
254 (delete-region beg (point))
|
|
255 (indent-to indent)
|
|
256 ;; If initial point was within line's indentation,
|
|
257 ;; position after the indentation. Else stay at same point in text.
|
|
258 (if (> (- (point-max) pos) (point))
|
|
259 (goto-char (- (point-max) pos))))
|
|
260 shift-amt))
|
|
261
|
|
262 (defun calculate-icon-indent (&optional parse-start)
|
|
263 "Return appropriate indentation for current line as Icon code.
|
|
264 In usual case returns an integer: the column to indent to.
|
|
265 Returns nil if line starts inside a string, t if in a comment."
|
|
266 (save-excursion
|
|
267 (beginning-of-line)
|
|
268 (let ((indent-point (point))
|
|
269 (case-fold-search nil)
|
|
270 state
|
|
271 containing-sexp
|
|
272 toplevel)
|
|
273 (if parse-start
|
|
274 (goto-char parse-start)
|
|
275 (setq toplevel (beginning-of-icon-defun)))
|
|
276 (while (< (point) indent-point)
|
|
277 (setq parse-start (point))
|
|
278 (setq state (parse-partial-sexp (point) indent-point 0))
|
|
279 (setq containing-sexp (car (cdr state))))
|
|
280 (cond ((or (nth 3 state) (nth 4 state))
|
|
281 ;; return nil or t if should not change this line
|
|
282 (nth 4 state))
|
|
283 ((and containing-sexp
|
|
284 (/= (char-after containing-sexp) ?{))
|
|
285 ;; line is expression, not statement:
|
|
286 ;; indent to just after the surrounding open.
|
|
287 (goto-char (1+ containing-sexp))
|
|
288 (current-column))
|
|
289 (t
|
|
290 (if toplevel
|
|
291 ;; Outside any procedures.
|
|
292 (progn (icon-backward-to-noncomment (point-min))
|
|
293 (if (icon-is-continuation-line)
|
|
294 icon-continued-statement-offset 0))
|
|
295 ;; Statement level.
|
|
296 (if (null containing-sexp)
|
|
297 (progn (beginning-of-icon-defun)
|
|
298 (setq containing-sexp (point))))
|
|
299 (goto-char indent-point)
|
|
300 ;; Is it a continuation or a new statement?
|
|
301 ;; Find previous non-comment character.
|
|
302 (icon-backward-to-noncomment containing-sexp)
|
|
303 ;; Now we get the answer.
|
|
304 (if (icon-is-continuation-line)
|
|
305 ;; This line is continuation of preceding line's statement;
|
|
306 ;; indent icon-continued-statement-offset more than the
|
|
307 ;; first line of the statement.
|
|
308 (progn
|
|
309 (icon-backward-to-start-of-continued-exp containing-sexp)
|
|
310 (+ icon-continued-statement-offset (current-column)
|
|
311 (if (save-excursion (goto-char indent-point)
|
|
312 (skip-chars-forward " \t")
|
|
313 (eq (following-char) ?{))
|
|
314 icon-continued-brace-offset 0)))
|
|
315 ;; This line starts a new statement.
|
|
316 ;; Position following last unclosed open.
|
|
317 (goto-char containing-sexp)
|
|
318 ;; Is line first statement after an open-brace?
|
|
319 (or
|
|
320 ;; If no, find that first statement and indent like it.
|
|
321 (save-excursion
|
|
322 (if (looking-at "procedure\\s ")
|
|
323 (forward-sexp 3)
|
|
324 (forward-char 1))
|
|
325 (while (progn (skip-chars-forward " \t\n")
|
|
326 (looking-at "#"))
|
|
327 ;; Skip over comments following openbrace.
|
|
328 (forward-line 1))
|
|
329 ;; The first following code counts
|
|
330 ;; if it is before the line we want to indent.
|
|
331 (and (< (point) indent-point)
|
|
332 (current-column)))
|
|
333 ;; If no previous statement,
|
|
334 ;; indent it relative to line brace is on.
|
|
335 ;; For open brace in column zero, don't let statement
|
|
336 ;; start there too. If icon-indent-level is zero,
|
|
337 ;; use icon-brace-offset + icon-continued-statement-offset
|
|
338 ;; instead.
|
|
339 ;; For open-braces not the first thing in a line,
|
|
340 ;; add in icon-brace-imaginary-offset.
|
|
341 (+ (if (and (bolp) (zerop icon-indent-level))
|
|
342 (+ icon-brace-offset
|
|
343 icon-continued-statement-offset)
|
|
344 icon-indent-level)
|
|
345 ;; Move back over whitespace before the openbrace.
|
|
346 ;; If openbrace is not first nonwhite thing on the line,
|
|
347 ;; add the icon-brace-imaginary-offset.
|
|
348 (progn (skip-chars-backward " \t")
|
|
349 (if (bolp) 0 icon-brace-imaginary-offset))
|
|
350 ;; Get initial indentation of the line we are on.
|
|
351 (current-indentation))))))))))
|
|
352
|
|
353 ;; List of words to check for as the last thing on a line.
|
|
354 ;; If cdr is t, next line is a continuation of the same statement,
|
|
355 ;; if cdr is nil, next line starts a new (possibly indented) statement.
|
|
356
|
|
357 (defconst icon-resword-alist
|
|
358 '(("by" . t) ("case" . t) ("create") ("do") ("dynamic" . t) ("else")
|
|
359 ("every" . t) ("if" . t) ("global" . t) ("initial" . t)
|
|
360 ("link" . t) ("local" . t) ("of") ("record" . t) ("repeat" . t)
|
|
361 ("static" . t) ("then") ("to" . t) ("until" . t) ("while" . t)))
|
|
362
|
|
363 (defun icon-is-continuation-line ()
|
|
364 (let* ((ch (preceding-char))
|
|
365 (ch-syntax (char-syntax ch)))
|
|
366 (if (eq ch-syntax ?w)
|
|
367 (assoc (buffer-substring
|
|
368 (progn (forward-word -1) (point))
|
|
369 (progn (forward-word 1) (point)))
|
|
370 icon-resword-alist)
|
|
371 (not (memq ch '(0 ?\; ?\} ?\{ ?\) ?\] ?\" ?\' ?\n))))))
|
|
372
|
|
373 (defun icon-backward-to-noncomment (lim)
|
|
374 (let (opoint stop)
|
|
375 (while (not stop)
|
|
376 (skip-chars-backward " \t\n\f" lim)
|
|
377 (setq opoint (point))
|
|
378 (beginning-of-line)
|
|
379 (if (and (nth 5 (parse-partial-sexp (point) opoint))
|
|
380 (< lim (point)))
|
|
381 (search-backward "#")
|
|
382 (setq stop t)))))
|
|
383
|
|
384 (defun icon-backward-to-start-of-continued-exp (lim)
|
|
385 (if (memq (preceding-char) '(?\) ?\]))
|
|
386 (forward-sexp -1))
|
|
387 (beginning-of-line)
|
|
388 (skip-chars-forward " \t")
|
|
389 (cond
|
|
390 ((<= (point) lim) (goto-char (1+ lim)))
|
|
391 ((not (icon-is-continued-line)) 0)
|
|
392 ((and (eq (char-syntax (following-char)) ?w)
|
|
393 (cdr
|
|
394 (assoc (buffer-substring (point)
|
|
395 (save-excursion (forward-word 1) (point)))
|
|
396 icon-resword-alist))) 0)
|
|
397 (t (end-of-line 0) (icon-backward-to-start-of-continued-exp lim))))
|
|
398
|
|
399 (defun icon-is-continued-line ()
|
|
400 (save-excursion
|
|
401 (end-of-line 0)
|
|
402 (icon-is-continuation-line)))
|
|
403
|
|
404 (defun icon-backward-to-start-of-if (&optional limit)
|
|
405 "Move to the start of the last ``unbalanced'' if."
|
|
406 (or limit (setq limit (save-excursion (beginning-of-icon-defun) (point))))
|
|
407 (let ((if-level 1)
|
|
408 (case-fold-search nil))
|
|
409 (while (not (zerop if-level))
|
|
410 (backward-sexp 1)
|
|
411 (cond ((looking-at "else\\b")
|
|
412 (setq if-level (1+ if-level)))
|
|
413 ((looking-at "if\\b")
|
|
414 (setq if-level (1- if-level)))
|
|
415 ((< (point) limit)
|
|
416 (setq if-level 0)
|
|
417 (goto-char limit))))))
|
|
418
|
|
419 (defun mark-icon-function ()
|
|
420 "Put mark at end of Icon function, point at beginning."
|
|
421 (interactive)
|
|
422 (push-mark (point))
|
|
423 (end-of-icon-defun)
|
|
424 (push-mark (point))
|
|
425 (beginning-of-line 0)
|
|
426 (beginning-of-icon-defun))
|
|
427
|
|
428 (defun beginning-of-icon-defun ()
|
|
429 "Go to the start of the enclosing procedure; return t if at top level."
|
|
430 (interactive)
|
|
431 (if (re-search-backward "^procedure\\s \\|^end[ \t\n]" (point-min) 'move)
|
|
432 (looking-at "e")
|
|
433 t))
|
|
434
|
|
435 (defun end-of-icon-defun ()
|
|
436 (interactive)
|
|
437 (if (not (bobp)) (forward-char -1))
|
|
438 (re-search-forward "\\(\\s \\|^\\)end\\(\\s \\|$\\)" (point-max) 'move)
|
|
439 (forward-word -1)
|
|
440 (forward-line 1))
|
|
441
|
|
442 (defun indent-icon-exp ()
|
|
443 "Indent each line of the Icon grouping following point."
|
|
444 (interactive)
|
|
445 (let ((indent-stack (list nil))
|
|
446 (contain-stack (list (point)))
|
|
447 (case-fold-search nil)
|
|
448 restart outer-loop-done inner-loop-done state ostate
|
|
449 this-indent last-sexp
|
|
450 at-else at-brace at-do
|
|
451 (opoint (point))
|
|
452 (next-depth 0))
|
|
453 (save-excursion
|
|
454 (forward-sexp 1))
|
|
455 (save-excursion
|
|
456 (setq outer-loop-done nil)
|
|
457 (while (and (not (eobp)) (not outer-loop-done))
|
|
458 (setq last-depth next-depth)
|
|
459 ;; Compute how depth changes over this line
|
|
460 ;; plus enough other lines to get to one that
|
|
461 ;; does not end inside a comment or string.
|
|
462 ;; Meanwhile, do appropriate indentation on comment lines.
|
|
463 (setq innerloop-done nil)
|
|
464 (while (and (not innerloop-done)
|
|
465 (not (and (eobp) (setq outer-loop-done t))))
|
|
466 (setq ostate state)
|
|
467 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
|
|
468 nil nil state))
|
|
469 (setq next-depth (car state))
|
|
470 (if (and (car (cdr (cdr state)))
|
|
471 (>= (car (cdr (cdr state))) 0))
|
|
472 (setq last-sexp (car (cdr (cdr state)))))
|
|
473 (if (or (nth 4 ostate))
|
|
474 (icon-indent-line))
|
|
475 (if (or (nth 3 state))
|
|
476 (forward-line 1)
|
|
477 (setq innerloop-done t)))
|
|
478 (if (<= next-depth 0)
|
|
479 (setq outer-loop-done t))
|
|
480 (if outer-loop-done
|
|
481 nil
|
|
482 (if (/= last-depth next-depth)
|
|
483 (setq last-sexp nil))
|
|
484 (while (> last-depth next-depth)
|
|
485 (setq indent-stack (cdr indent-stack)
|
|
486 contain-stack (cdr contain-stack)
|
|
487 last-depth (1- last-depth)))
|
|
488 (while (< last-depth next-depth)
|
|
489 (setq indent-stack (cons nil indent-stack)
|
|
490 contain-stack (cons nil contain-stack)
|
|
491 last-depth (1+ last-depth)))
|
|
492 (if (null (car contain-stack))
|
|
493 (setcar contain-stack (or (car (cdr state))
|
|
494 (save-excursion (forward-sexp -1)
|
|
495 (point)))))
|
|
496 (forward-line 1)
|
|
497 (skip-chars-forward " \t")
|
|
498 (if (eolp)
|
|
499 nil
|
|
500 (if (and (car indent-stack)
|
|
501 (>= (car indent-stack) 0))
|
|
502 ;; Line is on an existing nesting level.
|
|
503 ;; Lines inside parens are handled specially.
|
|
504 (if (/= (char-after (car contain-stack)) ?{)
|
|
505 (setq this-indent (car indent-stack))
|
|
506 ;; Line is at statement level.
|
|
507 ;; Is it a new statement? Is it an else?
|
|
508 ;; Find last non-comment character before this line
|
|
509 (save-excursion
|
|
510 (setq at-else (looking-at "else\\W"))
|
|
511 (setq at-brace (= (following-char) ?{))
|
|
512 (icon-backward-to-noncomment opoint)
|
|
513 (if (icon-is-continuation-line)
|
|
514 ;; Preceding line did not end in comma or semi;
|
|
515 ;; indent this line icon-continued-statement-offset
|
|
516 ;; more than previous.
|
|
517 (progn
|
|
518 (icon-backward-to-start-of-continued-exp (car contain-stack))
|
|
519 (setq this-indent
|
|
520 (+ icon-continued-statement-offset (current-column)
|
|
521 (if at-brace icon-continued-brace-offset 0))))
|
|
522 ;; Preceding line ended in comma or semi;
|
|
523 ;; use the standard indent for this level.
|
|
524 (if at-else
|
|
525 (progn (icon-backward-to-start-of-if opoint)
|
|
526 (setq this-indent (current-indentation)))
|
|
527 (setq this-indent (car indent-stack))))))
|
|
528 ;; Just started a new nesting level.
|
|
529 ;; Compute the standard indent for this level.
|
|
530 (let ((val (calculate-icon-indent
|
|
531 (if (car indent-stack)
|
|
532 (- (car indent-stack))))))
|
|
533 (setcar indent-stack
|
|
534 (setq this-indent val))))
|
|
535 ;; Adjust line indentation according to its contents
|
|
536 (if (or (= (following-char) ?})
|
|
537 (looking-at "end\\b"))
|
|
538 (setq this-indent (- this-indent icon-indent-level)))
|
|
539 (if (= (following-char) ?{)
|
|
540 (setq this-indent (+ this-indent icon-brace-offset)))
|
|
541 ;; Put chosen indentation into effect.
|
|
542 (or (= (current-column) this-indent)
|
|
543 (progn
|
|
544 (delete-region (point) (progn (beginning-of-line) (point)))
|
|
545 (indent-to this-indent)))
|
|
546 ;; Indent any comment following the text.
|
|
547 (or (looking-at comment-start-skip)
|
|
548 (if (re-search-forward comment-start-skip (save-excursion (end-of-line) (point)) t)
|
|
549 (progn (indent-for-comment) (beginning-of-line))))))))))
|
|
550
|