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