forked from MRFaria/epics-substitution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepics-template.el
76 lines (59 loc) · 2.39 KB
/
epics-template.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
;; Copyright 2016 Mauro Faria
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(defvar epics-template-mode-syntax-table nil)
(defvar epics-template-mode-highlights nil)
(defvar device--types '())
(defun find-devices-in-buffer ()
;; Search for macros
(goto-char (point-min))
(let ((devices '()))
(progn
(while (re-search-forward
"device([[:alnum:]]+,[[:alnum:]_]+,[[:alnum:]_]+,\"\\([[:alnum:] /]+\\)\"")
(add-to-list 'devices (match-string-no-properties 1)))
devices)))
(defun get-device-types (file)
(message file)
(with-temp-buffer
(insert-file-contents file)
(goto-char 1)
(message "getting device types")
(find-devices-in-buffer)))
(defun template-get-device-types (dbd-path)
(interactive "fSelect dbd file: ")
(setq-local device--types
(get-device-types dbd-path)))
(defun template-set-device-types ()
(interactive)
(if (not device--types)
(call-interactively 'template-get-device-types))
(completing-read "Select a device DTYP: "
device--types))
(setq epics-template-mode-syntax-table
(let ((synTable (make-syntax-table)))
;; bash style comment: “# …”
(modify-syntax-entry ?# "< b" synTable)
(modify-syntax-entry ?\n "> b" synTable)
(modify-syntax-entry ?$ "'" synTable)
synTable))
(setq epics-template-mode-highlights
'(
;;matches $() or ${} style macros
("\\(\\$([a-zA-Z0-9.=_-]+)\\)\\|\\(\\${[a-zA-Z0-9.=_-]+}\\)" 0 font-lock-variable-name-face t)
("field" . font-lock-keyword-face)
("record" . font-lock-function-name-face)
))
;;;###autoload
(define-derived-mode epics-template-mode fundamental-mode "template"
(setq font-lock-defaults '(epics-template-mode-highlights)))
(provide 'epics-template)