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