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