Mercurial > emacs
annotate lisp/net/snmp-mode.el @ 84671:f061115a812f
*** empty log message ***
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Thu, 20 Sep 2007 02:53:58 +0000 |
parents | dbbf6366b2a0 |
children | 107ccd98fa12 bdb3fe0ba9fa |
rev | line source |
---|---|
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
28210
diff
changeset
|
1 ;;; snmp-mode.el --- SNMP & SNMPv2 MIB major mode |
28210 | 2 |
74509 | 3 ;; Copyright (C) 1995, 1998, 2001, 2002, 2003, 2004, |
75347 | 4 ;; 2005, 2006, 2007 Free Software Foundation, Inc. |
28210 | 5 |
6 ;; Author: Paul D. Smith <psmith@BayNetworks.com> | |
7 ;; Keywords: data | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
78230
84cf1e2214c5
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
13 ;; the Free Software Foundation; either version 3, or (at your option) |
28210 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
28210 | 25 |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
28210
diff
changeset
|
26 ;;; Commentary: |
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
28210
diff
changeset
|
27 |
28210 | 28 ;; INTRODUCTION |
29 ;; ------------ | |
30 ;; This package provides a major mode for editing SNMP MIBs. It | |
31 ;; provides all the modern Emacs 19 bells and whistles: default | |
32 ;; fontification via font-lock, imenu search functions, etc. | |
33 ;; | |
34 ;; SNMP mode also uses tempo, a textual boilerplate insertion package | |
35 ;; distributed with Emacs, to add in boilerplate SNMP MIB structures. | |
36 ;; See tempo.el for more details about tempo. | |
37 ;; | |
38 ;; If you want to change or add new tempo templates, use the tempo tag | |
39 ;; list `snmp-tempo-tags' (or `snmpv2-tempo-tags'): this list is | |
40 ;; automatically installed when snmp-mode (or snmpv2-mode) is entered. | |
41 ;; | |
42 ;; The SNMPv2 mode in this version has been enhanced thanks to popular | |
43 ;; demand. | |
44 ;; | |
45 ;; I'm very interested in new tempo macros for both v1 and v2, and any | |
46 ;; other suggestions for enhancements (different syntax table items, new | |
47 ;; keybindings, etc.) | |
48 ;; | |
49 ;; | |
50 ;; USAGE | |
51 ;; ----- | |
52 ;; Mostly, use it as you would any other mode. There's a very | |
53 ;; simplistic auto-indent feature; hopefully it'll help more than get in | |
54 ;; your way. For the most part it tries to indent to the same level as | |
55 ;; the previous line. It will try to recognize some very simple tokens | |
56 ;; on the previous line that tell it to use extra indent or outdent. | |
57 ;; | |
58 ;; Templates | |
59 ;; --------- | |
60 ;; To use the Tempo templates, type the Tempo tag (or a unique prefix) | |
61 ;; and use C-c C-i (C-c TAB) to complete it; if you don't have | |
62 ;; tempo-interactive set to nil it will ask you to fill in values. | |
63 ;; Fields with predefined values (SYNTAX, STATUS, etc.) will do | |
64 ;; completing-reads on a list of valid values; use the normal SPC or TAB | |
65 ;; to complete. | |
66 ;; | |
67 ;; Currently the following templates are available: | |
68 ;; | |
69 ;; objectType -- Defines an OBJECT-TYPE macro. | |
70 ;; | |
71 ;; tableType -- Defines both a Table and Entry OBJECT-TYPE, and a | |
72 ;; SEQUENCE for the ASN.1 Entry definition. | |
73 ;; | |
74 ;; Once the template is done, you can use C-cC-f and C-cC-b to move back | |
75 ;; and forth between the Tempo sequence points to fill in the rest of | |
76 ;; the information. | |
77 ;; | |
78 ;; Font Lock | |
79 ;; ------------ | |
80 ;; | |
81 ;; If you want font-lock in your MIB buffers, add this: | |
82 ;; | |
83 ;; (add-hook 'snmp-common-mode-hook 'turn-on-font-lock) | |
84 ;; | |
85 ;; Enabling global-font-lock-mode is also sufficient. | |
86 ;; | |
87 | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
28210
diff
changeset
|
88 ;;; Code: |
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
28210
diff
changeset
|
89 |
43701
5f79f8210ef4
Require tempo when compiling to prevent warnings. Update copyright notice.
Pavel Janík <Pavel@Janik.cz>
parents:
38436
diff
changeset
|
90 (eval-when-compile |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
91 (require 'cl) |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
92 (require 'imenu) ; Need this stuff when compiling for imenu macros, etc. |
43701
5f79f8210ef4
Require tempo when compiling to prevent warnings. Update copyright notice.
Pavel Janík <Pavel@Janik.cz>
parents:
38436
diff
changeset
|
93 (require 'tempo)) |
5f79f8210ef4
Require tempo when compiling to prevent warnings. Update copyright notice.
Pavel Janík <Pavel@Janik.cz>
parents:
38436
diff
changeset
|
94 |
28210 | 95 ;;;---------------------------------------------------------------------------- |
96 ;; | |
97 ;; Customize these: | |
98 ;; | |
99 ;;;---------------------------------------------------------------------------- | |
100 | |
101 (defgroup snmp nil | |
102 "Mode for editing SNMP MIB files." | |
103 :group 'data | |
104 :version "20.4") | |
105 | |
106 (defcustom snmp-special-indent t | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
107 "If non-nil, use a simple heuristic to try to guess the right indentation. |
28210 | 108 If nil, then no special indentation is attempted." |
109 :type 'boolean | |
110 :group 'snmp) | |
111 | |
112 (defcustom snmp-indent-level 4 | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
113 "Indentation level for SNMP MIBs." |
28210 | 114 :type 'integer |
115 :group 'snmp) | |
116 | |
117 (defcustom snmp-tab-always-indent nil | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
118 "Non-nil means TAB should always reindent the current line. |
28210 | 119 A value of nil means reindent if point is within the initial line indentation; |
120 otherwise insert a TAB." | |
121 :type 'boolean | |
122 :group 'snmp) | |
123 | |
124 (defcustom snmp-completion-ignore-case t | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
125 "Non-nil means that case differences are ignored during completion. |
28210 | 126 A value of nil means that case is significant. |
127 This is used during Tempo template completion." | |
128 :type 'boolean | |
129 :group 'snmp) | |
130 | |
131 (defcustom snmp-common-mode-hook nil | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
132 "Hook(s) evaluated when a buffer enters either SNMP or SNMPv2 mode." |
28210 | 133 :type 'hook |
134 :group 'snmp) | |
135 | |
136 (defcustom snmp-mode-hook nil | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
137 "Hook(s) evaluated when a buffer enters SNMP mode." |
28210 | 138 :type 'hook |
139 :group 'snmp) | |
140 | |
141 (defcustom snmpv2-mode-hook nil | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
142 "Hook(s) evaluated when a buffer enters SNMPv2 mode." |
28210 | 143 :type 'hook |
144 :group 'snmp) | |
145 | |
146 (defvar snmp-tempo-tags nil | |
147 "*Tempo tags for SNMP mode.") | |
148 | |
149 (defvar snmpv2-tempo-tags nil | |
150 "*Tempo tags for SNMPv2 mode.") | |
151 | |
152 | |
153 ;; Enable fontification for SNMP MIBs | |
154 ;; | |
155 | |
156 ;; These are pretty basic fontifications. Note we assume these macros | |
157 ;; are first on a line (except whitespace), to speed up fontification. | |
158 ;; | |
159 (defvar snmp-font-lock-keywords-1 | |
160 (list | |
161 ;; OBJECT-TYPE, TRAP-TYPE, and OBJECT-IDENTIFIER macros | |
162 '("^[ \t]*\\([a-z][-a-zA-Z0-9]+\\)[ \t]+\\(\\(MODULE-\\(COMPLIANCE\\|IDENTITY\\)\\|OBJECT-\\(COMPLIANCE\\|GROUP\\|IDENTITY\\|TYPE\\)\\|TRAP-\\(GROUP\\|TYPE\\)\\)\\|\\(OBJECT\\)[ \t]+\\(IDENTIFIER\\)[ \t]*::=\\)" | |
163 (1 font-lock-variable-name-face) (3 font-lock-keyword-face nil t) | |
164 (7 font-lock-keyword-face nil t) (8 font-lock-keyword-face nil t)) | |
165 | |
166 ;; DEFINITIONS clause | |
167 '("^[ \t]*\\([A-Z][-a-zA-Z0-9]+\\)[ \t]+\\(DEFINITIONS\\)[ \t]*::=" | |
168 (1 font-lock-function-name-face) (2 font-lock-keyword-face)) | |
169 ) | |
170 "Basic SNMP MIB mode expression highlighting.") | |
171 | |
172 (defvar snmp-font-lock-keywords-2 | |
173 (append | |
174 '(("ACCESS\\|BEGIN\\|DE\\(FVAL\\|SCRIPTION\\)\\|END\\|FROM\\|I\\(MPORTS\\|NDEX\\)\\|S\\(TATUS\\|YNTAX\\)" | |
175 (0 font-lock-keyword-face))) | |
176 snmp-font-lock-keywords-1) | |
177 "Medium SNMP MIB mode expression highlighting.") | |
178 | |
179 (defvar snmp-font-lock-keywords-3 | |
180 (append | |
181 '(("\\([^\n]+\\)[ \t]+::=[ \t]+\\(SEQUENCE\\)[ \t]+{" | |
182 (1 font-lock-reference-face) (2 font-lock-keyword-face)) | |
183 ("::=[ \t]*{[ \t]*\\([a-z0-9].*[ \t]+\\)?\\([0-9]+\\)[ \t]*}" | |
184 (1 font-lock-reference-face nil t) (2 font-lock-variable-name-face))) | |
185 snmp-font-lock-keywords-2) | |
186 "Gaudy SNMP MIB mode expression highlighting.") | |
187 | |
188 (defvar snmp-font-lock-keywords snmp-font-lock-keywords-1 | |
189 "Default SNMP MIB mode expression highlighting.") | |
190 | |
191 | |
192 ;; These lists are used for the completion capabilities in the tempo | |
193 ;; templates. | |
194 ;; | |
195 | |
196 (defvar snmp-mode-syntax-list nil | |
197 "Predefined types for SYNTAX clauses.") | |
198 | |
199 (defvar snmp-rfc1155-types | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
200 '("INTEGER" "OCTET STRING" "OBJECT IDENTIFIER" "NULL" "IpAddress" |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
201 "NetworkAddress" "Counter" "Gauge" "TimeTicks" "Opaque") |
28210 | 202 "Types from RFC 1155 v1 SMI.") |
203 | |
204 (defvar snmp-rfc1213-types | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
205 '("DisplayString") |
28210 | 206 "Types from RFC 1213 MIB-II.") |
207 | |
208 (defvar snmp-rfc1902-types | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
209 '("INTEGER" "OCTET STRING" "OBJECT IDENTIFIER" "Integer32" |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
210 "IpAddress" "Counter32" "Gauge32" "Unsigned32" "TimeTicks" |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
211 "Opaque" "Counter64") |
28210 | 212 "Types from RFC 1902 v2 SMI.") |
213 | |
214 (defvar snmp-rfc1903-types | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
215 '("DisplayString" "PhysAddress" "MacAddress" "TruthValue" |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
216 "TestAndIncr" "AutonomousType" "InstancePointer" |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
217 "VariablePointer" "RowPointer" "RowStatus" "TimeStamp" |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
218 "TimeInterval" "DateAndTime" "StorageType" "TDomain" |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
219 "TAddress") |
28210 | 220 "Types from RFC 1903 Textual Conventions.") |
221 | |
222 | |
223 (defvar snmp-mode-access-list nil | |
224 "Predefined values for ACCESS clauses.") | |
225 | |
226 (defvar snmp-rfc1155-access | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
227 '("read-only" "read-write" "write-only" "not-accessible") |
28210 | 228 "ACCESS values from RFC 1155 v1 SMI.") |
229 | |
230 (defvar snmp-rfc1902-access | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
231 '("read-only" "read-write" "read-create" "not-accessible" |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
232 "accessible-for-notify") |
28210 | 233 "ACCESS values from RFC 1155 v1 SMI.") |
234 | |
235 | |
236 (defvar snmp-mode-status-list nil | |
237 "Predefined values for STATUS clauses.") | |
238 | |
239 (defvar snmp-rfc1212-status | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
240 '("mandatory" "obsolete" "deprecated") |
28210 | 241 "STATUS values from RFC 1212 v1 SMI.") |
242 | |
243 (defvar snmp-rfc1902-status | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
244 '("current" "obsolete" "deprecated") |
28210 | 245 "STATUS values from RFC 1902 v2 SMI.") |
246 | |
247 | |
248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
249 ;;;---------------------------------------------------------------------------- | |
250 ;; | |
251 ;; Nothing to customize below here. | |
252 ;; | |
253 ;;;---------------------------------------------------------------------------- | |
254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
255 | |
256 | |
257 ;; Create abbrev table for SNMP MIB mode | |
258 ;; | |
259 (defvar snmp-mode-abbrev-table nil | |
260 "Abbrev table in use in SNMP mode.") | |
261 (define-abbrev-table 'snmp-mode-abbrev-table ()) | |
262 | |
263 | |
264 ;; Create abbrev table for SNMPv2 mode | |
265 ;; | |
266 (defvar snmpv2-mode-abbrev-table nil | |
267 "Abbrev table in use in SNMPv2 mode.") | |
268 (define-abbrev-table 'snmpv2-mode-abbrev-table ()) | |
269 | |
270 | |
271 ;; Set up our keymap | |
272 ;; | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
273 (defvar snmp-mode-map |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
274 (let ((map (make-sparse-keymap))) |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
275 (define-key map "\177" 'backward-delete-char-untabify) |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
276 (define-key map "\C-c\C-i" 'tempo-complete-tag) |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
277 (define-key map "\C-c\C-f" 'tempo-forward-mark) |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
278 (define-key map "\C-c\C-b" 'tempo-backward-mark) |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
279 map) |
28210 | 280 "Keymap used in SNMP mode.") |
281 | |
282 | |
283 ;; Set up our syntax table | |
284 ;; | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
285 (defvar snmp-mode-syntax-table |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
286 (let ((st (make-syntax-table))) |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
287 (modify-syntax-entry ?\\ "\\" st) |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
288 (modify-syntax-entry ?- "_ 1234" st) |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
289 (modify-syntax-entry ?\n ">" st) |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
290 (modify-syntax-entry ?\^m ">" st) |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
291 (modify-syntax-entry ?_ "." st) |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
292 (modify-syntax-entry ?: "." st) |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
293 (modify-syntax-entry ?= "." st) |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
294 st) |
28210 | 295 "Syntax table used for buffers in SNMP mode.") |
296 | |
297 ;; Set up the stuff that's common between snmp-mode and snmpv2-mode | |
298 ;; | |
299 (defun snmp-common-mode (name mode abbrev font-keywords imenu-index tempo-tags) | |
300 (kill-all-local-variables) | |
301 | |
302 ;; Become the current major mode | |
303 (setq mode-name name) | |
304 (setq major-mode mode) | |
305 | |
306 ;; Activate keymap, syntax table, and abbrev table | |
307 (use-local-map snmp-mode-map) | |
308 (set-syntax-table snmp-mode-syntax-table) | |
309 (setq local-abbrev-table abbrev) | |
310 | |
311 ;; Set up paragraphs (?) | |
312 (make-local-variable 'paragraph-start) | |
313 (setq paragraph-start (concat "$\\|" page-delimiter)) | |
314 (make-local-variable 'paragraph-separate) | |
315 (setq paragraph-separate paragraph-start) | |
316 (make-local-variable 'paragraph-ignore-fill-prefix) | |
317 (setq paragraph-ignore-fill-prefix t) | |
318 | |
319 ;; Set up comments | |
320 (make-local-variable 'comment-start) | |
321 (setq comment-start "-- ") | |
322 (make-local-variable 'comment-start-skip) | |
323 (setq comment-start-skip "--+[ \t]*") | |
324 (make-local-variable 'comment-column) | |
325 (setq comment-column 40) | |
326 (make-local-variable 'parse-sexp-ignore-comments) | |
327 (setq parse-sexp-ignore-comments t) | |
328 | |
329 ;; Set up indentation | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
330 (if snmp-special-indent |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
331 (set (make-local-variable 'indent-line-function) 'snmp-indent-line)) |
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
332 (set (make-local-variable 'tab-always-indent) snmp-tab-always-indent) |
28210 | 333 |
334 ;; Font Lock | |
335 (make-local-variable 'font-lock-defaults) | |
336 (setq font-lock-defaults (cons font-keywords '(nil nil ((?- . "w 1234"))))) | |
337 | |
338 ;; Imenu | |
339 (make-local-variable 'imenu-create-index-function) | |
340 (setq imenu-create-index-function imenu-index) | |
341 | |
342 ;; Tempo | |
343 (tempo-use-tag-list tempo-tags) | |
344 (make-local-variable 'tempo-match-finder) | |
345 (setq tempo-match-finder "\\b\\(.+\\)\\=") | |
346 (make-local-variable 'tempo-interactive) | |
347 (setq tempo-interactive t) | |
348 | |
349 ;; Miscellaneous customization | |
350 (make-local-variable 'require-final-newline) | |
59236
11818a96df38
(snmp-common-mode): Use mode-require-final-newline.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
351 (setq require-final-newline mode-require-final-newline)) |
28210 | 352 |
353 | |
354 ;; SNMPv1 MIB Editing Mode. | |
355 ;; | |
356 ;;;###autoload | |
357 (defun snmp-mode () | |
358 "Major mode for editing SNMP MIBs. | |
359 Expression and list commands understand all C brackets. | |
360 Tab indents for C code. | |
361 Comments start with -- and end with newline or another --. | |
362 Delete converts tabs to spaces as it moves back. | |
363 \\{snmp-mode-map} | |
364 Turning on snmp-mode runs the hooks in `snmp-common-mode-hook', then | |
365 `snmp-mode-hook'." | |
366 (interactive) | |
367 | |
368 (snmp-common-mode "SNMP" 'snmp-mode | |
369 snmp-mode-abbrev-table | |
370 '(snmp-font-lock-keywords | |
371 snmp-font-lock-keywords-1 | |
372 snmp-font-lock-keywords-2 | |
373 snmp-font-lock-keywords-3) | |
374 'snmp-mode-imenu-create-index | |
375 'snmp-tempo-tags) | |
376 | |
377 ;; Completion lists | |
378 (make-local-variable 'snmp-mode-syntax-list) | |
379 (setq snmp-mode-syntax-list (append snmp-rfc1155-types | |
380 snmp-rfc1213-types | |
381 snmp-mode-syntax-list)) | |
382 (make-local-variable 'snmp-mode-access-list) | |
383 (setq snmp-mode-access-list snmp-rfc1155-access) | |
384 (make-local-variable 'snmp-mode-status-list) | |
385 (setq snmp-mode-status-list snmp-rfc1212-status) | |
386 | |
387 ;; Run hooks | |
62768 | 388 (run-mode-hooks 'snmp-common-mode-hook 'snmp-mode-hook)) |
28210 | 389 |
390 | |
391 ;;;###autoload | |
392 (defun snmpv2-mode () | |
393 "Major mode for editing SNMPv2 MIBs. | |
394 Expression and list commands understand all C brackets. | |
395 Tab indents for C code. | |
396 Comments start with -- and end with newline or another --. | |
397 Delete converts tabs to spaces as it moves back. | |
398 \\{snmp-mode-map} | |
399 Turning on snmp-mode runs the hooks in `snmp-common-mode-hook', | |
400 then `snmpv2-mode-hook'." | |
401 (interactive) | |
402 | |
403 (snmp-common-mode "SNMPv2" 'snmpv2-mode | |
404 snmpv2-mode-abbrev-table | |
405 '(snmp-font-lock-keywords | |
406 snmp-font-lock-keywords-1 | |
407 snmp-font-lock-keywords-2 | |
408 snmp-font-lock-keywords-3) | |
409 'snmp-mode-imenu-create-index | |
410 'snmpv2-tempo-tags) | |
411 | |
412 ;; Completion lists | |
413 (make-local-variable 'snmp-mode-syntax-list) | |
414 (setq snmp-mode-syntax-list (append snmp-rfc1902-types | |
415 snmp-rfc1903-types | |
416 snmp-mode-syntax-list)) | |
417 (make-local-variable 'snmp-mode-access-list) | |
418 (setq snmp-mode-access-list snmp-rfc1902-access) | |
419 (make-local-variable 'snmp-mode-status-list) | |
420 (setq snmp-mode-status-list snmp-rfc1902-status) | |
421 | |
422 ;; Run hooks | |
62768 | 423 (run-mode-hooks 'snmp-common-mode-hook 'snmpv2-mode-hook)) |
28210 | 424 |
425 | |
426 ;;;---------------------------------------------------------------------------- | |
427 ;; | |
428 ;; Indentation Setup | |
429 ;; | |
430 ;;;---------------------------------------------------------------------------- | |
431 | |
432 (defvar snmp-macro-open | |
433 "[a-zA-Z][-a-zA-Z0-9]*[ \t]*\\(OBJECT\\|TRAP\\)-\\(TYPE\\|GROUP\\)\ | |
434 \\|DESCRIPTION\\|IMPORTS\\|MODULE\\(-IDENTITY\\|-COMPLIANCE\\)\ | |
435 \\|.*::=[ \t]*\\(BEGIN\\|TEXTUAL-CONVENTION\\)[ \t]*$") | |
436 | |
437 (defvar snmp-macro-close | |
438 "::=[ \t]*{\\|\\(END\\|.*[;\"]\\)[ \t]*$") | |
439 | |
440 (defun snmp-calculate-indent () | |
441 "Calculate the current line indentation in SNMP MIB code. | |
442 | |
443 We use a very simple scheme: if the previous non-empty line was a \"macro | |
444 open\" string, add `snmp-indent-level' to it. If it was a \"macro close\" | |
445 string, subtract `snmp-indent-level'. Otherwise, use the same indentation | |
446 as the previous non-empty line. Note comments are considered empty | |
447 lines for the purposes of this function." | |
448 (let ((empty (concat "\\([ \t]*\\)\\(" comment-start-skip "\\|$\\)")) | |
449 (case-fold-search nil)) ; keywords must be in uppercase | |
450 (save-excursion | |
451 (while (and (>= (forward-line -1) 0) | |
452 (looking-at empty))) | |
453 (skip-chars-forward " \t") | |
454 (+ (current-column) | |
455 ;; Are we looking at a macro open string? If so, add more. | |
456 (cond ((looking-at snmp-macro-open) | |
457 snmp-indent-level) | |
458 ;; macro close string? If so, remove some. | |
459 ((looking-at snmp-macro-close) | |
460 (- snmp-indent-level)) | |
461 ;; Neither; just stay here. | |
462 (t 0)))))) | |
463 | |
464 (defun snmp-indent-line () | |
465 "Indent current line as SNMP MIB code." | |
466 (let ((indent (snmp-calculate-indent)) | |
467 (pos (- (point-max) (point))) | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
468 shift-amt beg) |
28210 | 469 (beginning-of-line) |
470 (setq beg (point)) | |
471 (skip-chars-forward " \t") | |
472 (setq shift-amt (- indent (current-column))) | |
473 (if (zerop shift-amt) | |
474 nil | |
475 (delete-region beg (point)) | |
476 (indent-to indent)) | |
477 ;; If initial point was within line's indentation, | |
478 ;; position after the indentation. Else stay at same point in text. | |
479 (if (> (- (point-max) pos) (point)) | |
480 (goto-char (- (point-max) pos))))) | |
481 | |
482 | |
483 ;;;---------------------------------------------------------------------------- | |
484 ;; | |
485 ;; Imenu Setup | |
486 ;; | |
487 ;;;---------------------------------------------------------------------------- | |
488 | |
489 (defvar snmp-clause-regexp | |
490 "^[ \t]*\\([a-zA-Z][-a-zA-Z0-9]*\\)[ \t\n]*\ | |
491 \\(TRAP-TYPE\\|::=\\|OBJECT\\(-TYPE[ \t\n]+SYNTAX\\|[ \t\n]+IDENTIFIER[ \t\n]*::=\\)\\)") | |
492 | |
493 (defun snmp-mode-imenu-create-index () | |
494 (let ((index-alist '()) | |
495 (index-oid-alist '()) | |
496 (index-tc-alist '()) | |
497 (index-table-alist '()) | |
498 (index-trap-alist '()) | |
499 (case-fold-search nil) ; keywords must be uppercase | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
500 prev-pos token end) |
28210 | 501 (goto-char (point-min)) |
502 (imenu-progress-message prev-pos 0) | |
503 ;; Search for a useful MIB item (that's not in a comment) | |
504 (save-match-data | |
505 (while (re-search-forward snmp-clause-regexp nil t) | |
506 (imenu-progress-message prev-pos) | |
507 (setq | |
508 end (match-end 0) | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
509 token (cons (match-string 1) |
28210 | 510 (set-marker (make-marker) (match-beginning 1)))) |
511 (goto-char (match-beginning 2)) | |
512 (cond ((looking-at "OBJECT-TYPE[ \t\n]+SYNTAX") | |
513 (push token index-alist)) | |
514 ((looking-at "OBJECT[ \t\n]+IDENTIFIER[ \t\n]*::=") | |
515 (push token index-oid-alist)) | |
516 ((looking-at "::=[ \t\n]*SEQUENCE[ \t\n]*{") | |
517 (push token index-table-alist)) | |
518 ((looking-at "TRAP-TYPE") | |
519 (push token index-trap-alist)) | |
520 ((looking-at "::=") | |
521 (push token index-tc-alist))) | |
522 (goto-char end))) | |
523 ;; Create the menu | |
524 (imenu-progress-message prev-pos 100) | |
525 (setq index-alist (nreverse index-alist)) | |
526 (and index-tc-alist | |
527 (push (cons "Textual Conventions" (nreverse index-tc-alist)) | |
528 index-alist)) | |
529 (and index-trap-alist | |
530 (push (cons "Traps" (nreverse index-trap-alist)) | |
531 index-alist)) | |
532 (and index-table-alist | |
533 (push (cons "Tables" (nreverse index-table-alist)) | |
534 index-alist)) | |
535 (and index-oid-alist | |
536 (push (cons "Object IDs" (nreverse index-oid-alist)) | |
537 index-alist)) | |
538 index-alist)) | |
539 | |
540 | |
541 ;;;---------------------------------------------------------------------------- | |
542 ;; | |
543 ;; Tempo Setup | |
544 ;; | |
545 ;;;---------------------------------------------------------------------------- | |
546 | |
547 (require 'tempo) | |
548 | |
549 ;; Perform a completing-read with info given | |
550 ;; | |
551 (defun snmp-completing-read (prompt table &optional pred require init hist) | |
552 "Read from the minibuffer, with completion. | |
553 Like `completing-read', but the variable `snmp-completion-ignore-case' | |
554 controls whether case is significant." | |
555 (let ((completion-ignore-case snmp-completion-ignore-case)) | |
556 (completing-read prompt table pred require init hist))) | |
557 | |
558 ;; OBJECT-TYPE macro template | |
559 ;; | |
560 (tempo-define-template "snmp-object-type" | |
561 '(> (P "Object Label: ") " OBJECT-TYPE" n> | |
562 "SYNTAX " | |
563 (if tempo-interactive | |
564 (snmp-completing-read "Syntax: " snmp-mode-syntax-list nil nil) | |
565 p) n> | |
566 "ACCESS " | |
567 (if tempo-interactive | |
568 (snmp-completing-read "Access: " snmp-mode-access-list nil t) | |
569 p) n> | |
570 "STATUS " | |
571 (if tempo-interactive | |
572 (snmp-completing-read "Status: " snmp-mode-status-list nil t) | |
573 p) n> | |
574 "DESCRIPTION" n> "\"" p "\"" n> | |
575 (P "Default Value: " defval t) | |
576 (if (string= "" (tempo-lookup-named 'defval)) | |
577 nil | |
578 '(l "DEFVAL { " (s defval) " }" n>)) | |
579 "::= { " (p "OID: ") " }" n) | |
580 "objectType" | |
581 "Insert an OBJECT-TYPE macro." | |
582 'snmp-tempo-tags) | |
583 | |
584 ;; Table macro template | |
585 ;; | |
586 (tempo-define-template "snmp-table-type" | |
587 ;; First the table OBJECT-TYPE | |
588 '(> (P "Table Name: " table) | |
589 (P "Entry Name: " entry t) | |
590 (let* ((entry (tempo-lookup-named 'entry)) | |
591 (seq (copy-sequence entry))) | |
592 (aset entry 0 (downcase (aref entry 0))) | |
593 (aset seq 0 (upcase (aref seq 0))) | |
594 (tempo-save-named 'obj-entry entry) | |
595 (tempo-save-named 'seq-entry seq) | |
596 nil) | |
597 " OBJECT-TYPE" n> | |
598 "SYNTAX SEQUENCE OF " | |
599 (s seq-entry) n> | |
600 "ACCESS not-accessible" n> | |
601 "STATUS mandatory" n> | |
602 "DESCRIPTION" n> "\"" p "\"" n> | |
603 "::= { " (p "OID: ") " }" n n> | |
604 ;; Next the row OBJECT-TYPE | |
605 (s obj-entry) " OBJECT-TYPE" n> | |
606 "SYNTAX " (s seq-entry) n> | |
607 "ACCESS not-accessible" n> | |
608 "STATUS mandatory" n> | |
609 "DESCRIPTION" n> "\"" p "\"" n> | |
610 "INDEX { " (p "Index List: ") " }" n> | |
611 "::= {" (s table) " 1 }" n n> | |
612 ;; Finally the SEQUENCE type | |
613 (s seq-entry) " ::= SEQUENCE {" n> p n> "}" n) | |
614 "tableType" | |
615 "Insert an SNMP table." | |
616 'snmp-tempo-tags) | |
617 | |
618 | |
619 ;; v2 SMI OBJECT-TYPE macro template | |
620 ;; | |
621 (tempo-define-template "snmpv2-object-type" | |
622 '(> (P "Object Label: ") " OBJECT-TYPE" n> | |
623 "SYNTAX " | |
624 (if tempo-interactive | |
625 (snmp-completing-read "Syntax: " snmp-mode-syntax-list nil nil) | |
626 p) n> | |
627 "MAX-ACCESS " | |
628 (if tempo-interactive | |
629 (snmp-completing-read "Max Access: " snmp-mode-access-list nil t) | |
630 p) n> | |
631 "STATUS " | |
632 (if tempo-interactive | |
633 (snmp-completing-read "Status: " snmp-mode-status-list nil t) | |
634 p) n> | |
635 "DESCRIPTION" n> "\"" p "\"" n> | |
636 (P "Default Value: " defval t) | |
637 (if (string= "" (tempo-lookup-named 'defval)) | |
638 nil | |
639 '(l "DEFVAL { " (s defval) " }" n>)) | |
640 "::= { " (p "OID: ") " }" n) | |
641 "objectType" | |
642 "Insert an v2 SMI OBJECT-TYPE macro." | |
643 'snmpv2-tempo-tags) | |
644 | |
645 ;; v2 SMI Table macro template | |
646 ;; | |
647 (tempo-define-template "snmpv2-table-type" | |
648 ;; First the table OBJECT-TYPE | |
649 '(> (P "Table Name: " table) | |
650 (P "Entry Name: " entry t) | |
651 (let* ((entry (tempo-lookup-named 'entry)) | |
652 (seq (copy-sequence entry))) | |
653 (aset entry 0 (downcase (aref entry 0))) | |
654 (aset seq 0 (upcase (aref seq 0))) | |
655 (tempo-save-named 'obj-entry entry) | |
656 (tempo-save-named 'seq-entry seq) | |
657 nil) | |
658 " OBJECT-TYPE" n> | |
659 "SYNTAX SEQUENCE OF " | |
660 (s seq-entry) n> | |
661 "MAX-ACCESS not-accessible" n> | |
662 "STATUS current" n> | |
663 "DESCRIPTION" n> "\"" p "\"" n> | |
664 "::= { " (p "OID: ") " }" n n> | |
665 ;; Next the row OBJECT-TYPE | |
666 (s obj-entry) " OBJECT-TYPE" n> | |
667 "SYNTAX " (s seq-entry) n> | |
668 "MAX-ACCESS not-accessible" n> | |
669 "STATUS current" n> | |
670 "DESCRIPTION" n> "\"" p "\"" n> | |
671 "INDEX { " (p "Index List: ") " }" n> | |
672 "::= { " (s table) " 1 }" n n> | |
673 ;; Finally the SEQUENCE type | |
674 (s seq-entry) " ::= SEQUENCE {" n> p n> "}" n) | |
675 "tableType" | |
676 "Insert an v2 SMI SNMP table." | |
677 'snmpv2-tempo-tags) | |
678 | |
679 ;; v2 SMI TEXTUAL-CONVENTION macro template | |
680 ;; | |
681 (tempo-define-template "snmpv2-textual-convention" | |
682 '(> (P "Texual Convention Type: ") " ::= TEXTUAL-CONVENTION" n> | |
683 "STATUS " | |
684 (if tempo-interactive | |
685 (snmp-completing-read "Status: " snmp-mode-status-list nil t) | |
686 p) n> | |
687 "DESCRIPTION" n> "\"" p "\"" n> | |
688 "SYNTAX " | |
689 (if tempo-interactive | |
690 (snmp-completing-read "Syntax: " snmp-mode-syntax-list nil nil) | |
691 p) n> ) | |
692 "textualConvention" | |
693 "Insert an v2 SMI TEXTUAL-CONVENTION macro." | |
694 'snmpv2-tempo-tags) | |
695 | |
696 | |
697 (provide 'snmp-mode) | |
698 | |
84653
dbbf6366b2a0
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78230
diff
changeset
|
699 ;; arch-tag: eb6cc0f9-1e47-4023-8625-bc9aae6c3527 |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
28210
diff
changeset
|
700 ;;; snmp-mode.el ends here |