-
Notifications
You must be signed in to change notification settings - Fork 3
/
junos-mode.el
75 lines (63 loc) · 2.74 KB
/
junos-mode.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
75
;;; junos-mode.el --- Major mode for Junos configuration files
;; Copyright (C) 2014 Free Software Foundation, Inc.
;; Author: Vincent Bernat
;; URL: https://github.com/vincentbernat/junos-mode
;; Keywords: extensions
;; Version: 0
;; This file 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 2, or (at your option)
;; any later version.
;; This file 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 GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; Simple mode for Junos-like files
;;; Code:
(unless (fboundp 'setq-local)
(defmacro setq-local (var val)
`(set (make-local-variable ',var) ,val)))
(defvar junos-mode-syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ?- "w" st)
(modify-syntax-entry ?+ "w" st)
(modify-syntax-entry ?_ "w" st)
(modify-syntax-entry ?. "w" st)
(modify-syntax-entry ?/ "w 124" st)
(modify-syntax-entry ?* ". 23b" st)
(modify-syntax-entry ?\# "<" st)
(modify-syntax-entry ?\n ">" st)
(modify-syntax-entry ?\; "." st)
(modify-syntax-entry ?{ "(" st)
(modify-syntax-entry ?} ")" st)
st)
"Syntax table for `junos-mode'.")
(defvar junos-font-lock-keywords
'(("^\\s-*\\(\\(inactive\\|active\\|delete\\|replace\\|protect\\|unprotect\\):\\s-+\\)?\\(\\sw+\\)\\s-*\\(\\(\\sw+\\s-+\\)*\\){\\s-*\\(\\s<.*\\)?$"
(1 'font-lock-keyword-face nil t)
(3 'font-lock-function-name-face)
(4 'font-lock-variable-name-face nil t))
("^\\s-*\\(\\(inactive\\|active\\|delete\\|replace\\|protect\\|unprotect\\):\\s-+\\)?\\(\\sw+\\)"
(1 'font-lock-keyword-face nil t)
(3 'font-lock-type-face))
;; IP
("\\([[:digit:]]+\\.\\)\\{3\\}[[:digit:]]+\\(/[[:digit:]]+\\)?" . 'font-lock-constant-face)
("\\(?:\\(?:[[:xdigit:]]+\\)?:\\)+[[:xdigit:]]*\\(/[[:digit:]]+\\)?" . 'font-lock-constant-face))
"Keyword highlighting specification for `junos-mode'.")
;;;###autoload
(define-derived-mode junos-mode c-mode "Junos"
"A major mode for editing Junos files."
:syntax-table junos-mode-syntax-table
(c-set-offset 'label '+)
(setq-local comment-start "# ")
(setq-local comment-end "")
(setq-local comment-start-skip "#+\\s-*")
(setq-local font-lock-defaults
'(junos-font-lock-keywords)))
(provide 'junos-mode)
;;; junos-mode.el ends here