]> gitweb.michael.orlitzky.com - nagios-mode.git/blob - nagios-mode.el
README: minor wording tweak.
[nagios-mode.git] / nagios-mode.el
1 ;;
2 ;; nagios-mode, an Emacs mode for Nagios <http://www.nagios.org/>
3 ;; configuration files.
4 ;;
5 ;; Copyright Michael Orlitzky
6 ;;
7 ;; http://michael.orlitzky.com/
8 ;;
9 ;; This program is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
13 ;;
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18 ;;
19 ;; http://www.fsf.org/licensing/licenses/gpl.html
20 ;;
21
22 (require 'font-lock)
23 (require 'regexp-opt)
24
25
26 ;; Custom Variables
27
28 (defcustom nagios-indent-level 2
29 "Number of spaces in one indentation (tab)."
30 :type 'integer :group 'nagios
31 )
32
33
34
35 ;; Indentation Voodoo
36
37 (defun nagios-indent-line(&optional flag)
38 "Indents a line, taking nesting into account."
39 (interactive)
40 (nagios-indent-to (nagios-calculate-indent))
41 )
42
43
44 (defun nagios-beginning-of-line-pos()
45 ;; Return the point position corresponding to the beginning
46 ;; of the current line.
47 (save-excursion
48 (beginning-of-line)
49 (point)
50 )
51 )
52
53 (defun nagios-end-of-line-pos()
54 ;; Return the point position corresponding to the end
55 ;; of the current line.
56 (save-excursion
57 (end-of-line)
58 (point)
59 )
60 )
61
62 (defun nagios-point-offset()
63 ;; How far are we from the beginning of the line?
64 (- (point) (nagios-beginning-of-line-pos))
65 )
66
67 (defun nagios-first-char-offset()
68 ;; How far is the first character on this line
69 ;; from the beginning of the line?
70 (save-excursion
71 (beginning-of-line)
72 (skip-chars-forward " \t")
73 )
74 )
75
76 (defun nagios-first-char-pos()
77 ;; What's the position of the first character on this line?
78 (+ (nagios-beginning-of-line-pos) (nagios-first-char-offset))
79 )
80
81 (defun nagios-indent-to(indent-column)
82 "Indent the current line to column indent-column."
83 ;; Store the point in orig-pos.
84 (let ((orig-point (point)))
85
86 ;; And store the offset of the first character (with respect to the
87 ;; beginning of the line) in orig-first-char-offset.
88 (let ((orig-first-char-offset (nagios-first-char-offset)))
89
90 ;; Delete any leading whitespace, and move the point to the
91 ;; beginning of the line.
92 (delete-region (nagios-beginning-of-line-pos) (nagios-first-char-pos))
93 (beginning-of-line)
94
95 ;; Now insert indent-column spaces.
96 (let ((indent-remaining indent-column))
97 (while (< 0 indent-remaining)
98 (insert " ")
99 (setq indent-remaining (- indent-remaining 1)))
100 )
101
102 ;; The text on the current line just moved left/right some amount;
103 ;; call it text-delta. We want to move the point that same distance.
104 (let ((text-delta (- (nagios-first-char-offset) orig-first-char-offset)))
105 (goto-char (+ orig-point text-delta))
106 )
107
108 ;; The point should never wind up to the left of indent-column, so
109 ;; if it's there, move it over to indent-column.
110 (if (< (nagios-point-offset) indent-column)
111 (goto-char (+ (nagios-beginning-of-line-pos) indent-column))
112 )
113 )
114 )
115 )
116
117
118 (defun nagios-char-is-commented(pos)
119 "True if the character at position pos is commented, nil otherwise."
120 (save-excursion
121 (goto-char pos)
122 (re-search-backward "\\(#\\|;\\)" (nagios-beginning-of-line-pos) t)
123 )
124 )
125
126 (defun nagios-char-is-commented-and-valid(pos)
127 "True if the character at position pos is commented and non-nil.
128 Nil otherwise."
129 (if (eq nil pos)
130 nil
131 (nagios-char-is-commented pos)
132 )
133 )
134
135
136 (defun nagios-last-opening-brace()
137 "Returns the position of the last opening brace, with
138 respect to the current point. Ignores braces which
139 are commented out."
140 (save-excursion
141 (let ((lob (re-search-backward "{" nil t)))
142
143 (while (nagios-char-is-commented-and-valid lob)
144 (goto-char lob)
145 (setq lob (re-search-backward "{" nil t))
146 )
147
148 (if lob
149 lob
150 -1)
151 )
152 )
153 )
154
155
156 (defun nagios-last-closing-brace()
157 "Get the position of the last closing brace, with
158 respect to the current point. Ignores braces which
159 are commented out."
160 (save-excursion
161 (let ((lcb (re-search-backward "}" nil t)))
162
163 (while (nagios-char-is-commented-and-valid lcb)
164 (goto-char lcb)
165 (setq lcb (re-search-backward "}" nil t))
166 )
167
168 (if lcb
169 lcb
170 -1)
171 )
172 )
173 )
174
175 (defun nagios-in-block()
176 "Determine if the point is inside of a {} block."
177
178 ;; If the last brace seen in the buffer is an opening brace, we're
179 ;; in a block. Otherwise, we aren't.
180 (if (>= (nagios-last-closing-brace) (nagios-last-opening-brace))
181 nil
182 t)
183 )
184
185
186 (defun nagios-brace-on-line()
187 ;; Is there a curly brace on this line?
188 (save-excursion
189 (beginning-of-line)
190 (re-search-forward "[{}]" (nagios-end-of-line-pos) t)
191 )
192 )
193
194
195 (defun nagios-calculate-indent()
196 "Calculate the level of indentation."
197
198 ;; We're either inside a block, or we aren't.
199 ;; Initialize the indent variable to either nagios-indent-level
200 ;; or 0 depending on whether or not we're in a block.
201 (let ((indent (if (nagios-in-block)
202 nagios-indent-level
203 0)
204 )
205 )
206
207 ;; Set the indentation level to 0 if we find either brace on this
208 ;; line and.
209 (if (and (nagios-brace-on-line)
210 (not (nagios-char-is-commented (nagios-brace-on-line))))
211 0
212 indent
213 )
214 )
215 )
216
217
218 ;; Keymaps
219
220 (defun nagios-insert-right-brace-and-indent()
221 "Insert a '}' character, and indent the line."
222 (interactive)
223 (insert "}")
224 (nagios-indent-line)
225 )
226
227
228 (defvar nagios-mode-map()
229 "Keymap used in nagios mode.")
230
231 (when (not nagios-mode-map)
232 (setq nagios-mode-map (make-sparse-keymap))
233 (define-key nagios-mode-map
234 (read-kbd-macro "}")
235 'nagios-insert-right-brace-and-indent)
236 )
237
238
239
240 (defconst nagios-directives
241 (eval-when-compile
242 (concat "^[ \t\r\n]*"
243
244 (regexp-opt
245 '("action_url"
246 "active_checks_enabled"
247 "address"
248 "alias"
249 "can_submit_commands"
250 "check_command"
251 "check_freshness"
252 "check_interval"
253 "check_period"
254 "checks_enabled"
255 "command_line"
256 "command_name"
257 "contact_groups"
258 "contact_name"
259 "contactgroup_members"
260 "contactgroup_name"
261 "contactgroups"
262 "contacts"
263 "dependency_period"
264 "dependent_description"
265 "dependent_host"
266 "dependent_host_name"
267 "dependent_hostgroup"
268 "dependent_hostgroup_name"
269 "dependent_hostgroups"
270 "dependent_service_description"
271 "dependent_servicegroup"
272 "dependent_servicegroup_name"
273 "dependent_servicegroups"
274 "description"
275 "display_name"
276 "email"
277 "escalation_options"
278 "escalation_period"
279 "event_handler"
280 "event_handler_enabled"
281 "exclude"
282 "execution_failure_criteria"
283 "execution_failure_options"
284 "failure_prediction_enabled"
285 "failure_prediction_options"
286 "first_notification"
287 "first_notification_delay"
288 "flap_detection_enabled"
289 "flap_detection_options"
290 "freshness_threshold"
291 "friday"
292 "high_flap_threshold"
293 "host"
294 "host_groups"
295 "host_name"
296 "host_notification_commands"
297 "host_notification_options"
298 "host_notification_period"
299 "host_notifications_enabled"
300 "hostgroup"
301 "hostgroup_members"
302 "hostgroup_name"
303 "hostgroups"
304 "hosts"
305 "hourly_value"
306 "icon_image"
307 "icon_image_alt"
308 "importance"
309 "inherits_parent"
310 "initial_state"
311 "is_volatile"
312 "last_notification"
313 "low_flap_threshold"
314 "master_description"
315 "master_host"
316 "master_host_name"
317 "master_service_description"
318 "max_check_attempts"
319 "members"
320 "minimum_importance"
321 "minimum_value"
322 "monday"
323 "normal_check_interval"
324 "notes"
325 "notes_url"
326 "notification_failure_criteria"
327 "notification_failure_options"
328 "notification_interval"
329 "notification_options"
330 "notification_period"
331 "notifications_enabled"
332 "obsess"
333 "obsess_over_host"
334 "obsess_over_service"
335 "pager"
336 "parallelize_check"
337 "parents"
338 "passive_checks_enabled"
339 "process_perf_data"
340 "retain_nonstatus_information"
341 "retain_status_information"
342 "retry_check_interval"
343 "retry_interval"
344 "saturday"
345 "service_description"
346 "service_groups"
347 "service_notification_commands"
348 "service_notification_options"
349 "service_notification_period"
350 "service_notifications_enabled"
351 "servicegroup"
352 "servicegroup_members"
353 "servicegroup_name"
354 "servicegroups"
355 "stalking_options"
356 "statusmap_image"
357 "sunday"
358 "thursday"
359 "timeperiod_name"
360 "tuesday"
361 "vrml_image"
362 "wednesday") t)
363
364 "[ \r\n\t]+")
365 )
366 )
367
368
369
370 (defconst nagios-macros
371 (eval-when-compile
372 (regexp-opt
373 '("$ADMINEMAIL$"
374 "$ADMINPAGER$"
375 "$ARG1$"
376 "$ARG10$"
377 "$ARG11$"
378 "$ARG12$"
379 "$ARG13$"
380 "$ARG14$"
381 "$ARG15$"
382 "$ARG16$"
383 "$ARG17$"
384 "$ARG18$"
385 "$ARG19$"
386 "$ARG2$"
387 "$ARG20$"
388 "$ARG21$"
389 "$ARG22$"
390 "$ARG23$"
391 "$ARG24$"
392 "$ARG25$"
393 "$ARG26$"
394 "$ARG27$"
395 "$ARG28$"
396 "$ARG29$"
397 "$ARG3$"
398 "$ARG30$"
399 "$ARG31$"
400 "$ARG32$"
401 "$ARG4$"
402 "$ARG5$"
403 "$ARG6$"
404 "$ARG7$"
405 "$ARG8$"
406 "$ARG9$"
407 "$COMMANDFILE$"
408 "$CONTACTALIAS$"
409 "$CONTACTEMAIL$"
410 "$CONTACTGROUPALIAS$"
411 "$CONTACTGROUPMEMBERS$"
412 "$CONTACTGROUPNAME$"
413 "$CONTACTGROUPNAMES$"
414 "$CONTACTNAME$"
415 "$CONTACTPAGER$"
416 "$DATE$"
417 "$EVENTSTARTTIME$"
418 "$HOSTACKAUTHOR$"
419 "$HOSTACKAUTHORALIAS$"
420 "$HOSTACKAUTHORNAME$"
421 "$HOSTACKCOMMENT$"
422 "$HOSTACTIONURL$"
423 "$HOSTADDRESS$"
424 "$HOSTALIAS$"
425 "$HOSTANDSERVICESIMPORTANCE$"
426 "$HOSTATTEMPT$"
427 "$HOSTCHECKCOMMAND$"
428 "$HOSTCHECKTYPE$"
429 "$HOSTDISPLAYNAME$"
430 "$HOSTDOWNTIME$"
431 "$HOSTDURATION$"
432 "$HOSTDURATIONSEC$"
433 "$HOSTEVENTID$"
434 "$HOSTEXECUTIONTIME$"
435 "$HOSTGROUPACTIONURL$"
436 "$HOSTGROUPALIAS$"
437 "$HOSTGROUPMEMBERADDRESSES$"
438 "$HOSTGROUPMEMBERS$"
439 "$HOSTGROUPNAME$"
440 "$HOSTGROUPNAMES$"
441 "$HOSTGROUPNOTES$"
442 "$HOSTGROUPNOTESURL$"
443 "$HOSTIMPORTANCE$"
444 "$HOSTINFOURL$"
445 "$HOSTLATENCY$"
446 "$HOSTNAME$"
447 "$HOSTNOTES$"
448 "$HOSTNOTESURL$"
449 "$HOSTNOTIFICATIONENABLED$"
450 "$HOSTNOTIFICATIONID$"
451 "$HOSTNOTIFICATIONNUMBER$"
452 "$HOSTNOTIFICATIONPERIOD$"
453 "$HOSTOUTPUT$"
454 "$HOSTPERCENTCHANGE$"
455 "$HOSTPERFDATA$"
456 "$HOSTPERFDATAFILE$"
457 "$HOSTPROBLEMID$"
458 "$HOSTSTATE$"
459 "$HOSTSTATEID$"
460 "$HOSTSTATETYPE$"
461 "$ISVALIDTIME$"
462 "$LASTHOSTCHECK$"
463 "$LASTHOSTDOWN$"
464 "$LASTHOSTEVENTID$"
465 "$LASTHOSTPROBLEMID$"
466 "$LASTHOSTSTATE$"
467 "$LASTHOSTSTATECHANGE$"
468 "$LASTHOSTSTATEID$"
469 "$LASTHOSTUNREACHABLE$"
470 "$LASTHOSTUP$"
471 "$LASTSERVICECHECK$"
472 "$LASTSERVICECRITICAL$"
473 "$LASTSERVICEEVENTID$"
474 "$LASTSERVICEOK$"
475 "$LASTSERVICEPROBLEMID$"
476 "$LASTSERVICESTATE$"
477 "$LASTSERVICESTATECHANGE$"
478 "$LASTSERVICESTATEID$"
479 "$LASTSERVICEUNKNOWN$"
480 "$LASTSERVICEWARNING$"
481 "$LOGFILE$"
482 "$LONGDATETIME$"
483 "$LONGHOSTOUTPUT$"
484 "$LONGSERVICEOUTPUT$"
485 "$MAINCONFIGFILE$"
486 "$MAXHOSTATTEMPTS$"
487 "$MAXSERVICEATTEMPTS$"
488 "$NEXTVALIDTIME$"
489 "$NOTIFICATIONAUTHOR$"
490 "$NOTIFICATIONAUTHORALIAS$"
491 "$NOTIFICATIONAUTHORNAME$"
492 "$NOTIFICATIONCOMMENT$"
493 "$NOTIFICATIONISESCALATED$"
494 "$NOTIFICATIONNUMBER$"
495 "$NOTIFICATIONRECIPIENTS$"
496 "$NOTIFICATIONTYPE$"
497 "$OBJECTCACHEFILE$"
498 "$PROCESSSTARTTIME$"
499 "$RESOURCEFILE$"
500 "$RETENTIONDATAFILE$"
501 "$SERVICEACKAUTHOR$"
502 "$SERVICEACKAUTHORALIAS$"
503 "$SERVICEACKAUTHORNAME$"
504 "$SERVICEACKCOMMENT$"
505 "$SERVICEACTIONURL$"
506 "$SERVICEATTEMPT$"
507 "$SERVICECHECKCOMMAND$"
508 "$SERVICECHECKTYPE$"
509 "$SERVICEDESC$"
510 "$SERVICEDISPLAYNAME$"
511 "$SERVICEDOWNTIME$"
512 "$SERVICEDURATION$"
513 "$SERVICEDURATIONSEC$"
514 "$SERVICEEVENTID$"
515 "$SERVICEEXECUTIONTIME$"
516 "$SERVICEGROUPACTIONURL$"
517 "$SERVICEGROUPALIAS$"
518 "$SERVICEGROUPMEMBERS$"
519 "$SERVICEGROUPNAME$"
520 "$SERVICEGROUPNAMES$"
521 "$SERVICEGROUPNOTES$"
522 "$SERVICEGROUPNOTESURL$"
523 "$SERVICEIMPORTANCE$"
524 "$SERVICEINFOURL$"
525 "$SERVICEISVOLATILE$"
526 "$SERVICELATENCY$"
527 "$SERVICENOTES$"
528 "$SERVICENOTESURL$"
529 "$SERVICENOTIFICATIONENABLED$"
530 "$SERVICENOTIFICATIONID$"
531 "$SERVICENOTIFICATIONNUMBER$"
532 "$SERVICENOTIFICATIONPERIOD$"
533 "$SERVICEOUTPUT$"
534 "$SERVICEPERCENTCHANGE$"
535 "$SERVICEPERFDATA$"
536 "$SERVICEPERFDATAFILE$"
537 "$SERVICEPROBLEMID$"
538 "$SERVICESTATE$"
539 "$SERVICESTATEID$"
540 "$SERVICESTATETYPE$"
541 "$SHORTDATETIME$"
542 "$STATUSDATAFILE$"
543 "$TEMPFILE$"
544 "$TEMPPATH$"
545 "$TIME$"
546 "$TIMET$"
547 "$TOTALHOSTPROBLEMS$"
548 "$TOTALHOSTPROBLEMSUNHANDLED$"
549 "$TOTALHOSTSDOWN$"
550 "$TOTALHOSTSDOWNUNHANDLED$"
551 "$TOTALHOSTSERVICES$"
552 "$TOTALHOSTSERVICESCRITICAL$"
553 "$TOTALHOSTSERVICESOK$"
554 "$TOTALHOSTSERVICESUNKNOWN$"
555 "$TOTALHOSTSERVICESWARNING$"
556 "$TOTALHOSTSUNREACHABLE$"
557 "$TOTALHOSTSUNREACHABLEUNHANDLED$"
558 "$TOTALHOSTSUP$"
559 "$TOTALSERVICEPROBLEMS$"
560 "$TOTALSERVICEPROBLEMSUNHANDLED$"
561 "$TOTALSERVICESCRITICAL$"
562 "$TOTALSERVICESCRITICALUNHANDLED$"
563 "$TOTALSERVICESOK$"
564 "$TOTALSERVICESUNKNOWN$"
565 "$TOTALSERVICESUNKNOWNUNHANDLED$"
566 "$TOTALSERVICESWARNING$"
567 "$TOTALSERVICESWARNINGUNHANDLED$"
568 "$USER1$"
569 "$USER10$"
570 "$USER100$"
571 "$USER101$"
572 "$USER102$"
573 "$USER103$"
574 "$USER104$"
575 "$USER105$"
576 "$USER106$"
577 "$USER107$"
578 "$USER108$"
579 "$USER109$"
580 "$USER11$"
581 "$USER110$"
582 "$USER111$"
583 "$USER112$"
584 "$USER113$"
585 "$USER114$"
586 "$USER115$"
587 "$USER116$"
588 "$USER117$"
589 "$USER118$"
590 "$USER119$"
591 "$USER12$"
592 "$USER120$"
593 "$USER121$"
594 "$USER122$"
595 "$USER123$"
596 "$USER124$"
597 "$USER125$"
598 "$USER126$"
599 "$USER127$"
600 "$USER128$"
601 "$USER129$"
602 "$USER13$"
603 "$USER130$"
604 "$USER131$"
605 "$USER132$"
606 "$USER133$"
607 "$USER134$"
608 "$USER135$"
609 "$USER136$"
610 "$USER137$"
611 "$USER138$"
612 "$USER139$"
613 "$USER14$"
614 "$USER140$"
615 "$USER141$"
616 "$USER142$"
617 "$USER143$"
618 "$USER144$"
619 "$USER145$"
620 "$USER146$"
621 "$USER147$"
622 "$USER148$"
623 "$USER149$"
624 "$USER15$"
625 "$USER150$"
626 "$USER151$"
627 "$USER152$"
628 "$USER153$"
629 "$USER154$"
630 "$USER155$"
631 "$USER156$"
632 "$USER157$"
633 "$USER158$"
634 "$USER159$"
635 "$USER16$"
636 "$USER160$"
637 "$USER161$"
638 "$USER162$"
639 "$USER163$"
640 "$USER164$"
641 "$USER165$"
642 "$USER166$"
643 "$USER167$"
644 "$USER168$"
645 "$USER169$"
646 "$USER17$"
647 "$USER170$"
648 "$USER171$"
649 "$USER172$"
650 "$USER173$"
651 "$USER174$"
652 "$USER175$"
653 "$USER176$"
654 "$USER177$"
655 "$USER178$"
656 "$USER179$"
657 "$USER18$"
658 "$USER180$"
659 "$USER181$"
660 "$USER182$"
661 "$USER183$"
662 "$USER184$"
663 "$USER185$"
664 "$USER186$"
665 "$USER187$"
666 "$USER188$"
667 "$USER189$"
668 "$USER19$"
669 "$USER190$"
670 "$USER191$"
671 "$USER192$"
672 "$USER193$"
673 "$USER194$"
674 "$USER195$"
675 "$USER196$"
676 "$USER197$"
677 "$USER198$"
678 "$USER199$"
679 "$USER2$"
680 "$USER20$"
681 "$USER200$"
682 "$USER201$"
683 "$USER202$"
684 "$USER203$"
685 "$USER204$"
686 "$USER205$"
687 "$USER206$"
688 "$USER207$"
689 "$USER208$"
690 "$USER209$"
691 "$USER21$"
692 "$USER210$"
693 "$USER211$"
694 "$USER212$"
695 "$USER213$"
696 "$USER214$"
697 "$USER215$"
698 "$USER216$"
699 "$USER217$"
700 "$USER218$"
701 "$USER219$"
702 "$USER22$"
703 "$USER220$"
704 "$USER221$"
705 "$USER222$"
706 "$USER223$"
707 "$USER224$"
708 "$USER225$"
709 "$USER226$"
710 "$USER227$"
711 "$USER228$"
712 "$USER229$"
713 "$USER23$"
714 "$USER230$"
715 "$USER231$"
716 "$USER232$"
717 "$USER233$"
718 "$USER234$"
719 "$USER235$"
720 "$USER236$"
721 "$USER237$"
722 "$USER238$"
723 "$USER239$"
724 "$USER24$"
725 "$USER240$"
726 "$USER241$"
727 "$USER242$"
728 "$USER243$"
729 "$USER244$"
730 "$USER245$"
731 "$USER246$"
732 "$USER247$"
733 "$USER248$"
734 "$USER249$"
735 "$USER25$"
736 "$USER250$"
737 "$USER251$"
738 "$USER252$"
739 "$USER253$"
740 "$USER254$"
741 "$USER255$"
742 "$USER256$"
743 "$USER26$"
744 "$USER27$"
745 "$USER28$"
746 "$USER29$"
747 "$USER3$"
748 "$USER30$"
749 "$USER31$"
750 "$USER32$"
751 "$USER33$"
752 "$USER34$"
753 "$USER35$"
754 "$USER36$"
755 "$USER37$"
756 "$USER38$"
757 "$USER39$"
758 "$USER4$"
759 "$USER40$"
760 "$USER41$"
761 "$USER42$"
762 "$USER43$"
763 "$USER44$"
764 "$USER45$"
765 "$USER46$"
766 "$USER47$"
767 "$USER48$"
768 "$USER49$"
769 "$USER5$"
770 "$USER50$"
771 "$USER51$"
772 "$USER52$"
773 "$USER53$"
774 "$USER54$"
775 "$USER55$"
776 "$USER56$"
777 "$USER57$"
778 "$USER58$"
779 "$USER59$"
780 "$USER6$"
781 "$USER60$"
782 "$USER61$"
783 "$USER62$"
784 "$USER63$"
785 "$USER64$"
786 "$USER65$"
787 "$USER66$"
788 "$USER67$"
789 "$USER68$"
790 "$USER69$"
791 "$USER7$"
792 "$USER70$"
793 "$USER71$"
794 "$USER72$"
795 "$USER73$"
796 "$USER74$"
797 "$USER75$"
798 "$USER76$"
799 "$USER77$"
800 "$USER78$"
801 "$USER79$"
802 "$USER8$"
803 "$USER80$"
804 "$USER81$"
805 "$USER82$"
806 "$USER83$"
807 "$USER84$"
808 "$USER85$"
809 "$USER86$"
810 "$USER87$"
811 "$USER88$"
812 "$USER89$"
813 "$USER9$"
814 "$USER90$"
815 "$USER91$"
816 "$USER92$"
817 "$USER93$"
818 "$USER94$"
819 "$USER95$"
820 "$USER96$"
821 "$USER97$"
822 "$USER98$"
823 "$USER99$")))
824 )
825
826
827
828 (defconst nagios-definitions
829 (eval-when-compile
830
831 (concat "^[ \t\r\n]*"
832
833 "\\(" ;; Stick parenthesis around whatever comes out
834 ;; of regexp-opt. We use this to match a
835 ;; subexpression during font-lock.
836 (regexp-opt
837 '("define command"
838 "define contact"
839 "define contactgroup"
840 "define host"
841 "define hostdependency"
842 "define hostescalation"
843 "define hostextinfo"
844 "define hostgroup"
845 "define null"
846 "define service"
847 "define servicedependency"
848 "define serviceescalation"
849 "define serviceextinfo"
850 "define servicegroup"
851 "define timeperiod"))
852 ;; This closes the parentheses that we opened
853 "\\)" ;; before regexp-opt.
854
855 ;; These can be "terminated" by either an opening curly
856 ;; brace, or a space.
857 "\\({\\| \\)")
858 )
859 )
860
861
862
863 (defconst nagios-special
864 (eval-when-compile
865 (concat "^[ \t\r\n]*"
866
867 (regexp-opt
868 '("name" "register" "use") t)
869
870 "[ \r\n\t]+"))
871 )
872
873
874
875 ;; The One True Font Locking Variable
876
877 (defvar nagios-font-lock-keywords
878 (list
879 (cons nagios-special font-lock-keyword-face)
880 (cons nagios-directives font-lock-variable-name-face)
881 (cons nagios-macros font-lock-constant-face)
882 (cons nagios-definitions '(1 font-lock-function-name-face)))
883
884 "Rules for highlighting Nagios configuration files."
885 )
886
887
888
889 (defvar nagios-mode-syntax-table nil
890 "Syntax table used in nagios-mode buffers.")
891 (if nagios-mode-syntax-table
892 nil
893 (setq nagios-mode-syntax-table (make-syntax-table))
894 (modify-syntax-entry ?# "< b" nagios-mode-syntax-table) ;; Comment style 1
895 (modify-syntax-entry ?\; "< b" nagios-mode-syntax-table) ;; Comment style 2
896 (modify-syntax-entry ?\n "> b" nagios-mode-syntax-table) ;; End comment
897 )
898
899
900 ;; Main Mode Function
901
902 (defun nagios-mode()
903 "Major mode for editing Nagios configuration files."
904
905 (interactive)
906 (kill-all-local-variables)
907 (make-local-variable 'font-lock-defaults)
908 (make-local-variable 'comment-start)
909 (make-local-variable 'comment-start-skip)
910 (make-local-variable 'comment-end)
911 (make-local-variable 'indent-line-function)
912
913 (set-syntax-table nagios-mode-syntax-table)
914
915 (setq mode-name "nagios"
916 major-mode 'nagios-mode
917 indent-line-function 'nagios-indent-line
918 font-lock-defaults '(nagios-font-lock-keywords)
919 comment-start "#"
920 comment-start-skip "#\|; +"
921 comment-end ""
922 )
923
924 ;; Keyboard Mapping
925 (use-local-map nagios-mode-map)
926
927 ;; I don't /think/ I need to define this before attempting
928 ;; to run it. Users can define it if they want.
929 (run-hooks 'nagios-mode-hook)
930 )
931
932
933 (provide 'nagios-mode)