]> gitweb.michael.orlitzky.com - nagios-mode.git/blob - nagios-mode.el
nagios-mode.el: move directives to their own lines for easy diffing.
[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 '("active_checks_enabled"
246 "address"
247 "alias"
248 "check_command"
249 "check_freshness"
250 "check_interval"
251 "check_period"
252 "checks_enabled"
253 "command_line"
254 "command_name"
255 "contactgroups"
256 "contact_groups"
257 "contactgroup_members"
258 "contact_name"
259 "contactgroup_name"
260 "contacts"
261 "dependent_host_name"
262 "dependent_service_description"
263 "email"
264 "event_handler"
265 "event_handler_enabled"
266 "execution_failure_criteria"
267 "failure_prediction_enabled"
268 "first_notification"
269 "first_notification_delay"
270 "flap_detection_enabled"
271 "freshness_threshold"
272 "friday"
273 "high_flap_threshold"
274 "host_name"
275 "host_notification_commands"
276 "host_notification_options"
277 "host_notification_period"
278 "host_notifications_enabled"
279 "hostgroup_name"
280 "hostgroups"
281 "is_volatile"
282 "last_notification"
283 "low_flap_threshold"
284 "max_check_attempts"
285 "members"
286 "monday"
287 "normal_check_interval"
288 "notes"
289 "notification_failure_criteria"
290 "notification_interval"
291 "notification_options"
292 "notification_period"
293 "notifications_enabled"
294 "obsess_over_service"
295 "pager"
296 "parallelize_check"
297 "parents"
298 "passive_checks_enabled"
299 "process_perf_data"
300 "retain_nonstatus_information"
301 "retain_status_information"
302 "retry_check_interval"
303 "retry_interval"
304 "saturday"
305 "service_description"
306 "service_notification_commands"
307 "service_notification_options"
308 "service_notification_period"
309 "service_notifications_enabled"
310 "servicegroup_name"
311 "stalking_options"
312 "sunday"
313 "thursday"
314 "timeperiod_name"
315 "tuesday"
316 "wednesday") t)
317
318 "[ \r\n\t]+")
319 )
320 )
321
322
323
324 (defconst nagios-macros
325 (eval-when-compile
326 (regexp-opt
327 '("$ADMINEMAIL$"
328 "$ADMINPAGER$"
329 "$ARG1$"
330 "$ARG10$"
331 "$ARG11$"
332 "$ARG12$"
333 "$ARG13$"
334 "$ARG14$"
335 "$ARG15$"
336 "$ARG16$"
337 "$ARG17$"
338 "$ARG18$"
339 "$ARG19$"
340 "$ARG2$"
341 "$ARG20$"
342 "$ARG21$"
343 "$ARG22$"
344 "$ARG23$"
345 "$ARG24$"
346 "$ARG25$"
347 "$ARG26$"
348 "$ARG27$"
349 "$ARG28$"
350 "$ARG29$"
351 "$ARG3$"
352 "$ARG30$"
353 "$ARG31$"
354 "$ARG32$"
355 "$ARG4$"
356 "$ARG5$"
357 "$ARG6$"
358 "$ARG7$"
359 "$ARG8$"
360 "$ARG9$"
361 "$COMMANDFILE$"
362 "$CONTACTALIAS$"
363 "$CONTACTEMAIL$"
364 "$CONTACTGROUPALIAS$"
365 "$CONTACTGROUPMEMBERS$"
366 "$CONTACTGROUPNAME$"
367 "$CONTACTGROUPNAMES$"
368 "$CONTACTNAME$"
369 "$CONTACTPAGER$"
370 "$DATE$"
371 "$EVENTSTARTTIME$"
372 "$HOSTACKAUTHOR$"
373 "$HOSTACKAUTHORALIAS$"
374 "$HOSTACKAUTHORNAME$"
375 "$HOSTACKCOMMENT$"
376 "$HOSTACTIONURL$"
377 "$HOSTADDRESS$"
378 "$HOSTALIAS$"
379 "$HOSTANDSERVICESIMPORTANCE$"
380 "$HOSTATTEMPT$"
381 "$HOSTCHECKCOMMAND$"
382 "$HOSTCHECKTYPE$"
383 "$HOSTDISPLAYNAME$"
384 "$HOSTDOWNTIME$"
385 "$HOSTDURATION$"
386 "$HOSTDURATIONSEC$"
387 "$HOSTEVENTID$"
388 "$HOSTEXECUTIONTIME$"
389 "$HOSTGROUPACTIONURL$"
390 "$HOSTGROUPALIAS$"
391 "$HOSTGROUPMEMBERADDRESSES$"
392 "$HOSTGROUPMEMBERS$"
393 "$HOSTGROUPNAME$"
394 "$HOSTGROUPNAMES$"
395 "$HOSTGROUPNOTES$"
396 "$HOSTGROUPNOTESURL$"
397 "$HOSTIMPORTANCE$"
398 "$HOSTINFOURL$"
399 "$HOSTLATENCY$"
400 "$HOSTNAME$"
401 "$HOSTNOTES$"
402 "$HOSTNOTESURL$"
403 "$HOSTNOTIFICATIONENABLED$"
404 "$HOSTNOTIFICATIONID$"
405 "$HOSTNOTIFICATIONNUMBER$"
406 "$HOSTNOTIFICATIONPERIOD$"
407 "$HOSTOUTPUT$"
408 "$HOSTPERCENTCHANGE$"
409 "$HOSTPERFDATA$"
410 "$HOSTPERFDATAFILE$"
411 "$HOSTPROBLEMID$"
412 "$HOSTSTATE$"
413 "$HOSTSTATEID$"
414 "$HOSTSTATETYPE$"
415 "$ISVALIDTIME$"
416 "$LASTHOSTCHECK$"
417 "$LASTHOSTDOWN$"
418 "$LASTHOSTEVENTID$"
419 "$LASTHOSTPROBLEMID$"
420 "$LASTHOSTSTATE$"
421 "$LASTHOSTSTATECHANGE$"
422 "$LASTHOSTSTATEID$"
423 "$LASTHOSTUNREACHABLE$"
424 "$LASTHOSTUP$"
425 "$LASTSERVICECHECK$"
426 "$LASTSERVICECRITICAL$"
427 "$LASTSERVICEEVENTID$"
428 "$LASTSERVICEOK$"
429 "$LASTSERVICEPROBLEMID$"
430 "$LASTSERVICESTATE$"
431 "$LASTSERVICESTATECHANGE$"
432 "$LASTSERVICESTATEID$"
433 "$LASTSERVICEUNKNOWN$"
434 "$LASTSERVICEWARNING$"
435 "$LOGFILE$"
436 "$LONGDATETIME$"
437 "$LONGHOSTOUTPUT$"
438 "$LONGSERVICEOUTPUT$"
439 "$MAINCONFIGFILE$"
440 "$MAXHOSTATTEMPTS$"
441 "$MAXSERVICEATTEMPTS$"
442 "$NEXTVALIDTIME$"
443 "$NOTIFICATIONAUTHOR$"
444 "$NOTIFICATIONAUTHORALIAS$"
445 "$NOTIFICATIONAUTHORNAME$"
446 "$NOTIFICATIONCOMMENT$"
447 "$NOTIFICATIONISESCALATED$"
448 "$NOTIFICATIONNUMBER$"
449 "$NOTIFICATIONRECIPIENTS$"
450 "$NOTIFICATIONTYPE$"
451 "$OBJECTCACHEFILE$"
452 "$PROCESSSTARTTIME$"
453 "$RESOURCEFILE$"
454 "$RETENTIONDATAFILE$"
455 "$SERVICEACKAUTHOR$"
456 "$SERVICEACKAUTHORALIAS$"
457 "$SERVICEACKAUTHORNAME$"
458 "$SERVICEACKCOMMENT$"
459 "$SERVICEACTIONURL$"
460 "$SERVICEATTEMPT$"
461 "$SERVICECHECKCOMMAND$"
462 "$SERVICECHECKTYPE$"
463 "$SERVICEDESC$"
464 "$SERVICEDISPLAYNAME$"
465 "$SERVICEDOWNTIME$"
466 "$SERVICEDURATION$"
467 "$SERVICEDURATIONSEC$"
468 "$SERVICEEVENTID$"
469 "$SERVICEEXECUTIONTIME$"
470 "$SERVICEGROUPACTIONURL$"
471 "$SERVICEGROUPALIAS$"
472 "$SERVICEGROUPMEMBERS$"
473 "$SERVICEGROUPNAME$"
474 "$SERVICEGROUPNAMES$"
475 "$SERVICEGROUPNOTES$"
476 "$SERVICEGROUPNOTESURL$"
477 "$SERVICEIMPORTANCE$"
478 "$SERVICEINFOURL$"
479 "$SERVICEISVOLATILE$"
480 "$SERVICELATENCY$"
481 "$SERVICENOTES$"
482 "$SERVICENOTESURL$"
483 "$SERVICENOTIFICATIONENABLED$"
484 "$SERVICENOTIFICATIONID$"
485 "$SERVICENOTIFICATIONNUMBER$"
486 "$SERVICENOTIFICATIONPERIOD$"
487 "$SERVICEOUTPUT$"
488 "$SERVICEPERCENTCHANGE$"
489 "$SERVICEPERFDATA$"
490 "$SERVICEPERFDATAFILE$"
491 "$SERVICEPROBLEMID$"
492 "$SERVICESTATE$"
493 "$SERVICESTATEID$"
494 "$SERVICESTATETYPE$"
495 "$SHORTDATETIME$"
496 "$STATUSDATAFILE$"
497 "$TEMPFILE$"
498 "$TEMPPATH$"
499 "$TIME$"
500 "$TIMET$"
501 "$TOTALHOSTPROBLEMS$"
502 "$TOTALHOSTPROBLEMSUNHANDLED$"
503 "$TOTALHOSTSDOWN$"
504 "$TOTALHOSTSDOWNUNHANDLED$"
505 "$TOTALHOSTSERVICES$"
506 "$TOTALHOSTSERVICESCRITICAL$"
507 "$TOTALHOSTSERVICESOK$"
508 "$TOTALHOSTSERVICESUNKNOWN$"
509 "$TOTALHOSTSERVICESWARNING$"
510 "$TOTALHOSTSUNREACHABLE$"
511 "$TOTALHOSTSUNREACHABLEUNHANDLED$"
512 "$TOTALHOSTSUP$"
513 "$TOTALSERVICEPROBLEMS$"
514 "$TOTALSERVICEPROBLEMSUNHANDLED$"
515 "$TOTALSERVICESCRITICAL$"
516 "$TOTALSERVICESCRITICALUNHANDLED$"
517 "$TOTALSERVICESOK$"
518 "$TOTALSERVICESUNKNOWN$"
519 "$TOTALSERVICESUNKNOWNUNHANDLED$"
520 "$TOTALSERVICESWARNING$"
521 "$TOTALSERVICESWARNINGUNHANDLED$"
522 "$USER1$"
523 "$USER10$"
524 "$USER100$"
525 "$USER101$"
526 "$USER102$"
527 "$USER103$"
528 "$USER104$"
529 "$USER105$"
530 "$USER106$"
531 "$USER107$"
532 "$USER108$"
533 "$USER109$"
534 "$USER11$"
535 "$USER110$"
536 "$USER111$"
537 "$USER112$"
538 "$USER113$"
539 "$USER114$"
540 "$USER115$"
541 "$USER116$"
542 "$USER117$"
543 "$USER118$"
544 "$USER119$"
545 "$USER12$"
546 "$USER120$"
547 "$USER121$"
548 "$USER122$"
549 "$USER123$"
550 "$USER124$"
551 "$USER125$"
552 "$USER126$"
553 "$USER127$"
554 "$USER128$"
555 "$USER129$"
556 "$USER13$"
557 "$USER130$"
558 "$USER131$"
559 "$USER132$"
560 "$USER133$"
561 "$USER134$"
562 "$USER135$"
563 "$USER136$"
564 "$USER137$"
565 "$USER138$"
566 "$USER139$"
567 "$USER14$"
568 "$USER140$"
569 "$USER141$"
570 "$USER142$"
571 "$USER143$"
572 "$USER144$"
573 "$USER145$"
574 "$USER146$"
575 "$USER147$"
576 "$USER148$"
577 "$USER149$"
578 "$USER15$"
579 "$USER150$"
580 "$USER151$"
581 "$USER152$"
582 "$USER153$"
583 "$USER154$"
584 "$USER155$"
585 "$USER156$"
586 "$USER157$"
587 "$USER158$"
588 "$USER159$"
589 "$USER16$"
590 "$USER160$"
591 "$USER161$"
592 "$USER162$"
593 "$USER163$"
594 "$USER164$"
595 "$USER165$"
596 "$USER166$"
597 "$USER167$"
598 "$USER168$"
599 "$USER169$"
600 "$USER17$"
601 "$USER170$"
602 "$USER171$"
603 "$USER172$"
604 "$USER173$"
605 "$USER174$"
606 "$USER175$"
607 "$USER176$"
608 "$USER177$"
609 "$USER178$"
610 "$USER179$"
611 "$USER18$"
612 "$USER180$"
613 "$USER181$"
614 "$USER182$"
615 "$USER183$"
616 "$USER184$"
617 "$USER185$"
618 "$USER186$"
619 "$USER187$"
620 "$USER188$"
621 "$USER189$"
622 "$USER19$"
623 "$USER190$"
624 "$USER191$"
625 "$USER192$"
626 "$USER193$"
627 "$USER194$"
628 "$USER195$"
629 "$USER196$"
630 "$USER197$"
631 "$USER198$"
632 "$USER199$"
633 "$USER2$"
634 "$USER20$"
635 "$USER200$"
636 "$USER201$"
637 "$USER202$"
638 "$USER203$"
639 "$USER204$"
640 "$USER205$"
641 "$USER206$"
642 "$USER207$"
643 "$USER208$"
644 "$USER209$"
645 "$USER21$"
646 "$USER210$"
647 "$USER211$"
648 "$USER212$"
649 "$USER213$"
650 "$USER214$"
651 "$USER215$"
652 "$USER216$"
653 "$USER217$"
654 "$USER218$"
655 "$USER219$"
656 "$USER22$"
657 "$USER220$"
658 "$USER221$"
659 "$USER222$"
660 "$USER223$"
661 "$USER224$"
662 "$USER225$"
663 "$USER226$"
664 "$USER227$"
665 "$USER228$"
666 "$USER229$"
667 "$USER23$"
668 "$USER230$"
669 "$USER231$"
670 "$USER232$"
671 "$USER233$"
672 "$USER234$"
673 "$USER235$"
674 "$USER236$"
675 "$USER237$"
676 "$USER238$"
677 "$USER239$"
678 "$USER24$"
679 "$USER240$"
680 "$USER241$"
681 "$USER242$"
682 "$USER243$"
683 "$USER244$"
684 "$USER245$"
685 "$USER246$"
686 "$USER247$"
687 "$USER248$"
688 "$USER249$"
689 "$USER25$"
690 "$USER250$"
691 "$USER251$"
692 "$USER252$"
693 "$USER253$"
694 "$USER254$"
695 "$USER255$"
696 "$USER256$"
697 "$USER26$"
698 "$USER27$"
699 "$USER28$"
700 "$USER29$"
701 "$USER3$"
702 "$USER30$"
703 "$USER31$"
704 "$USER32$"
705 "$USER33$"
706 "$USER34$"
707 "$USER35$"
708 "$USER36$"
709 "$USER37$"
710 "$USER38$"
711 "$USER39$"
712 "$USER4$"
713 "$USER40$"
714 "$USER41$"
715 "$USER42$"
716 "$USER43$"
717 "$USER44$"
718 "$USER45$"
719 "$USER46$"
720 "$USER47$"
721 "$USER48$"
722 "$USER49$"
723 "$USER5$"
724 "$USER50$"
725 "$USER51$"
726 "$USER52$"
727 "$USER53$"
728 "$USER54$"
729 "$USER55$"
730 "$USER56$"
731 "$USER57$"
732 "$USER58$"
733 "$USER59$"
734 "$USER6$"
735 "$USER60$"
736 "$USER61$"
737 "$USER62$"
738 "$USER63$"
739 "$USER64$"
740 "$USER65$"
741 "$USER66$"
742 "$USER67$"
743 "$USER68$"
744 "$USER69$"
745 "$USER7$"
746 "$USER70$"
747 "$USER71$"
748 "$USER72$"
749 "$USER73$"
750 "$USER74$"
751 "$USER75$"
752 "$USER76$"
753 "$USER77$"
754 "$USER78$"
755 "$USER79$"
756 "$USER8$"
757 "$USER80$"
758 "$USER81$"
759 "$USER82$"
760 "$USER83$"
761 "$USER84$"
762 "$USER85$"
763 "$USER86$"
764 "$USER87$"
765 "$USER88$"
766 "$USER89$"
767 "$USER9$"
768 "$USER90$"
769 "$USER91$"
770 "$USER92$"
771 "$USER93$"
772 "$USER94$"
773 "$USER95$"
774 "$USER96$"
775 "$USER97$"
776 "$USER98$"
777 "$USER99$")))
778 )
779
780
781
782 (defconst nagios-definitions
783 (eval-when-compile
784
785 (concat "^[ \t\r\n]*"
786
787 "\\(" ;; Stick parenthesis around whatever comes out
788 ;; of regexp-opt. We use this to match a
789 ;; subexpression during font-lock.
790 (regexp-opt
791 '("define command"
792 "define contact"
793 "define contactgroup"
794 "define host"
795 "define hostdependency"
796 "define hostescalation"
797 "define hostextinfo"
798 "define hostgroup"
799 "define null"
800 "define service"
801 "define servicedependency"
802 "define serviceescalation"
803 "define serviceextinfo"
804 "define servicegroup"
805 "define timeperiod"))
806 ;; This closes the parentheses that we opened
807 "\\)" ;; before regexp-opt.
808
809 ;; These can be "terminated" by either an opening curly
810 ;; brace, or a space.
811 "\\({\\| \\)")
812 )
813 )
814
815
816
817 (defconst nagios-special
818 (eval-when-compile
819 (concat "^[ \t\r\n]*"
820
821 (regexp-opt
822 '("name" "register" "use") t)
823
824 "[ \r\n\t]+"))
825 )
826
827
828
829 ;; The One True Font Locking Variable
830
831 (defvar nagios-font-lock-keywords
832 (list
833 (cons nagios-special font-lock-keyword-face)
834 (cons nagios-directives font-lock-variable-name-face)
835 (cons nagios-macros font-lock-constant-face)
836 (cons nagios-definitions '(1 font-lock-function-name-face)))
837
838 "Rules for highlighting Nagios configuration files."
839 )
840
841
842
843 (defvar nagios-mode-syntax-table nil
844 "Syntax table used in nagios-mode buffers.")
845 (if nagios-mode-syntax-table
846 nil
847 (setq nagios-mode-syntax-table (make-syntax-table))
848 (modify-syntax-entry ?# "< b" nagios-mode-syntax-table) ;; Comment style 1
849 (modify-syntax-entry ?\; "< b" nagios-mode-syntax-table) ;; Comment style 2
850 (modify-syntax-entry ?\n "> b" nagios-mode-syntax-table) ;; End comment
851 )
852
853
854 ;; Main Mode Function
855
856 (defun nagios-mode()
857 "Major mode for editing Nagios configuration files."
858
859 (interactive)
860 (kill-all-local-variables)
861 (make-local-variable 'font-lock-defaults)
862 (make-local-variable 'comment-start)
863 (make-local-variable 'comment-start-skip)
864 (make-local-variable 'comment-end)
865 (make-local-variable 'indent-line-function)
866
867 (set-syntax-table nagios-mode-syntax-table)
868
869 (setq mode-name "nagios"
870 major-mode 'nagios-mode
871 indent-line-function 'nagios-indent-line
872 font-lock-defaults '(nagios-font-lock-keywords)
873 comment-start "#"
874 comment-start-skip "#\|; +"
875 comment-end ""
876 )
877
878 ;; Keyboard Mapping
879 (use-local-map nagios-mode-map)
880
881 ;; I don't /think/ I need to define this before attempting
882 ;; to run it. Users can define it if they want.
883 (run-hooks 'nagios-mode-hook)
884 )
885
886
887 (provide 'nagios-mode)