comparison lisp/net/snmp-mode.el @ 91041:bdb3fe0ba9fa

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 866-879) - Merge multi-tty branch - Update from CVS - Merge from emacs--rel--22 Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-257
author Miles Bader <miles@gnu.org>
date Thu, 11 Oct 2007 16:22:07 +0000
parents f55f9811f5d7 dbbf6366b2a0
children 606f2d163a64
comparison
equal deleted inserted replaced
91040:14c4a6aac623 91041:bdb3fe0ba9fa
86 ;; 86 ;;
87 87
88 ;;; Code: 88 ;;; Code:
89 89
90 (eval-when-compile 90 (eval-when-compile
91 (require 'cl)
92 (require 'imenu) ; Need this stuff when compiling for imenu macros, etc.
91 (require 'tempo)) 93 (require 'tempo))
92 94
93 ;;;---------------------------------------------------------------------------- 95 ;;;----------------------------------------------------------------------------
94 ;; 96 ;;
95 ;; Customize these: 97 ;; Customize these:
100 "Mode for editing SNMP MIB files." 102 "Mode for editing SNMP MIB files."
101 :group 'data 103 :group 'data
102 :version "20.4") 104 :version "20.4")
103 105
104 (defcustom snmp-special-indent t 106 (defcustom snmp-special-indent t
105 "*If non-nil, use a simple heuristic to try to guess the right indentation. 107 "If non-nil, use a simple heuristic to try to guess the right indentation.
106 If nil, then no special indentation is attempted." 108 If nil, then no special indentation is attempted."
107 :type 'boolean 109 :type 'boolean
108 :group 'snmp) 110 :group 'snmp)
109 111
110 (defcustom snmp-indent-level 4 112 (defcustom snmp-indent-level 4
111 "*Indentation level for SNMP MIBs." 113 "Indentation level for SNMP MIBs."
112 :type 'integer 114 :type 'integer
113 :group 'snmp) 115 :group 'snmp)
114 116
115 (defcustom snmp-tab-always-indent nil 117 (defcustom snmp-tab-always-indent nil
116 "*Non-nil means TAB should always reindent the current line. 118 "Non-nil means TAB should always reindent the current line.
117 A value of nil means reindent if point is within the initial line indentation; 119 A value of nil means reindent if point is within the initial line indentation;
118 otherwise insert a TAB." 120 otherwise insert a TAB."
119 :type 'boolean 121 :type 'boolean
120 :group 'snmp) 122 :group 'snmp)
121 123
122 (defcustom snmp-completion-ignore-case t 124 (defcustom snmp-completion-ignore-case t
123 "*Non-nil means that case differences are ignored during completion. 125 "Non-nil means that case differences are ignored during completion.
124 A value of nil means that case is significant. 126 A value of nil means that case is significant.
125 This is used during Tempo template completion." 127 This is used during Tempo template completion."
126 :type 'boolean 128 :type 'boolean
127 :group 'snmp) 129 :group 'snmp)
128 130
129 (defcustom snmp-common-mode-hook nil 131 (defcustom snmp-common-mode-hook nil
130 "*Hook(s) evaluated when a buffer enters either SNMP or SNMPv2 mode." 132 "Hook(s) evaluated when a buffer enters either SNMP or SNMPv2 mode."
131 :type 'hook 133 :type 'hook
132 :group 'snmp) 134 :group 'snmp)
133 135
134 (defcustom snmp-mode-hook nil 136 (defcustom snmp-mode-hook nil
135 "*Hook(s) evaluated when a buffer enters SNMP mode." 137 "Hook(s) evaluated when a buffer enters SNMP mode."
136 :type 'hook 138 :type 'hook
137 :group 'snmp) 139 :group 'snmp)
138 140
139 (defcustom snmpv2-mode-hook nil 141 (defcustom snmpv2-mode-hook nil
140 "*Hook(s) evaluated when a buffer enters SNMPv2 mode." 142 "Hook(s) evaluated when a buffer enters SNMPv2 mode."
141 :type 'hook 143 :type 'hook
142 :group 'snmp) 144 :group 'snmp)
143 145
144 (defvar snmp-tempo-tags nil 146 (defvar snmp-tempo-tags nil
145 "*Tempo tags for SNMP mode.") 147 "*Tempo tags for SNMP mode.")
193 195
194 (defvar snmp-mode-syntax-list nil 196 (defvar snmp-mode-syntax-list nil
195 "Predefined types for SYNTAX clauses.") 197 "Predefined types for SYNTAX clauses.")
196 198
197 (defvar snmp-rfc1155-types 199 (defvar snmp-rfc1155-types
198 '(("INTEGER") ("OCTET STRING") ("OBJECT IDENTIFIER") ("NULL") ("IpAddress") 200 '("INTEGER" "OCTET STRING" "OBJECT IDENTIFIER" "NULL" "IpAddress"
199 ("NetworkAddress") ("Counter") ("Gauge") ("TimeTicks") ("Opaque")) 201 "NetworkAddress" "Counter" "Gauge" "TimeTicks" "Opaque")
200 "Types from RFC 1155 v1 SMI.") 202 "Types from RFC 1155 v1 SMI.")
201 203
202 (defvar snmp-rfc1213-types 204 (defvar snmp-rfc1213-types
203 '(("DisplayString")) 205 '("DisplayString")
204 "Types from RFC 1213 MIB-II.") 206 "Types from RFC 1213 MIB-II.")
205 207
206 (defvar snmp-rfc1902-types 208 (defvar snmp-rfc1902-types
207 '(("INTEGER") ("OCTET STRING") ("OBJECT IDENTIFIER") ("Integer32") 209 '("INTEGER" "OCTET STRING" "OBJECT IDENTIFIER" "Integer32"
208 ("IpAddress") ("Counter32") ("Gauge32") ("Unsigned32") ("TimeTicks") 210 "IpAddress" "Counter32" "Gauge32" "Unsigned32" "TimeTicks"
209 ("Opaque") ("Counter64")) 211 "Opaque" "Counter64")
210 "Types from RFC 1902 v2 SMI.") 212 "Types from RFC 1902 v2 SMI.")
211 213
212 (defvar snmp-rfc1903-types 214 (defvar snmp-rfc1903-types
213 '(("DisplayString") ("PhysAddress") ("MacAddress") ("TruthValue") 215 '("DisplayString" "PhysAddress" "MacAddress" "TruthValue"
214 ("TestAndIncr") ("AutonomousType") ("InstancePointer") 216 "TestAndIncr" "AutonomousType" "InstancePointer"
215 ("VariablePointer") ("RowPointer") ("RowStatus") ("TimeStamp") 217 "VariablePointer" "RowPointer" "RowStatus" "TimeStamp"
216 ("TimeInterval") ("DateAndTime") ("StorageType") ("TDomain") 218 "TimeInterval" "DateAndTime" "StorageType" "TDomain"
217 ("TAddress")) 219 "TAddress")
218 "Types from RFC 1903 Textual Conventions.") 220 "Types from RFC 1903 Textual Conventions.")
219 221
220 222
221 (defvar snmp-mode-access-list nil 223 (defvar snmp-mode-access-list nil
222 "Predefined values for ACCESS clauses.") 224 "Predefined values for ACCESS clauses.")
223 225
224 (defvar snmp-rfc1155-access 226 (defvar snmp-rfc1155-access
225 '(("read-only") ("read-write") ("write-only") ("not-accessible")) 227 '("read-only" "read-write" "write-only" "not-accessible")
226 "ACCESS values from RFC 1155 v1 SMI.") 228 "ACCESS values from RFC 1155 v1 SMI.")
227 229
228 (defvar snmp-rfc1902-access 230 (defvar snmp-rfc1902-access
229 '(("read-only") ("read-write") ("read-create") ("not-accessible") 231 '("read-only" "read-write" "read-create" "not-accessible"
230 ("accessible-for-notify")) 232 "accessible-for-notify")
231 "ACCESS values from RFC 1155 v1 SMI.") 233 "ACCESS values from RFC 1155 v1 SMI.")
232 234
233 235
234 (defvar snmp-mode-status-list nil 236 (defvar snmp-mode-status-list nil
235 "Predefined values for STATUS clauses.") 237 "Predefined values for STATUS clauses.")
236 238
237 (defvar snmp-rfc1212-status 239 (defvar snmp-rfc1212-status
238 '(("mandatory") ("obsolete") ("deprecated")) 240 '("mandatory" "obsolete" "deprecated")
239 "STATUS values from RFC 1212 v1 SMI.") 241 "STATUS values from RFC 1212 v1 SMI.")
240 242
241 (defvar snmp-rfc1902-status 243 (defvar snmp-rfc1902-status
242 '(("current") ("obsolete") ("deprecated")) 244 '("current" "obsolete" "deprecated")
243 "STATUS values from RFC 1902 v2 SMI.") 245 "STATUS values from RFC 1902 v2 SMI.")
244 246
245 247
246 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
247 ;;;---------------------------------------------------------------------------- 249 ;;;----------------------------------------------------------------------------
248 ;; 250 ;;
249 ;; Nothing to customize below here. 251 ;; Nothing to customize below here.
250 ;; 252 ;;
251 ;;;---------------------------------------------------------------------------- 253 ;;;----------------------------------------------------------------------------
252 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
253
254
255 ;; Need this stuff when compiling for imenu macros, etc.
256 ;;
257 (eval-when-compile
258 (require 'cl)
259 (require 'imenu))
260 255
261 256
262 ;; Create abbrev table for SNMP MIB mode 257 ;; Create abbrev table for SNMP MIB mode
263 ;; 258 ;;
264 (defvar snmp-mode-abbrev-table nil 259 (defvar snmp-mode-abbrev-table nil
273 (define-abbrev-table 'snmpv2-mode-abbrev-table ()) 268 (define-abbrev-table 'snmpv2-mode-abbrev-table ())
274 269
275 270
276 ;; Set up our keymap 271 ;; Set up our keymap
277 ;; 272 ;;
278 (defvar snmp-mode-map (make-sparse-keymap) 273 (defvar snmp-mode-map
274 (let ((map (make-sparse-keymap)))
275 (define-key map "\177" 'backward-delete-char-untabify)
276 (define-key map "\C-c\C-i" 'tempo-complete-tag)
277 (define-key map "\C-c\C-f" 'tempo-forward-mark)
278 (define-key map "\C-c\C-b" 'tempo-backward-mark)
279 map)
279 "Keymap used in SNMP mode.") 280 "Keymap used in SNMP mode.")
280 281
281 (define-key snmp-mode-map "\t" 'snmp-indent-command)
282 (define-key snmp-mode-map "\177" 'backward-delete-char-untabify)
283
284 (define-key snmp-mode-map "\C-c\C-i" 'tempo-complete-tag)
285 (define-key snmp-mode-map "\C-c\C-f" 'tempo-forward-mark)
286 (define-key snmp-mode-map "\C-c\C-b" 'tempo-backward-mark)
287
288 282
289 ;; Set up our syntax table 283 ;; Set up our syntax table
290 ;; 284 ;;
291 (defvar snmp-mode-syntax-table nil 285 (defvar snmp-mode-syntax-table
286 (let ((st (make-syntax-table)))
287 (modify-syntax-entry ?\\ "\\" st)
288 (modify-syntax-entry ?- "_ 1234" st)
289 (modify-syntax-entry ?\n ">" st)
290 (modify-syntax-entry ?\^m ">" st)
291 (modify-syntax-entry ?_ "." st)
292 (modify-syntax-entry ?: "." st)
293 (modify-syntax-entry ?= "." st)
294 st)
292 "Syntax table used for buffers in SNMP mode.") 295 "Syntax table used for buffers in SNMP mode.")
293
294 (if snmp-mode-syntax-table
295 ()
296 (setq snmp-mode-syntax-table (make-syntax-table))
297 (modify-syntax-entry ?\\ "\\" snmp-mode-syntax-table)
298 (modify-syntax-entry ?- "_ 1234" snmp-mode-syntax-table)
299 (modify-syntax-entry ?\n ">" snmp-mode-syntax-table)
300 (modify-syntax-entry ?\^m ">" snmp-mode-syntax-table)
301 (modify-syntax-entry ?_ "." snmp-mode-syntax-table)
302 (modify-syntax-entry ?: "." snmp-mode-syntax-table)
303 (modify-syntax-entry ?= "." snmp-mode-syntax-table))
304 296
305 ;; Set up the stuff that's common between snmp-mode and snmpv2-mode 297 ;; Set up the stuff that's common between snmp-mode and snmpv2-mode
306 ;; 298 ;;
307 (defun snmp-common-mode (name mode abbrev font-keywords imenu-index tempo-tags) 299 (defun snmp-common-mode (name mode abbrev font-keywords imenu-index tempo-tags)
308 (kill-all-local-variables) 300 (kill-all-local-variables)
333 (setq comment-column 40) 325 (setq comment-column 40)
334 (make-local-variable 'parse-sexp-ignore-comments) 326 (make-local-variable 'parse-sexp-ignore-comments)
335 (setq parse-sexp-ignore-comments t) 327 (setq parse-sexp-ignore-comments t)
336 328
337 ;; Set up indentation 329 ;; Set up indentation
338 (make-local-variable 'indent-line-function) 330 (if snmp-special-indent
339 (setq indent-line-function (if snmp-special-indent 331 (set (make-local-variable 'indent-line-function) 'snmp-indent-line))
340 'snmp-indent-line 332 (set (make-local-variable 'tab-always-indent) snmp-tab-always-indent)
341 'indent-to-left-margin))
342 333
343 ;; Font Lock 334 ;; Font Lock
344 (make-local-variable 'font-lock-defaults) 335 (make-local-variable 'font-lock-defaults)
345 (setq font-lock-defaults (cons font-keywords '(nil nil ((?- . "w 1234"))))) 336 (setq font-lock-defaults (cons font-keywords '(nil nil ((?- . "w 1234")))))
346 337
472 463
473 (defun snmp-indent-line () 464 (defun snmp-indent-line ()
474 "Indent current line as SNMP MIB code." 465 "Indent current line as SNMP MIB code."
475 (let ((indent (snmp-calculate-indent)) 466 (let ((indent (snmp-calculate-indent))
476 (pos (- (point-max) (point))) 467 (pos (- (point-max) (point)))
477 shift-amt beg end) 468 shift-amt beg)
478 (beginning-of-line) 469 (beginning-of-line)
479 (setq beg (point)) 470 (setq beg (point))
480 (skip-chars-forward " \t") 471 (skip-chars-forward " \t")
481 (setq shift-amt (- indent (current-column))) 472 (setq shift-amt (- indent (current-column)))
482 (if (zerop shift-amt) 473 (if (zerop shift-amt)
486 ;; If initial point was within line's indentation, 477 ;; If initial point was within line's indentation,
487 ;; position after the indentation. Else stay at same point in text. 478 ;; position after the indentation. Else stay at same point in text.
488 (if (> (- (point-max) pos) (point)) 479 (if (> (- (point-max) pos) (point))
489 (goto-char (- (point-max) pos))))) 480 (goto-char (- (point-max) pos)))))
490 481
491 (defun snmp-indent-command ()
492 "Indent current line as SNMP MIB code, or sometimes insert a TAB.
493 If `snmp-tab-always-indent' is t, always reindent the current line when
494 this command is run.
495 If `snmp-tab-always-indent' is nil, reindent the current line if point is
496 in the initial indentation. Otherwise, insert a TAB."
497 (interactive)
498 (if (and (not snmp-tab-always-indent)
499 (save-excursion
500 (skip-chars-backward " \t")
501 (not (bolp))))
502 (insert-tab)
503 (snmp-indent-line)))
504
505 482
506 ;;;---------------------------------------------------------------------------- 483 ;;;----------------------------------------------------------------------------
507 ;; 484 ;;
508 ;; Imenu Setup 485 ;; Imenu Setup
509 ;; 486 ;;
518 (index-oid-alist '()) 495 (index-oid-alist '())
519 (index-tc-alist '()) 496 (index-tc-alist '())
520 (index-table-alist '()) 497 (index-table-alist '())
521 (index-trap-alist '()) 498 (index-trap-alist '())
522 (case-fold-search nil) ; keywords must be uppercase 499 (case-fold-search nil) ; keywords must be uppercase
523 prev-pos token marker end) 500 prev-pos token end)
524 (goto-char (point-min)) 501 (goto-char (point-min))
525 (imenu-progress-message prev-pos 0) 502 (imenu-progress-message prev-pos 0)
526 ;; Search for a useful MIB item (that's not in a comment) 503 ;; Search for a useful MIB item (that's not in a comment)
527 (save-match-data 504 (save-match-data
528 (while (re-search-forward snmp-clause-regexp nil t) 505 (while (re-search-forward snmp-clause-regexp nil t)
529 (imenu-progress-message prev-pos) 506 (imenu-progress-message prev-pos)
530 (setq 507 (setq
531 end (match-end 0) 508 end (match-end 0)
532 token (cons (buffer-substring (match-beginning 1) (match-end 1)) 509 token (cons (match-string 1)
533 (set-marker (make-marker) (match-beginning 1)))) 510 (set-marker (make-marker) (match-beginning 1))))
534 (goto-char (match-beginning 2)) 511 (goto-char (match-beginning 2))
535 (cond ((looking-at "OBJECT-TYPE[ \t\n]+SYNTAX") 512 (cond ((looking-at "OBJECT-TYPE[ \t\n]+SYNTAX")
536 (push token index-alist)) 513 (push token index-alist))
537 ((looking-at "OBJECT[ \t\n]+IDENTIFIER[ \t\n]*::=") 514 ((looking-at "OBJECT[ \t\n]+IDENTIFIER[ \t\n]*::=")
717 'snmpv2-tempo-tags) 694 'snmpv2-tempo-tags)
718 695
719 696
720 (provide 'snmp-mode) 697 (provide 'snmp-mode)
721 698
722 ;;; arch-tag: eb6cc0f9-1e47-4023-8625-bc9aae6c3527 699 ;; arch-tag: eb6cc0f9-1e47-4023-8625-bc9aae6c3527
723 ;;; snmp-mode.el ends here 700 ;;; snmp-mode.el ends here