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