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