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