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