· 9 years ago · Sep 11, 2016, 11:18 AM
1;;; MOD5-mode.el --- sample major mode for editing MOD5 code.
2
3;; Copyleft © 2016, by
4
5;; Author: (@gmail.com)
6;; Version: 0.0.1
7;; Created: 07-Sep-2016
8;; Keywords: languages
9;; Homepage: n/a
10
11;; This file is not part of GNU Emacs.
12
13;;; License:
14
15;; You can redistribute this program and/or modify it under the terms of the GNU General Public License version 2.
16
17;;; Commentary:
18
19;; This elisp file will enable the highlight of the MOD5 code when viewed in Emacs.
20
21;; ********* probably a link will be helpful here - under construction ***********
22
23;;; Code:
24
25;; define several category of keywords
26(setq MOD5-keywords '("SEQ_SKEL" "NEMG" "NSDN" "SSTEP" "STEP" "START" "SCU" "LAMP" "HORN" "PRINTER" "MODULE" "END MODULE" "CALL TEMPLATE" "IF" "FOR") )
27(setq MOD5-types '("AI" "AO" "DI" "DO" "AISIM" "DISIM" "ACO" "AIM" "AOT" "DOT" "AP" "AC" "DC" "DT" "DM" "AK" "AG" "AR" "TA"))
28(setq MOD5-constants '("PFS" "NFS" "IONE" "ZERO"))
29(setq MOD5-events '("WARN" "REQ" "ALT"))
30(setq MOD5-functions '("ALM_DI_DO05B" "IFD03B" "ALM_4S_AX04B" "ALM_DX05B" "ALM_RERING03B" "ALM_DI_DO05B" "IS04B"))
31(setq MOD5-operators '("=" "AND" "OR" "XOR"))
32(setq MOD5-acmdb '("\[(&A-Z0-9_)\]+" "\[(:A-Z0-9_)\]"))
33
34;; generate regex string for each category of keywords
35(setq MOD5-keywords-regexp (regexp-opt MOD5-keywords 'words))
36(setq MOD5-type-regexp (regexp-opt MOD5-types 'words))
37(setq MOD5-constant-regexp (regexp-opt MOD5-constants 'words))
38(setq MOD5-event-regexp (regexp-opt MOD5-events 'words))
39(setq MOD5-functions-regexp (regexp-opt MOD5-functions 'words))
40(setq MOD5-operators-regexp (regexp-opt MOD5-operators 'words))
41(setq MOD5-acmdb-regexp (regexp-opt MOD5-acmdb 'words))
42
43;; create the list for font-lock.
44;; each category of keyword is given a particular face
45(setq MOD5-font-lock-keywords
46 `(
47 (,MOD5-type-regexp . font-lock-type-face)
48 (,MOD5-constant-regexp . font-lock-constant-face)
49 (,MOD5-event-regexp . font-lock-builtin-face)
50 (,MOD5-functions-regexp . font-lock-function-name-face)
51 (,MOD5-keywords-regexp . font-lock-keyword-face)
52 (,MOD5-acmdb-regexp . font-lock-variable-name-face)
53 (,MOD5-operators-regexp . font-lock-negation-char-face)
54 ;; note: order above matters, because once colored, that part won't change.
55 ;; in general, longer words first
56 ))
57
58;;;###autoload
59(define-derived-mode MOD5-mode fundamental-mode
60 "MOD5 mode"
61 "Major mode for editing MOD5 Dowtran Code…"
62
63 ;; code for syntax highlighting
64 (setq font-lock-defaults '((MOD5-font-lock-keywords))))
65
66;; clear memory. no longer needed
67(setq MOD5-keywords nil)
68(setq MOD5-types nil)
69(setq MOD5-constants nil)
70(setq MOD5-events nil)
71(setq MOD5-functions nil)
72(setq MOD5-acmdb nil)
73(setq MOD5-operators nil)
74
75;; clear memory. no longer needed
76(setq MOD5-keywords-regexp nil)
77(setq MOD5-types-regexp nil)
78(setq MOD5-constants-regexp nil)
79(setq MOD5-events-regexp nil)
80(setq MOD5-functions-regexp nil)
81(setq MOD5-acmdb-regexp nil)
82(setq MOD5-operators-regexp nil)
83
84;; add the mode to the `features' list
85(provide 'MOD5-mode)
86
87;; Local Variables:
88;; coding: utf-8
89;; End:
90
91;;; MOD5-mode.el ends here