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