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