Initial Commit
[packages] / xemacs-packages / prog-modes / uil-mode.el
1 ;;; uil-mode.el --- UIL file editing mode for Emacs
2
3 ;;; Written by Brett Johnson <brett@fc.hp.com>
4 ;;; Maintained for XEmacs by Jake Colman <jake.colman@xemacs.org>
5
6 ;;; Commentary:
7 ;; Sets up cc-mode with support for UIL file #-comments , a lightly
8 ;; hacked syntax table, and some minimal font-lock regexps.
9
10 ;;; Code:
11
12 (require 'cc-mode)
13
14 (defvar uil-mode-syntax-table nil
15   "Syntax table in use in uil-mode buffers.")
16
17 (if uil-mode-syntax-table
18     ()
19   (setq uil-mode-syntax-table (make-syntax-table))
20   (c-populate-syntax-table uil-mode-syntax-table)
21   ;; add extra comment syntax
22   (modify-syntax-entry ?/  ". 14" uil-mode-syntax-table)
23   (modify-syntax-entry ?*  ". 23" uil-mode-syntax-table)
24   (modify-syntax-entry ?!  "< b" uil-mode-syntax-table)
25   (modify-syntax-entry ?\n "> b" uil-mode-syntax-table)
26   (modify-syntax-entry ?\^m "> b" uil-mode-syntax-table)
27   )
28
29 (defvar uil-mode-abbrev-table nil
30   "Abbrev table in use in uil-mode buffers.")
31 (define-abbrev-table 'uil-mode-abbrev-table ())
32
33 (defconst uil-font-lock-keywords
34   (list
35    ;; Make punctuation bold.
36    (cons "[-+*/{}():;=]" 'bold)
37    ;; Fontify procedure/identifier names.
38    '("\\(procedure\\)[ \t]+\\(\\sw+\\)"
39      (1 font-lock-keyword-face) (2 font-lock-function-name-face))
40    '("\\(identifier\\)[ \t]+\\(\\sw+\\)"
41      (1 font-lock-keyword-face) (2 font-lock-variable-name-face))
42    ;; Fontify UIL keywords.
43    (cons (concat "\\<\\(module\\|end\\|widget\\|gadget\\|"
44                  "arguments\\|callbacks\\|controls\\|identifiers\\|"
45                  "include\\|list\\|object\\|procedure[s]?\\|value\\|"
46                  "exported\\|private\\|on\\|off\\|true\\|false\\)\\>")
47          'font-lock-keyword-face)
48    ;; Pseudo-keyworks (not reserved).
49    (cons (concat "\\<\\(background\\|case_\\(in\\)?sensitive\\|file\\|"
50                  "foreground\\|imported\\|\\(un\\)?managed\\|names\\|"
51                  "objects\\|right_to_left\\|user_defined\\)\\>")
52          'font-lock-type-face)
53    ;; Built in types..
54    (cons (concat
55           "\\<\\(a\\(ny\\|rgument\\|sciz_\\(string_\\)?table\\)\\|"
56           "boolean\\|c\\(haracter_set\\|olor\\(_table\\)?\\)\\|"
57           "compound_string\\(_table\\)?\\|font\\(_table\\|set\\)?\\|"
58           "i\\(con\\|nteger\\(_table\\)?\\)\\|keysym\\|reason\\|rgb\\|"
59           "single_float\\|string\\(_table\\)?\\|translation_table\\|"
60           "wide_character\\|xbitmapfile\\|version\\)\\>") 'font-lock-type-face)
61    ;; Make a hack at motif constants & fields..
62    (cons "\\<\\(Xm[a-zA-Z_]+\\|iso_[a-z0-1A-Z]+\\)\\>" 'font-lock-variable-name-face)
63    ))
64
65 (put 'uil-mode 'font-lock-keywords 'uil-font-lock-keywords)
66
67 ;;;###autoload
68 (defun uil-mode ()
69   "Major mode for editing UIL files.
70 This is much like C mode except for the syntax of comments.  It uses
71 the same keymap as C mode and has the same variables for customizing
72 indentation.  It has its own abbrev table and its own syntax table.
73
74 Turning on uil mode calls the value of the variable `uil-mode-hook'
75 with no args, if that value is non-nil."
76   (interactive)
77   (kill-all-local-variables)
78   (require 'cc-mode)
79   (c-initialize-cc-mode)
80   (use-local-map c-mode-map)
81   (c-common-init)
82   (setq major-mode 'uil-mode)
83   (setq mode-name "uil")
84   (setq local-abbrev-table uil-mode-abbrev-table)
85   (set-syntax-table uil-mode-syntax-table)
86   (make-local-variable 'indent-line-function)
87   (setq indent-line-function 'c-indent-line)
88   (make-local-variable 'require-final-newline)
89   (setq require-final-newline t)
90   (make-local-variable 'comment-start)
91 ;  (setq comment-start "!\\|/\*")
92 ;  (make-local-variable 'comment-end)
93 ;  (setq comment-end "\n\\|\*/")
94 ;  (make-local-variable 'comment-start-skip)
95   (setq comment-start "!")
96   (make-local-variable 'comment-end)
97   (setq comment-end "")
98   (make-local-variable 'comment-start-skip)
99   (setq comment-start-skip "!+ *")
100   (make-local-variable 'comment-indent-function)
101   (setq comment-indent-function 'c-comment-indent)
102   (run-hooks 'uil-mode-hook))
103
104 ;; XEmacs addition
105 ;;;###autoload(add-to-list 'auto-mode-alist '("\\.uil$" . uil-mode))
106
107 (provide 'uil-mode)
108
109 ;;; uil-mode.el ends here