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