("Romanian"): Remove unibyte-syntax property.
[emacs.git] / lisp / net / snmp-mode.el
blob227eccd4757972329479ce326bd1e92963f8fdb4
1 ;;; snmp-mode.el --- SNMP & SNMPv2 MIB major mode
3 ;; Copyright (C) 1995,1998 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 2, or (at your option)
13 ;; 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; 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.
25 ;;; Commentary:
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.
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.
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.
41 ;; The SNMPv2 mode in this version has been enhanced thanks to popular
42 ;; demand.
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.)
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.
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.
66 ;; Currently the following templates are available:
68 ;; objectType -- Defines an OBJECT-TYPE macro.
70 ;; tableType -- Defines both a Table and Entry OBJECT-TYPE, and a
71 ;; SEQUENCE for the ASN.1 Entry definition.
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.
77 ;; Font Lock
78 ;; ------------
80 ;; If you want font-lock in your MIB buffers, add this:
82 ;; (add-hook 'snmp-common-mode-hook 'turn-on-font-lock)
84 ;; Enabling global-font-lock-mode is also sufficient.
87 ;;; Code:
89 ;;;----------------------------------------------------------------------------
91 ;; Customize these:
93 ;;;----------------------------------------------------------------------------
95 (defgroup snmp nil
96 "Mode for editing SNMP MIB files."
97 :group 'data
98 :version "20.4")
100 (defcustom snmp-special-indent t
101 "*If non-nil, use a simple heuristic to try to guess the right indentation.
102 If nil, then no special indentation is attempted."
103 :type 'boolean
104 :group 'snmp)
106 (defcustom snmp-indent-level 4
107 "*Indentation level for SNMP MIBs."
108 :type 'integer
109 :group 'snmp)
111 (defcustom snmp-tab-always-indent nil
112 "*Non-nil means TAB should always reindent the current line.
113 A value of nil means reindent if point is within the initial line indentation;
114 otherwise insert a TAB."
115 :type 'boolean
116 :group 'snmp)
118 (defcustom snmp-completion-ignore-case t
119 "*Non-nil means that case differences are ignored during completion.
120 A value of nil means that case is significant.
121 This is used during Tempo template completion."
122 :type 'boolean
123 :group 'snmp)
125 (defcustom snmp-common-mode-hook nil
126 "*Hook(s) evaluated when a buffer enters either SNMP or SNMPv2 mode."
127 :type 'hook
128 :group 'snmp)
130 (defcustom snmp-mode-hook nil
131 "*Hook(s) evaluated when a buffer enters SNMP mode."
132 :type 'hook
133 :group 'snmp)
135 (defcustom snmpv2-mode-hook nil
136 "*Hook(s) evaluated when a buffer enters SNMPv2 mode."
137 :type 'hook
138 :group 'snmp)
140 (defvar snmp-tempo-tags nil
141 "*Tempo tags for SNMP mode.")
143 (defvar snmpv2-tempo-tags nil
144 "*Tempo tags for SNMPv2 mode.")
147 ;; Enable fontification for SNMP MIBs
150 ;; These are pretty basic fontifications. Note we assume these macros
151 ;; are first on a line (except whitespace), to speed up fontification.
153 (defvar snmp-font-lock-keywords-1
154 (list
155 ;; OBJECT-TYPE, TRAP-TYPE, and OBJECT-IDENTIFIER macros
156 '("^[ \t]*\\([a-z][-a-zA-Z0-9]+\\)[ \t]+\\(\\(MODULE-\\(COMPLIANCE\\|IDENTITY\\)\\|OBJECT-\\(COMPLIANCE\\|GROUP\\|IDENTITY\\|TYPE\\)\\|TRAP-\\(GROUP\\|TYPE\\)\\)\\|\\(OBJECT\\)[ \t]+\\(IDENTIFIER\\)[ \t]*::=\\)"
157 (1 font-lock-variable-name-face) (3 font-lock-keyword-face nil t)
158 (7 font-lock-keyword-face nil t) (8 font-lock-keyword-face nil t))
160 ;; DEFINITIONS clause
161 '("^[ \t]*\\([A-Z][-a-zA-Z0-9]+\\)[ \t]+\\(DEFINITIONS\\)[ \t]*::="
162 (1 font-lock-function-name-face) (2 font-lock-keyword-face))
164 "Basic SNMP MIB mode expression highlighting.")
166 (defvar snmp-font-lock-keywords-2
167 (append
168 '(("ACCESS\\|BEGIN\\|DE\\(FVAL\\|SCRIPTION\\)\\|END\\|FROM\\|I\\(MPORTS\\|NDEX\\)\\|S\\(TATUS\\|YNTAX\\)"
169 (0 font-lock-keyword-face)))
170 snmp-font-lock-keywords-1)
171 "Medium SNMP MIB mode expression highlighting.")
173 (defvar snmp-font-lock-keywords-3
174 (append
175 '(("\\([^\n]+\\)[ \t]+::=[ \t]+\\(SEQUENCE\\)[ \t]+{"
176 (1 font-lock-reference-face) (2 font-lock-keyword-face))
177 ("::=[ \t]*{[ \t]*\\([a-z0-9].*[ \t]+\\)?\\([0-9]+\\)[ \t]*}"
178 (1 font-lock-reference-face nil t) (2 font-lock-variable-name-face)))
179 snmp-font-lock-keywords-2)
180 "Gaudy SNMP MIB mode expression highlighting.")
182 (defvar snmp-font-lock-keywords snmp-font-lock-keywords-1
183 "Default SNMP MIB mode expression highlighting.")
186 ;; These lists are used for the completion capabilities in the tempo
187 ;; templates.
190 (defvar snmp-mode-syntax-list nil
191 "Predefined types for SYNTAX clauses.")
193 (defvar snmp-rfc1155-types
194 '(("INTEGER") ("OCTET STRING") ("OBJECT IDENTIFIER") ("NULL") ("IpAddress")
195 ("NetworkAddress") ("Counter") ("Gauge") ("TimeTicks") ("Opaque"))
196 "Types from RFC 1155 v1 SMI.")
198 (defvar snmp-rfc1213-types
199 '(("DisplayString"))
200 "Types from RFC 1213 MIB-II.")
202 (defvar snmp-rfc1902-types
203 '(("INTEGER") ("OCTET STRING") ("OBJECT IDENTIFIER") ("Integer32")
204 ("IpAddress") ("Counter32") ("Gauge32") ("Unsigned32") ("TimeTicks")
205 ("Opaque") ("Counter64"))
206 "Types from RFC 1902 v2 SMI.")
208 (defvar snmp-rfc1903-types
209 '(("DisplayString") ("PhysAddress") ("MacAddress") ("TruthValue")
210 ("TestAndIncr") ("AutonomousType") ("InstancePointer")
211 ("VariablePointer") ("RowPointer") ("RowStatus") ("TimeStamp")
212 ("TimeInterval") ("DateAndTime") ("StorageType") ("TDomain")
213 ("TAddress"))
214 "Types from RFC 1903 Textual Conventions.")
217 (defvar snmp-mode-access-list nil
218 "Predefined values for ACCESS clauses.")
220 (defvar snmp-rfc1155-access
221 '(("read-only") ("read-write") ("write-only") ("not-accessible"))
222 "ACCESS values from RFC 1155 v1 SMI.")
224 (defvar snmp-rfc1902-access
225 '(("read-only") ("read-write") ("read-create") ("not-accessible")
226 ("accessible-for-notify"))
227 "ACCESS values from RFC 1155 v1 SMI.")
230 (defvar snmp-mode-status-list nil
231 "Predefined values for STATUS clauses.")
233 (defvar snmp-rfc1212-status
234 '(("mandatory") ("obsolete") ("deprecated"))
235 "STATUS values from RFC 1212 v1 SMI.")
237 (defvar snmp-rfc1902-status
238 '(("current") ("obsolete") ("deprecated"))
239 "STATUS values from RFC 1902 v2 SMI.")
242 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
243 ;;;----------------------------------------------------------------------------
245 ;; Nothing to customize below here.
247 ;;;----------------------------------------------------------------------------
248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
251 ;; Need this stuff when compiling for imenu macros, etc.
253 (eval-when-compile
254 (require 'cl)
255 (require 'imenu))
258 ;; Create abbrev table for SNMP MIB mode
260 (defvar snmp-mode-abbrev-table nil
261 "Abbrev table in use in SNMP mode.")
262 (define-abbrev-table 'snmp-mode-abbrev-table ())
265 ;; Create abbrev table for SNMPv2 mode
267 (defvar snmpv2-mode-abbrev-table nil
268 "Abbrev table in use in SNMPv2 mode.")
269 (define-abbrev-table 'snmpv2-mode-abbrev-table ())
272 ;; Set up our keymap
274 (defvar snmp-mode-map (make-sparse-keymap)
275 "Keymap used in SNMP mode.")
277 (define-key snmp-mode-map "\t" 'snmp-indent-command)
278 (define-key snmp-mode-map "\177" 'backward-delete-char-untabify)
280 (define-key snmp-mode-map "\C-c\C-i" 'tempo-complete-tag)
281 (define-key snmp-mode-map "\C-c\C-f" 'tempo-forward-mark)
282 (define-key snmp-mode-map "\C-c\C-b" 'tempo-backward-mark)
285 ;; Set up our syntax table
287 (defvar snmp-mode-syntax-table nil
288 "Syntax table used for buffers in SNMP mode.")
290 (if snmp-mode-syntax-table
292 (setq snmp-mode-syntax-table (make-syntax-table))
293 (modify-syntax-entry ?\\ "\\" snmp-mode-syntax-table)
294 (modify-syntax-entry ?- "_ 1234" snmp-mode-syntax-table)
295 (modify-syntax-entry ?\n ">" snmp-mode-syntax-table)
296 (modify-syntax-entry ?\^m ">" snmp-mode-syntax-table)
297 (modify-syntax-entry ?_ "." snmp-mode-syntax-table)
298 (modify-syntax-entry ?: "." snmp-mode-syntax-table)
299 (modify-syntax-entry ?= "." snmp-mode-syntax-table))
301 ;; Set up the stuff that's common between snmp-mode and snmpv2-mode
303 (defun snmp-common-mode (name mode abbrev font-keywords imenu-index tempo-tags)
304 (kill-all-local-variables)
306 ;; Become the current major mode
307 (setq mode-name name)
308 (setq major-mode mode)
310 ;; Activate keymap, syntax table, and abbrev table
311 (use-local-map snmp-mode-map)
312 (set-syntax-table snmp-mode-syntax-table)
313 (setq local-abbrev-table abbrev)
315 ;; Set up paragraphs (?)
316 (make-local-variable 'paragraph-start)
317 (setq paragraph-start (concat "$\\|" page-delimiter))
318 (make-local-variable 'paragraph-separate)
319 (setq paragraph-separate paragraph-start)
320 (make-local-variable 'paragraph-ignore-fill-prefix)
321 (setq paragraph-ignore-fill-prefix t)
323 ;; Set up comments
324 (make-local-variable 'comment-start)
325 (setq comment-start "-- ")
326 (make-local-variable 'comment-start-skip)
327 (setq comment-start-skip "--+[ \t]*")
328 (make-local-variable 'comment-column)
329 (setq comment-column 40)
330 (make-local-variable 'parse-sexp-ignore-comments)
331 (setq parse-sexp-ignore-comments t)
333 ;; Set up indentation
334 (make-local-variable 'indent-line-function)
335 (setq indent-line-function (if snmp-special-indent
336 'snmp-indent-line
337 'indent-to-left-margin))
339 ;; Font Lock
340 (make-local-variable 'font-lock-defaults)
341 (setq font-lock-defaults (cons font-keywords '(nil nil ((?- . "w 1234")))))
343 ;; Imenu
344 (make-local-variable 'imenu-create-index-function)
345 (setq imenu-create-index-function imenu-index)
347 ;; Tempo
348 (tempo-use-tag-list tempo-tags)
349 (make-local-variable 'tempo-match-finder)
350 (setq tempo-match-finder "\\b\\(.+\\)\\=")
351 (make-local-variable 'tempo-interactive)
352 (setq tempo-interactive t)
354 ;; Miscellaneous customization
355 (make-local-variable 'require-final-newline)
356 (setq require-final-newline t))
359 ;; SNMPv1 MIB Editing Mode.
361 ;;;###autoload
362 (defun snmp-mode ()
363 "Major mode for editing SNMP MIBs.
364 Expression and list commands understand all C brackets.
365 Tab indents for C code.
366 Comments start with -- and end with newline or another --.
367 Delete converts tabs to spaces as it moves back.
368 \\{snmp-mode-map}
369 Turning on snmp-mode runs the hooks in `snmp-common-mode-hook', then
370 `snmp-mode-hook'."
371 (interactive)
373 (snmp-common-mode "SNMP" 'snmp-mode
374 snmp-mode-abbrev-table
375 '(snmp-font-lock-keywords
376 snmp-font-lock-keywords-1
377 snmp-font-lock-keywords-2
378 snmp-font-lock-keywords-3)
379 'snmp-mode-imenu-create-index
380 'snmp-tempo-tags)
382 ;; Completion lists
383 (make-local-variable 'snmp-mode-syntax-list)
384 (setq snmp-mode-syntax-list (append snmp-rfc1155-types
385 snmp-rfc1213-types
386 snmp-mode-syntax-list))
387 (make-local-variable 'snmp-mode-access-list)
388 (setq snmp-mode-access-list snmp-rfc1155-access)
389 (make-local-variable 'snmp-mode-status-list)
390 (setq snmp-mode-status-list snmp-rfc1212-status)
392 ;; Run hooks
393 (run-hooks 'snmp-common-mode-hook)
394 (run-hooks 'snmp-mode-hook))
397 ;;;###autoload
398 (defun snmpv2-mode ()
399 "Major mode for editing SNMPv2 MIBs.
400 Expression and list commands understand all C brackets.
401 Tab indents for C code.
402 Comments start with -- and end with newline or another --.
403 Delete converts tabs to spaces as it moves back.
404 \\{snmp-mode-map}
405 Turning on snmp-mode runs the hooks in `snmp-common-mode-hook',
406 then `snmpv2-mode-hook'."
407 (interactive)
409 (snmp-common-mode "SNMPv2" 'snmpv2-mode
410 snmpv2-mode-abbrev-table
411 '(snmp-font-lock-keywords
412 snmp-font-lock-keywords-1
413 snmp-font-lock-keywords-2
414 snmp-font-lock-keywords-3)
415 'snmp-mode-imenu-create-index
416 'snmpv2-tempo-tags)
418 ;; Completion lists
419 (make-local-variable 'snmp-mode-syntax-list)
420 (setq snmp-mode-syntax-list (append snmp-rfc1902-types
421 snmp-rfc1903-types
422 snmp-mode-syntax-list))
423 (make-local-variable 'snmp-mode-access-list)
424 (setq snmp-mode-access-list snmp-rfc1902-access)
425 (make-local-variable 'snmp-mode-status-list)
426 (setq snmp-mode-status-list snmp-rfc1902-status)
428 ;; Run hooks
429 (run-hooks 'snmp-common-mode-hook)
430 (run-hooks 'snmpv2-mode-hook))
433 ;;;----------------------------------------------------------------------------
435 ;; Indentation Setup
437 ;;;----------------------------------------------------------------------------
439 (defvar snmp-macro-open
440 "[a-zA-Z][-a-zA-Z0-9]*[ \t]*\\(OBJECT\\|TRAP\\)-\\(TYPE\\|GROUP\\)\
441 \\|DESCRIPTION\\|IMPORTS\\|MODULE\\(-IDENTITY\\|-COMPLIANCE\\)\
442 \\|.*::=[ \t]*\\(BEGIN\\|TEXTUAL-CONVENTION\\)[ \t]*$")
444 (defvar snmp-macro-close
445 "::=[ \t]*{\\|\\(END\\|.*[;\"]\\)[ \t]*$")
447 (defun snmp-calculate-indent ()
448 "Calculate the current line indentation in SNMP MIB code.
450 We use a very simple scheme: if the previous non-empty line was a \"macro
451 open\" string, add `snmp-indent-level' to it. If it was a \"macro close\"
452 string, subtract `snmp-indent-level'. Otherwise, use the same indentation
453 as the previous non-empty line. Note comments are considered empty
454 lines for the purposes of this function."
455 (let ((empty (concat "\\([ \t]*\\)\\(" comment-start-skip "\\|$\\)"))
456 (case-fold-search nil)) ; keywords must be in uppercase
457 (save-excursion
458 (while (and (>= (forward-line -1) 0)
459 (looking-at empty)))
460 (skip-chars-forward " \t")
461 (+ (current-column)
462 ;; Are we looking at a macro open string? If so, add more.
463 (cond ((looking-at snmp-macro-open)
464 snmp-indent-level)
465 ;; macro close string? If so, remove some.
466 ((looking-at snmp-macro-close)
467 (- snmp-indent-level))
468 ;; Neither; just stay here.
469 (t 0))))))
471 (defun snmp-indent-line ()
472 "Indent current line as SNMP MIB code."
473 (let ((indent (snmp-calculate-indent))
474 (pos (- (point-max) (point)))
475 shift-amt beg end)
476 (beginning-of-line)
477 (setq beg (point))
478 (skip-chars-forward " \t")
479 (setq shift-amt (- indent (current-column)))
480 (if (zerop shift-amt)
482 (delete-region beg (point))
483 (indent-to indent))
484 ;; If initial point was within line's indentation,
485 ;; position after the indentation. Else stay at same point in text.
486 (if (> (- (point-max) pos) (point))
487 (goto-char (- (point-max) pos)))))
489 (defun snmp-indent-command ()
490 "Indent current line as SNMP MIB code, or sometimes insert a TAB.
491 If `snmp-tab-always-indent' is t, always reindent the current line when
492 this command is run.
493 If `snmp-tab-always-indent' is nil, reindent the current line if point is
494 in the initial indentation. Otherwise, insert a TAB."
495 (interactive)
496 (if (and (not snmp-tab-always-indent)
497 (save-excursion
498 (skip-chars-backward " \t")
499 (not (bolp))))
500 (insert-tab)
501 (snmp-indent-line)))
504 ;;;----------------------------------------------------------------------------
506 ;; Imenu Setup
508 ;;;----------------------------------------------------------------------------
510 (defvar snmp-clause-regexp
511 "^[ \t]*\\([a-zA-Z][-a-zA-Z0-9]*\\)[ \t\n]*\
512 \\(TRAP-TYPE\\|::=\\|OBJECT\\(-TYPE[ \t\n]+SYNTAX\\|[ \t\n]+IDENTIFIER[ \t\n]*::=\\)\\)")
514 (defun snmp-mode-imenu-create-index ()
515 (let ((index-alist '())
516 (index-oid-alist '())
517 (index-tc-alist '())
518 (index-table-alist '())
519 (index-trap-alist '())
520 (case-fold-search nil) ; keywords must be uppercase
521 prev-pos token marker end)
522 (goto-char (point-min))
523 (imenu-progress-message prev-pos 0)
524 ;; Search for a useful MIB item (that's not in a comment)
525 (save-match-data
526 (while (re-search-forward snmp-clause-regexp nil t)
527 (imenu-progress-message prev-pos)
528 (setq
529 end (match-end 0)
530 token (cons (buffer-substring (match-beginning 1) (match-end 1))
531 (set-marker (make-marker) (match-beginning 1))))
532 (goto-char (match-beginning 2))
533 (cond ((looking-at "OBJECT-TYPE[ \t\n]+SYNTAX")
534 (push token index-alist))
535 ((looking-at "OBJECT[ \t\n]+IDENTIFIER[ \t\n]*::=")
536 (push token index-oid-alist))
537 ((looking-at "::=[ \t\n]*SEQUENCE[ \t\n]*{")
538 (push token index-table-alist))
539 ((looking-at "TRAP-TYPE")
540 (push token index-trap-alist))
541 ((looking-at "::=")
542 (push token index-tc-alist)))
543 (goto-char end)))
544 ;; Create the menu
545 (imenu-progress-message prev-pos 100)
546 (setq index-alist (nreverse index-alist))
547 (and index-tc-alist
548 (push (cons "Textual Conventions" (nreverse index-tc-alist))
549 index-alist))
550 (and index-trap-alist
551 (push (cons "Traps" (nreverse index-trap-alist))
552 index-alist))
553 (and index-table-alist
554 (push (cons "Tables" (nreverse index-table-alist))
555 index-alist))
556 (and index-oid-alist
557 (push (cons "Object IDs" (nreverse index-oid-alist))
558 index-alist))
559 index-alist))
562 ;;;----------------------------------------------------------------------------
564 ;; Tempo Setup
566 ;;;----------------------------------------------------------------------------
568 (require 'tempo)
570 ;; Perform a completing-read with info given
572 (defun snmp-completing-read (prompt table &optional pred require init hist)
573 "Read from the minibuffer, with completion.
574 Like `completing-read', but the variable `snmp-completion-ignore-case'
575 controls whether case is significant."
576 (let ((completion-ignore-case snmp-completion-ignore-case))
577 (completing-read prompt table pred require init hist)))
579 ;; OBJECT-TYPE macro template
581 (tempo-define-template "snmp-object-type"
582 '(> (P "Object Label: ") " OBJECT-TYPE" n>
583 "SYNTAX "
584 (if tempo-interactive
585 (snmp-completing-read "Syntax: " snmp-mode-syntax-list nil nil)
586 p) n>
587 "ACCESS "
588 (if tempo-interactive
589 (snmp-completing-read "Access: " snmp-mode-access-list nil t)
590 p) n>
591 "STATUS "
592 (if tempo-interactive
593 (snmp-completing-read "Status: " snmp-mode-status-list nil t)
594 p) n>
595 "DESCRIPTION" n> "\"" p "\"" n>
596 (P "Default Value: " defval t)
597 (if (string= "" (tempo-lookup-named 'defval))
599 '(l "DEFVAL { " (s defval) " }" n>))
600 "::= { " (p "OID: ") " }" n)
601 "objectType"
602 "Insert an OBJECT-TYPE macro."
603 'snmp-tempo-tags)
605 ;; Table macro template
607 (tempo-define-template "snmp-table-type"
608 ;; First the table OBJECT-TYPE
609 '(> (P "Table Name: " table)
610 (P "Entry Name: " entry t)
611 (let* ((entry (tempo-lookup-named 'entry))
612 (seq (copy-sequence entry)))
613 (aset entry 0 (downcase (aref entry 0)))
614 (aset seq 0 (upcase (aref seq 0)))
615 (tempo-save-named 'obj-entry entry)
616 (tempo-save-named 'seq-entry seq)
617 nil)
618 " OBJECT-TYPE" n>
619 "SYNTAX SEQUENCE OF "
620 (s seq-entry) n>
621 "ACCESS not-accessible" n>
622 "STATUS mandatory" n>
623 "DESCRIPTION" n> "\"" p "\"" n>
624 "::= { " (p "OID: ") " }" n n>
625 ;; Next the row OBJECT-TYPE
626 (s obj-entry) " OBJECT-TYPE" n>
627 "SYNTAX " (s seq-entry) n>
628 "ACCESS not-accessible" n>
629 "STATUS mandatory" n>
630 "DESCRIPTION" n> "\"" p "\"" n>
631 "INDEX { " (p "Index List: ") " }" n>
632 "::= {" (s table) " 1 }" n n>
633 ;; Finally the SEQUENCE type
634 (s seq-entry) " ::= SEQUENCE {" n> p n> "}" n)
635 "tableType"
636 "Insert an SNMP table."
637 'snmp-tempo-tags)
640 ;; v2 SMI OBJECT-TYPE macro template
642 (tempo-define-template "snmpv2-object-type"
643 '(> (P "Object Label: ") " OBJECT-TYPE" n>
644 "SYNTAX "
645 (if tempo-interactive
646 (snmp-completing-read "Syntax: " snmp-mode-syntax-list nil nil)
647 p) n>
648 "MAX-ACCESS "
649 (if tempo-interactive
650 (snmp-completing-read "Max Access: " snmp-mode-access-list nil t)
651 p) n>
652 "STATUS "
653 (if tempo-interactive
654 (snmp-completing-read "Status: " snmp-mode-status-list nil t)
655 p) n>
656 "DESCRIPTION" n> "\"" p "\"" n>
657 (P "Default Value: " defval t)
658 (if (string= "" (tempo-lookup-named 'defval))
660 '(l "DEFVAL { " (s defval) " }" n>))
661 "::= { " (p "OID: ") " }" n)
662 "objectType"
663 "Insert an v2 SMI OBJECT-TYPE macro."
664 'snmpv2-tempo-tags)
666 ;; v2 SMI Table macro template
668 (tempo-define-template "snmpv2-table-type"
669 ;; First the table OBJECT-TYPE
670 '(> (P "Table Name: " table)
671 (P "Entry Name: " entry t)
672 (let* ((entry (tempo-lookup-named 'entry))
673 (seq (copy-sequence entry)))
674 (aset entry 0 (downcase (aref entry 0)))
675 (aset seq 0 (upcase (aref seq 0)))
676 (tempo-save-named 'obj-entry entry)
677 (tempo-save-named 'seq-entry seq)
678 nil)
679 " OBJECT-TYPE" n>
680 "SYNTAX SEQUENCE OF "
681 (s seq-entry) n>
682 "MAX-ACCESS not-accessible" n>
683 "STATUS current" n>
684 "DESCRIPTION" n> "\"" p "\"" n>
685 "::= { " (p "OID: ") " }" n n>
686 ;; Next the row OBJECT-TYPE
687 (s obj-entry) " OBJECT-TYPE" n>
688 "SYNTAX " (s seq-entry) n>
689 "MAX-ACCESS not-accessible" n>
690 "STATUS current" n>
691 "DESCRIPTION" n> "\"" p "\"" n>
692 "INDEX { " (p "Index List: ") " }" n>
693 "::= { " (s table) " 1 }" n n>
694 ;; Finally the SEQUENCE type
695 (s seq-entry) " ::= SEQUENCE {" n> p n> "}" n)
696 "tableType"
697 "Insert an v2 SMI SNMP table."
698 'snmpv2-tempo-tags)
700 ;; v2 SMI TEXTUAL-CONVENTION macro template
702 (tempo-define-template "snmpv2-textual-convention"
703 '(> (P "Texual Convention Type: ") " ::= TEXTUAL-CONVENTION" n>
704 "STATUS "
705 (if tempo-interactive
706 (snmp-completing-read "Status: " snmp-mode-status-list nil t)
707 p) n>
708 "DESCRIPTION" n> "\"" p "\"" n>
709 "SYNTAX "
710 (if tempo-interactive
711 (snmp-completing-read "Syntax: " snmp-mode-syntax-list nil nil)
712 p) n> )
713 "textualConvention"
714 "Insert an v2 SMI TEXTUAL-CONVENTION macro."
715 'snmpv2-tempo-tags)
718 (provide 'snmp-mode)
720 ;;; snmp-mode.el ends here