Fix provide call.
[bpt/emacs.git] / lisp / progmodes / icon.el
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
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; A major mode for editing the Icon programming language.
29
30 ;;; Code:
31
32 (defvar icon-mode-abbrev-table nil
33 "Abbrev table in use in Icon-mode buffers.")
34 (define-abbrev-table 'icon-mode-abbrev-table ())
35
36 (defvar icon-mode-map ()
37 "Keymap used in Icon mode.")
38 (if icon-mode-map
39 ()
40 (let ((map (make-sparse-keymap "Icon")))
41 (setq icon-mode-map (make-sparse-keymap))
42 (define-key icon-mode-map "{" 'electric-icon-brace)
43 (define-key icon-mode-map "}" 'electric-icon-brace)
44 (define-key icon-mode-map "\e\C-h" 'mark-icon-function)
45 (define-key icon-mode-map "\e\C-a" 'beginning-of-icon-defun)
46 (define-key icon-mode-map "\e\C-e" 'end-of-icon-defun)
47 (define-key icon-mode-map "\e\C-q" 'indent-icon-exp)
48 (define-key icon-mode-map "\177" 'backward-delete-char-untabify)
49 (define-key icon-mode-map "\t" 'icon-indent-command)
50
51 (define-key icon-mode-map [menu-bar] (make-sparse-keymap))
52 (define-key icon-mode-map [menu-bar icon]
53 (cons "Icon" map))
54 (define-key map [beginning-of-icon-defun] '("Beginning of function" . beginning-of-icon-defun))
55 (define-key map [end-of-icon-defun] '("End of function" . end-of-icon-defun))
56 (define-key map [comment-region] '("Comment Out Region" . comment-region))
57 (define-key map [indent-region] '("Indent Region" . indent-region))
58 (define-key map [indent-line] '("Indent Line" . icon-indent-command))
59 (put 'eval-region 'menu-enable 'mark-active)
60 (put 'comment-region 'menu-enable 'mark-active)
61 (put 'indent-region 'menu-enable 'mark-active)))
62
63 (defvar icon-mode-syntax-table nil
64 "Syntax table in use in Icon-mode buffers.")
65
66 (if icon-mode-syntax-table
67 ()
68 (setq icon-mode-syntax-table (make-syntax-table))
69 (modify-syntax-entry ?\\ "\\" icon-mode-syntax-table)
70 (modify-syntax-entry ?# "<" icon-mode-syntax-table)
71 (modify-syntax-entry ?\n ">" icon-mode-syntax-table)
72 (modify-syntax-entry ?$ "." icon-mode-syntax-table)
73 (modify-syntax-entry ?/ "." icon-mode-syntax-table)
74 (modify-syntax-entry ?* "." icon-mode-syntax-table)
75 (modify-syntax-entry ?+ "." icon-mode-syntax-table)
76 (modify-syntax-entry ?- "." icon-mode-syntax-table)
77 (modify-syntax-entry ?= "." icon-mode-syntax-table)
78 (modify-syntax-entry ?% "." icon-mode-syntax-table)
79 (modify-syntax-entry ?< "." icon-mode-syntax-table)
80 (modify-syntax-entry ?> "." icon-mode-syntax-table)
81 (modify-syntax-entry ?& "." icon-mode-syntax-table)
82 (modify-syntax-entry ?| "." icon-mode-syntax-table)
83 (modify-syntax-entry ?\' "\"" icon-mode-syntax-table))
84
85 (defgroup icon nil
86 "Mode for editing Icon code."
87 :group 'languages)
88
89 (defcustom icon-indent-level 4
90 "*Indentation of Icon statements with respect to containing block."
91 :type 'integer
92 :group 'icon)
93
94 (defcustom icon-brace-imaginary-offset 0
95 "*Imagined indentation of a Icon open brace that actually follows a statement."
96 :type 'integer
97 :group 'icon)
98
99 (defcustom icon-brace-offset 0
100 "*Extra indentation for braces, compared with other text in same context."
101 :type 'integer
102 :group 'icon)
103
104 (defcustom icon-continued-statement-offset 4
105 "*Extra indent for Icon lines not starting new statements."
106 :type 'integer
107 :group 'icon)
108
109 (defcustom icon-continued-brace-offset 0
110 "*Extra indent for Icon substatements that start with open-braces.
111 This is in addition to `icon-continued-statement-offset'."
112 :type 'integer
113 :group 'icon)
114
115 (defcustom icon-auto-newline nil
116 "*Non-nil means automatically newline before and after braces Icon code.
117 This applies when braces are inserted."
118 :type 'boolean
119 :group 'icon)
120
121 (defcustom icon-tab-always-indent t
122 "*Non-nil means TAB in Icon mode should always reindent the current line.
123 It will then reindent, regardless of where in the line point is
124 when the TAB command is used."
125 :type 'integer
126 :group 'icon)
127
128 (defvar icon-imenu-generic-expression
129 '((nil "^[ \t]*procedure[ \t]+\\(\\sw+\\)[ \t]*(" 1))
130 "Imenu expression for Icon mode. See `imenu-generic-expression'.")
131
132
133 \f
134 ;;;###autoload
135 (defun icon-mode ()
136 "Major mode for editing Icon code.
137 Expression and list commands understand all Icon brackets.
138 Tab indents for Icon code.
139 Paragraphs are separated by blank lines only.
140 Delete converts tabs to spaces as it moves back.
141 \\{icon-mode-map}
142 Variables controlling indentation style:
143 icon-tab-always-indent
144 Non-nil means TAB in Icon mode should always reindent the current line,
145 regardless of where in the line point is when the TAB command is used.
146 icon-auto-newline
147 Non-nil means automatically newline before and after braces
148 inserted in Icon code.
149 icon-indent-level
150 Indentation of Icon statements within surrounding block.
151 The surrounding block's indentation is the indentation
152 of the line on which the open-brace appears.
153 icon-continued-statement-offset
154 Extra indentation given to a substatement, such as the
155 then-clause of an if or body of a while.
156 icon-continued-brace-offset
157 Extra indentation given to a brace that starts a substatement.
158 This is in addition to `icon-continued-statement-offset'.
159 icon-brace-offset
160 Extra indentation for line if it starts with an open brace.
161 icon-brace-imaginary-offset
162 An open brace following other text is treated as if it were
163 this far to the right of the start of its line.
164
165 Turning on Icon mode calls the value of the variable `icon-mode-hook'
166 with no args, if that value is non-nil."
167 (interactive)
168 (kill-all-local-variables)
169 (use-local-map icon-mode-map)
170 (setq major-mode 'icon-mode)
171 (setq mode-name "Icon")
172 (setq local-abbrev-table icon-mode-abbrev-table)
173 (set-syntax-table icon-mode-syntax-table)
174 (make-local-variable 'paragraph-start)
175 (setq paragraph-start (concat "$\\|" page-delimiter))
176 (make-local-variable 'paragraph-separate)
177 (setq paragraph-separate paragraph-start)
178 (make-local-variable 'indent-line-function)
179 (setq indent-line-function 'icon-indent-line)
180 (make-local-variable 'require-final-newline)
181 (setq require-final-newline t)
182 (make-local-variable 'comment-start)
183 (setq comment-start "# ")
184 (make-local-variable 'comment-end)
185 (setq comment-end "")
186 (make-local-variable 'comment-column)
187 (setq comment-column 32)
188 (make-local-variable 'comment-start-skip)
189 (setq comment-start-skip "# *")
190 (make-local-variable 'comment-indent-function)
191 (setq comment-indent-function 'icon-comment-indent)
192 ;; font-lock support
193 (make-local-variable 'font-lock-defaults)
194 (setq font-lock-defaults
195 '((icon-font-lock-keywords
196 icon-font-lock-keywords-1 icon-font-lock-keywords-2)
197 nil nil ((?_ . "w")) beginning-of-defun
198 ;; Obsoleted by Emacs 19.35 parse-partial-sexp's COMMENTSTOP.
199 ;(font-lock-comment-start-regexp . "#")
200 (font-lock-mark-block-function . mark-defun)))
201 ;; imenu support
202 (make-local-variable 'imenu-generic-expression)
203 (setq imenu-generic-expression icon-imenu-generic-expression)
204 ;; hideshow support
205 ;; we start from the assertion that `hs-special-modes-alist' is autoloaded.
206 (unless (assq 'icon-mode hs-special-modes-alist)
207 (setq hs-special-modes-alist
208 (cons '(icon-mode "\\<procedure\\>" "\\<end\\>" nil
209 icon-forward-sexp-function)
210 hs-special-modes-alist)))
211 (run-hooks 'icon-mode-hook))
212 \f
213 ;; This is used by indent-for-comment to decide how much to
214 ;; indent a comment in Icon code based on its context.
215 (defun icon-comment-indent ()
216 (if (looking-at "^#")
217 0
218 (save-excursion
219 (skip-chars-backward " \t")
220 (max (if (bolp) 0 (1+ (current-column)))
221 comment-column))))
222
223 (defun electric-icon-brace (arg)
224 "Insert character and correct line's indentation."
225 (interactive "P")
226 (let (insertpos)
227 (if (and (not arg)
228 (eolp)
229 (or (save-excursion
230 (skip-chars-backward " \t")
231 (bolp))
232 (if icon-auto-newline
233 (progn (icon-indent-line) (newline) t)
234 nil)))
235 (progn
236 (insert last-command-char)
237 (icon-indent-line)
238 (if icon-auto-newline
239 (progn
240 (newline)
241 ;; (newline) may have done auto-fill
242 (setq insertpos (- (point) 2))
243 (icon-indent-line)))
244 (save-excursion
245 (if insertpos (goto-char (1+ insertpos)))
246 (delete-char -1))))
247 (if insertpos
248 (save-excursion
249 (goto-char insertpos)
250 (self-insert-command (prefix-numeric-value arg)))
251 (self-insert-command (prefix-numeric-value arg)))))
252 \f
253 (defun icon-indent-command (&optional whole-exp)
254 (interactive "P")
255 "Indent current line as Icon code, or in some cases insert a tab character.
256 If `icon-tab-always-indent' is non-nil (the default), always indent current
257 line. Otherwise, indent the current line only if point is at the left margin
258 or in the line's indentation; otherwise insert a tab.
259
260 A numeric argument, regardless of its value, means indent rigidly all the
261 lines of the expression starting after point so that this line becomes
262 properly indented. The relative indentation among the lines of the
263 expression are preserved."
264 (if whole-exp
265 ;; If arg, always indent this line as Icon
266 ;; and shift remaining lines of expression the same amount.
267 (let ((shift-amt (icon-indent-line))
268 beg end)
269 (save-excursion
270 (if icon-tab-always-indent
271 (beginning-of-line))
272 (setq beg (point))
273 (forward-sexp 1)
274 (setq end (point))
275 (goto-char beg)
276 (forward-line 1)
277 (setq beg (point)))
278 (if (> end beg)
279 (indent-code-rigidly beg end shift-amt "#")))
280 (if (and (not icon-tab-always-indent)
281 (save-excursion
282 (skip-chars-backward " \t")
283 (not (bolp))))
284 (insert-tab)
285 (icon-indent-line))))
286
287 (defun icon-indent-line ()
288 "Indent current line as Icon code.
289 Return the amount the indentation changed by."
290 (let ((indent (calculate-icon-indent nil))
291 beg shift-amt
292 (case-fold-search nil)
293 (pos (- (point-max) (point))))
294 (beginning-of-line)
295 (setq beg (point))
296 (cond ((eq indent nil)
297 (setq indent (current-indentation)))
298 ((looking-at "[ \t]*#")
299 (setq indent 0))
300 (t
301 (skip-chars-forward " \t")
302 (if (listp indent) (setq indent (car indent)))
303 (cond ((and (looking-at "else\\b")
304 (not (looking-at "else\\s_")))
305 (setq indent (save-excursion
306 (icon-backward-to-start-of-if)
307 (current-indentation))))
308 ((or (= (following-char) ?})
309 (looking-at "end\\b"))
310 (setq indent (- indent icon-indent-level)))
311 ((= (following-char) ?{)
312 (setq indent (+ indent icon-brace-offset))))))
313 (skip-chars-forward " \t")
314 (setq shift-amt (- indent (current-column)))
315 (if (zerop shift-amt)
316 (if (> (- (point-max) pos) (point))
317 (goto-char (- (point-max) pos)))
318 (delete-region beg (point))
319 (indent-to indent)
320 ;; If initial point was within line's indentation,
321 ;; position after the indentation. Else stay at same point in text.
322 (if (> (- (point-max) pos) (point))
323 (goto-char (- (point-max) pos))))
324 shift-amt))
325
326 (defun calculate-icon-indent (&optional parse-start)
327 "Return appropriate indentation for current line as Icon code.
328 In usual case returns an integer: the column to indent to.
329 Returns nil if line starts inside a string, t if in a comment."
330 (save-excursion
331 (beginning-of-line)
332 (let ((indent-point (point))
333 (case-fold-search nil)
334 state
335 containing-sexp
336 toplevel)
337 (if parse-start
338 (goto-char parse-start)
339 (setq toplevel (beginning-of-icon-defun)))
340 (while (< (point) indent-point)
341 (setq parse-start (point))
342 (setq state (parse-partial-sexp (point) indent-point 0))
343 (setq containing-sexp (car (cdr state))))
344 (cond ((or (nth 3 state) (nth 4 state))
345 ;; return nil or t if should not change this line
346 (nth 4 state))
347 ((and containing-sexp
348 (/= (char-after containing-sexp) ?{))
349 ;; line is expression, not statement:
350 ;; indent to just after the surrounding open.
351 (goto-char (1+ containing-sexp))
352 (current-column))
353 (t
354 (if toplevel
355 ;; Outside any procedures.
356 (progn (icon-backward-to-noncomment (point-min))
357 (if (icon-is-continuation-line)
358 icon-continued-statement-offset 0))
359 ;; Statement level.
360 (if (null containing-sexp)
361 (progn (beginning-of-icon-defun)
362 (setq containing-sexp (point))))
363 (goto-char indent-point)
364 ;; Is it a continuation or a new statement?
365 ;; Find previous non-comment character.
366 (icon-backward-to-noncomment containing-sexp)
367 ;; Now we get the answer.
368 (if (icon-is-continuation-line)
369 ;; This line is continuation of preceding line's statement;
370 ;; indent icon-continued-statement-offset more than the
371 ;; first line of the statement.
372 (progn
373 (icon-backward-to-start-of-continued-exp containing-sexp)
374 (+ icon-continued-statement-offset (current-column)
375 (if (save-excursion (goto-char indent-point)
376 (skip-chars-forward " \t")
377 (eq (following-char) ?{))
378 icon-continued-brace-offset 0)))
379 ;; This line starts a new statement.
380 ;; Position following last unclosed open.
381 (goto-char containing-sexp)
382 ;; Is line first statement after an open-brace?
383 (or
384 ;; If no, find that first statement and indent like it.
385 (save-excursion
386 (if (looking-at "procedure\\s ")
387 (forward-sexp 3)
388 (forward-char 1))
389 (while (progn (skip-chars-forward " \t\n")
390 (looking-at "#"))
391 ;; Skip over comments following openbrace.
392 (forward-line 1))
393 ;; The first following code counts
394 ;; if it is before the line we want to indent.
395 (and (< (point) indent-point)
396 (current-column)))
397 ;; If no previous statement,
398 ;; indent it relative to line brace is on.
399 ;; For open brace in column zero, don't let statement
400 ;; start there too. If icon-indent-level is zero,
401 ;; use icon-brace-offset + icon-continued-statement-offset
402 ;; instead.
403 ;; For open-braces not the first thing in a line,
404 ;; add in icon-brace-imaginary-offset.
405 (+ (if (and (bolp) (zerop icon-indent-level))
406 (+ icon-brace-offset
407 icon-continued-statement-offset)
408 icon-indent-level)
409 ;; Move back over whitespace before the openbrace.
410 ;; If openbrace is not first nonwhite thing on the line,
411 ;; add the icon-brace-imaginary-offset.
412 (progn (skip-chars-backward " \t")
413 (if (bolp) 0 icon-brace-imaginary-offset))
414 ;; Get initial indentation of the line we are on.
415 (current-indentation))))))))))
416
417 ;; List of words to check for as the last thing on a line.
418 ;; If cdr is t, next line is a continuation of the same statement,
419 ;; if cdr is nil, next line starts a new (possibly indented) statement.
420
421 (defconst icon-resword-alist
422 '(("by" . t) ("case" . t) ("create") ("do") ("dynamic" . t) ("else")
423 ("every" . t) ("if" . t) ("global" . t) ("initial" . t)
424 ("link" . t) ("local" . t) ("of") ("record" . t) ("repeat" . t)
425 ("static" . t) ("then") ("to" . t) ("until" . t) ("while" . t)))
426
427 (defun icon-is-continuation-line ()
428 (let* ((ch (preceding-char))
429 (ch-syntax (char-syntax ch)))
430 (if (eq ch-syntax ?w)
431 (assoc (buffer-substring
432 (progn (forward-word -1) (point))
433 (progn (forward-word 1) (point)))
434 icon-resword-alist)
435 (not (memq ch '(0 ?\; ?\} ?\{ ?\) ?\] ?\" ?\' ?\n))))))
436
437 (defun icon-backward-to-noncomment (lim)
438 (let (opoint stop)
439 (while (not stop)
440 (skip-chars-backward " \t\n\f" lim)
441 (setq opoint (point))
442 (beginning-of-line)
443 (if (and (nth 5 (parse-partial-sexp (point) opoint))
444 (< lim (point)))
445 (search-backward "#")
446 (setq stop t)))))
447
448 (defun icon-backward-to-start-of-continued-exp (lim)
449 (if (memq (preceding-char) '(?\) ?\]))
450 (forward-sexp -1))
451 (beginning-of-line)
452 (skip-chars-forward " \t")
453 (cond
454 ((<= (point) lim) (goto-char (1+ lim)))
455 ((not (icon-is-continued-line)) 0)
456 ((and (eq (char-syntax (following-char)) ?w)
457 (cdr
458 (assoc (buffer-substring (point)
459 (save-excursion (forward-word 1) (point)))
460 icon-resword-alist))) 0)
461 (t (end-of-line 0) (icon-backward-to-start-of-continued-exp lim))))
462
463 (defun icon-is-continued-line ()
464 (save-excursion
465 (end-of-line 0)
466 (icon-is-continuation-line)))
467
468 (defun icon-backward-to-start-of-if (&optional limit)
469 "Move to the start of the last \"unbalanced\" if."
470 (or limit (setq limit (save-excursion (beginning-of-icon-defun) (point))))
471 (let ((if-level 1)
472 (case-fold-search nil))
473 (while (not (zerop if-level))
474 (backward-sexp 1)
475 (cond ((looking-at "else\\b")
476 (setq if-level (1+ if-level)))
477 ((looking-at "if\\b")
478 (setq if-level (1- if-level)))
479 ((< (point) limit)
480 (setq if-level 0)
481 (goto-char limit))))))
482 \f
483 (defun mark-icon-function ()
484 "Put mark at end of Icon function, point at beginning."
485 (interactive)
486 (push-mark (point))
487 (end-of-icon-defun)
488 (push-mark (point))
489 (beginning-of-line 0)
490 (beginning-of-icon-defun))
491
492 (defun beginning-of-icon-defun ()
493 "Go to the start of the enclosing procedure; return t if at top level."
494 (interactive)
495 (if (re-search-backward "^procedure\\s \\|^end[ \t\n]" (point-min) 'move)
496 (looking-at "e")
497 t))
498
499 (defun end-of-icon-defun ()
500 (interactive)
501 (if (not (bobp)) (forward-char -1))
502 (re-search-forward "\\(\\s \\|^\\)end\\(\\s \\|$\\)" (point-max) 'move)
503 (forward-word -1)
504 (forward-line 1))
505 \f
506 (defun indent-icon-exp ()
507 "Indent each line of the Icon grouping following point."
508 (interactive)
509 (let ((indent-stack (list nil))
510 (contain-stack (list (point)))
511 (case-fold-search nil)
512 restart outer-loop-done inner-loop-done state ostate
513 this-indent last-sexp last-depth
514 at-else at-brace at-do
515 (opoint (point))
516 (next-depth 0))
517 (save-excursion
518 (forward-sexp 1))
519 (save-excursion
520 (setq outer-loop-done nil)
521 (while (and (not (eobp)) (not outer-loop-done))
522 (setq last-depth next-depth)
523 ;; Compute how depth changes over this line
524 ;; plus enough other lines to get to one that
525 ;; does not end inside a comment or string.
526 ;; Meanwhile, do appropriate indentation on comment lines.
527 (setq inner-loop-done nil)
528 (while (and (not inner-loop-done)
529 (not (and (eobp) (setq outer-loop-done t))))
530 (setq ostate state)
531 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
532 nil nil state))
533 (setq next-depth (car state))
534 (if (and (car (cdr (cdr state)))
535 (>= (car (cdr (cdr state))) 0))
536 (setq last-sexp (car (cdr (cdr state)))))
537 (if (or (nth 4 ostate))
538 (icon-indent-line))
539 (if (or (nth 3 state))
540 (forward-line 1)
541 (setq inner-loop-done t)))
542 (if (<= next-depth 0)
543 (setq outer-loop-done t))
544 (if outer-loop-done
545 nil
546 (if (/= last-depth next-depth)
547 (setq last-sexp nil))
548 (while (> last-depth next-depth)
549 (setq indent-stack (cdr indent-stack)
550 contain-stack (cdr contain-stack)
551 last-depth (1- last-depth)))
552 (while (< last-depth next-depth)
553 (setq indent-stack (cons nil indent-stack)
554 contain-stack (cons nil contain-stack)
555 last-depth (1+ last-depth)))
556 (if (null (car contain-stack))
557 (setcar contain-stack (or (car (cdr state))
558 (save-excursion (forward-sexp -1)
559 (point)))))
560 (forward-line 1)
561 (skip-chars-forward " \t")
562 (if (eolp)
563 nil
564 (if (and (car indent-stack)
565 (>= (car indent-stack) 0))
566 ;; Line is on an existing nesting level.
567 ;; Lines inside parens are handled specially.
568 (if (/= (char-after (car contain-stack)) ?{)
569 (setq this-indent (car indent-stack))
570 ;; Line is at statement level.
571 ;; Is it a new statement? Is it an else?
572 ;; Find last non-comment character before this line
573 (save-excursion
574 (setq at-else (looking-at "else\\W"))
575 (setq at-brace (= (following-char) ?{))
576 (icon-backward-to-noncomment opoint)
577 (if (icon-is-continuation-line)
578 ;; Preceding line did not end in comma or semi;
579 ;; indent this line icon-continued-statement-offset
580 ;; more than previous.
581 (progn
582 (icon-backward-to-start-of-continued-exp (car contain-stack))
583 (setq this-indent
584 (+ icon-continued-statement-offset (current-column)
585 (if at-brace icon-continued-brace-offset 0))))
586 ;; Preceding line ended in comma or semi;
587 ;; use the standard indent for this level.
588 (if at-else
589 (progn (icon-backward-to-start-of-if opoint)
590 (setq this-indent (current-indentation)))
591 (setq this-indent (car indent-stack))))))
592 ;; Just started a new nesting level.
593 ;; Compute the standard indent for this level.
594 (let ((val (calculate-icon-indent
595 (if (car indent-stack)
596 (- (car indent-stack))))))
597 (setcar indent-stack
598 (setq this-indent val))))
599 ;; Adjust line indentation according to its contents
600 (if (or (= (following-char) ?})
601 (looking-at "end\\b"))
602 (setq this-indent (- this-indent icon-indent-level)))
603 (if (= (following-char) ?{)
604 (setq this-indent (+ this-indent icon-brace-offset)))
605 ;; Put chosen indentation into effect.
606 (or (= (current-column) this-indent)
607 (progn
608 (delete-region (point) (progn (beginning-of-line) (point)))
609 (indent-to this-indent)))
610 ;; Indent any comment following the text.
611 (or (looking-at comment-start-skip)
612 (if (re-search-forward comment-start-skip (save-excursion (end-of-line) (point)) t)
613 (progn (indent-for-comment) (beginning-of-line))))))))))
614
615 (defconst icon-font-lock-keywords-1
616 (eval-when-compile
617 (list
618 ;; Fontify procedure name definitions.
619 '("^[ \t]*\\(procedure\\)\\>[ \t]*\\(\\sw+\\)?"
620 (1 font-lock-builtin-face) (2 font-lock-function-name-face nil t))))
621 "Subdued level highlighting for Icon mode.")
622
623 (defconst icon-font-lock-keywords-2
624 (append
625 icon-font-lock-keywords-1
626 (eval-when-compile
627 (list
628 ;; Fontify all type specifiers.
629 (cons
630 (concat
631 "\\<" (regexp-opt '("null" "string" "co-expression" "table" "integer"
632 "cset" "set" "real" "file" "list") t)
633 "\\>")
634 'font-lock-type-face)
635 ;; Fontify all keywords.
636 ;;
637 (cons
638 (concat
639 "\\<"
640 (regexp-opt
641 '("break" "do" "next" "repeat" "to" "by" "else" "if" "not" "return"
642 "until" "case" "of" "while" "create" "every" "suspend" "default"
643 "fail" "record" "then") t)
644 "\\>")
645 'font-lock-keyword-face)
646 ;; "end" "initial"
647 (cons (concat "\\<" (regexp-opt '("end" "initial") t) "\\>")
648 'font-lock-builtin-face)
649 ;; Fontify all system variables.
650 (cons
651 (regexp-opt
652 '("&allocated" "&ascii" "&clock" "&col" "&collections" "&column"
653 "&control" "&cset" "&current" "&date" "&dateline" "&digits" "&dump"
654 "&e" "&error" "&errornumber" "&errortext" "&errorvalue" "&errout"
655 "&eventcode" "&eventsource" "&eventvalue" "&fail" "&features"
656 "&file" "&host" "&input" "&interval" "&lcase" "&ldrag" "&letters"
657 "&level" "&line" "&lpress" "&lrelease" "&main" "&mdrag" "&meta"
658 "&mpress" "&mrelease" "&null" "&output" "&phi" "&pi" "&pos"
659 "&progname" "&random" "&rdrag" "&regions" "&resize" "&row"
660 "&rpress" "&rrelease" "&shift" "&source" "&storage" "&subject"
661 "&time" "&trace" "&ucase" "&version" "&window" "&x" "&y") t)
662 'font-lock-reference-face)
663 (cons ;; global local static declarations and link files
664 (concat
665 "^[ \t]*"
666 (regexp-opt '("global" "link" "local" "static") t)
667 "\\(\\sw+\\>\\)*")
668 '((1 font-lock-builtin-face)
669 (font-lock-match-c-style-declaration-item-and-skip-to-next
670 (goto-char (or (match-beginning 2) (match-end 1))) nil
671 (1 (if (match-beginning 2)
672 font-lock-function-name-face
673 font-lock-variable-name-face)))))
674
675 (cons ;; $define $elif $ifdef $ifndef $undef
676 (concat "^"
677 (regexp-opt'("$define" "$elif" "$ifdef" "$ifndef" "$undef") t)
678 "\\>[ \t]*\\([^ \t\n]+\\)?")
679 '((1 font-lock-builtin-face)
680 (4 font-lock-variable-name-face nil t)))
681 (cons ;; $dump $endif $else $include
682 (concat
683 "^" (regexp-opt'("$dump" "$endif" "$else" "$include") t) "\\>" )
684 'font-lock-builtin-face)
685 (cons ;; $warning $error
686 (concat "^" (regexp-opt '("$warning" "$error") t)
687 "\\>[ \t]*\\(.+\\)?")
688 '((1 font-lock-builtin-face) (3 font-lock-warning-face nil t))))))
689 "Gaudy level highlighting for Icon mode.")
690
691 (defvar icon-font-lock-keywords icon-font-lock-keywords-1
692 "Default expressions to highlight in `icon-mode'.")
693
694 ;;;used by hs-minor-mode
695 (defun icon-forward-sexp-function (arg)
696 (if (< arg 0)
697 (beginning-of-icon-defun)
698 (end-of-icon-defun)
699 (forward-char -1)))
700
701 (provide 'icon)
702
703 ;;; icon.el ends here