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