Created
September 11, 2016 11:17
-
-
Save prasannarajaram/2fb69bfacb25cf1e2646ab1c86d29e98 to your computer and use it in GitHub Desktop.
Syntax highlighting using Emacs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; MOD5-mode.el --- sample major mode for editing MOD5 code. | |
;; Copyleft © 2016, by | |
;; Author: (@gmail.com) | |
;; Version: 0.0.1 | |
;; Created: 07-Sep-2016 | |
;; Keywords: languages | |
;; Homepage: n/a | |
;; This file is not part of GNU Emacs. | |
;;; License: | |
;; You can redistribute this program and/or modify it under the terms of the GNU General Public License version 2. | |
;;; Commentary: | |
;; This elisp file will enable the highlight of the MOD5 code when viewed in Emacs. | |
;; ********* probably a link will be helpful here - under construction *********** | |
;;; Code: | |
;; define several category of keywords | |
(setq MOD5-keywords '("SEQ_SKEL" "NEMG" "NSDN" "SSTEP" "STEP" "START" "SCU" "LAMP" "HORN" "PRINTER" "MODULE" "END MODULE" "CALL TEMPLATE" "IF" "FOR") ) | |
(setq MOD5-types '("AI" "AO" "DI" "DO" "AISIM" "DISIM" "ACO" "AIM" "AOT" "DOT" "AP" "AC" "DC" "DT" "DM" "AK" "AG" "AR" "TA")) | |
(setq MOD5-constants '("PFS" "NFS" "IONE" "ZERO")) | |
(setq MOD5-events '("WARN" "REQ" "ALT")) | |
(setq MOD5-functions '("ALM_DI_DO05B" "IFD03B" "ALM_4S_AX04B" "ALM_DX05B" "ALM_RERING03B" "ALM_DI_DO05B" "IS04B")) | |
(setq MOD5-operators '("=" "AND" "OR" "XOR")) | |
(setq MOD5-acmdb '("\[(&A-Z0-9_)\]+" "\[(:A-Z0-9_)\]")) | |
;; generate regex string for each category of keywords | |
(setq MOD5-keywords-regexp (regexp-opt MOD5-keywords 'words)) | |
(setq MOD5-type-regexp (regexp-opt MOD5-types 'words)) | |
(setq MOD5-constant-regexp (regexp-opt MOD5-constants 'words)) | |
(setq MOD5-event-regexp (regexp-opt MOD5-events 'words)) | |
(setq MOD5-functions-regexp (regexp-opt MOD5-functions 'words)) | |
(setq MOD5-operators-regexp (regexp-opt MOD5-operators 'words)) | |
(setq MOD5-acmdb-regexp (regexp-opt MOD5-acmdb 'words)) | |
;; create the list for font-lock. | |
;; each category of keyword is given a particular face | |
(setq MOD5-font-lock-keywords | |
`( | |
(,MOD5-type-regexp . font-lock-type-face) | |
(,MOD5-constant-regexp . font-lock-constant-face) | |
(,MOD5-event-regexp . font-lock-builtin-face) | |
(,MOD5-functions-regexp . font-lock-function-name-face) | |
(,MOD5-keywords-regexp . font-lock-keyword-face) | |
(,MOD5-acmdb-regexp . font-lock-variable-name-face) | |
(,MOD5-operators-regexp . font-lock-negation-char-face) | |
;; note: order above matters, because once colored, that part won't change. | |
;; in general, longer words first | |
)) | |
;;;###autoload | |
(define-derived-mode MOD5-mode fundamental-mode | |
"MOD5 mode" | |
"Major mode for editing MOD5 Dowtran Code…" | |
;; code for syntax highlighting | |
(setq font-lock-defaults '((MOD5-font-lock-keywords)))) | |
;; clear memory. no longer needed | |
(setq MOD5-keywords nil) | |
(setq MOD5-types nil) | |
(setq MOD5-constants nil) | |
(setq MOD5-events nil) | |
(setq MOD5-functions nil) | |
(setq MOD5-acmdb nil) | |
(setq MOD5-operators nil) | |
;; clear memory. no longer needed | |
(setq MOD5-keywords-regexp nil) | |
(setq MOD5-types-regexp nil) | |
(setq MOD5-constants-regexp nil) | |
(setq MOD5-events-regexp nil) | |
(setq MOD5-functions-regexp nil) | |
(setq MOD5-acmdb-regexp nil) | |
(setq MOD5-operators-regexp nil) | |
;; add the mode to the `features' list | |
(provide 'MOD5-mode) | |
;; Local Variables: | |
;; coding: utf-8 | |
;; End: | |
;;; MOD5-mode.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment