X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=nagios-mode.el;h=6b2d1d12a3ded7159559539603d19aa6021f5cb6;hb=f5456f838c2441f40a58d34515fa4bd389bc2259;hp=e1573345a61670b5fb8a9989d3abf622c367ecf4;hpb=eb979cc1755ca7cf5b42f0ec401777fd6a1c50ee;p=nagios-mode.git diff --git a/nagios-mode.el b/nagios-mode.el index e157334..6b2d1d1 100644 --- a/nagios-mode.el +++ b/nagios-mode.el @@ -155,27 +155,6 @@ ;; Regular Expression Transformations -(defun regexp-word(regexp) - "Takes a regular expression as an argument, and adds the word boundary condition to the beginning and end of it. Newlines are treated as word boundaries." - - ;; This basically joins two expressions in an alternation. - ;; The first allows for a newline followed by our regexp (on - ;; a word boundary), and the second checks for any-non-word - ;; character followed by our regexp. - ;; - ;; I consider neither a hyphen nor an underscore to be a word - ;; boundary for the purpose of syntax highlighting, so I stick - ;; the no-hyphens-or-underscores class on each end of the - ;; expressions. - - (concat "\\(" - (concat "\\(^\\<\\(" regexp "\\)\\>[^_-]\\)") - "\\|" - (concat "\\([^_-]\\<\\(" regexp "\\)\\>[^_-]\\)") - "\\)") - ) - - (defun regexp-alt-raw(element-list) "Takes a list of elements, and returns the string '\\(element1\\|element2...\\)'" @@ -194,28 +173,20 @@ -;; Syntax Highlighting Patterns - -(defconst nagios-comments - (eval-when-compile - (regexp-alt-raw - '("#+.*" - ";+.*"))) - ) - - (defconst nagios-directives (eval-when-compile + (concat "^[ \t\r\n]*" + (regexp-opt '("active_checks_enabled" "address" "alias" "check_command" "check_freshness" "check_interval" "check_period" "checks_enabled" - "command_line" "command_name" "contact_groups" "contact_name" - "contactgroup_name" "contacts" "dependent_host_name" - "dependent_service_description" "email" "event_handler" - "event_handler_enabled" "execution_failure_criteria" + "command_line" "command_name" "contactgroups" "contact_groups" + "contactgroup_members" "contact_name" "contactgroup_name" "contacts" + "dependent_host_name" "dependent_service_description" "email" + "event_handler" "event_handler_enabled" "execution_failure_criteria" "failure_prediction_enabled" "first_notification" - "flap_detection_enabled" "freshness_threshold" "friday" - "high_flap_threshold" "host_name" "host_notification_commands" + "first_notification_delay" "flap_detection_enabled" "freshness_threshold" + "friday" "high_flap_threshold" "host_name" "host_notification_commands" "host_notification_options" "host_notification_period" "host_notifications_enabled" "hostgroup_name" "hostgroups" "is_volatile" "last_notification" "low_flap_threshold" @@ -231,9 +202,12 @@ "service_notification_commands" "service_notification_options" "service_notification_period" "service_notifications_enabled" "servicegroup_name" "stalking_options" - "sunday" "thursday" "timeperiod_name" "tuesday" "wednesday") t)) + "sunday" "thursday" "timeperiod_name" "tuesday" "wednesday") t) + + "[ \r\n\t]+") + ) ) - + (defconst nagios-macros @@ -255,19 +229,31 @@ (defconst nagios-definitions (eval-when-compile + + (concat "^[ \t\r\n]*" + (regexp-alt-raw '("define +\\(host\\|service\\|timeperiod\\|contact\\|command\\)" "define +\\(host\\|contact\\|service\\)group" "define +\\(service\\|host\\)dependency" - "define +\\(service\\|host\\|hostgroup\\)escalation"))) + "define +\\(service\\|host\\|hostgroup\\)escalation")) + + ;; These can be "terminated" by either an opening curly + ;; brace, or a space. + "\\({\\| \\)") + ) ) (defconst nagios-special (eval-when-compile + (concat "^[ \t\r\n]*" + (regexp-opt - '("name" "register" "use") t)) + '("name" "register" "use") t) + + "[ \r\n\t]+")) ) @@ -276,50 +262,59 @@ (defvar nagios-font-lock-keywords (list + (cons nagios-special font-lock-keyword-face) + (cons nagios-directives font-lock-variable-name-face) + (cons nagios-macros font-lock-constant-face) + (cons nagios-definitions '(1 font-lock-function-name-face))) - ;; This first bit of ugliness allows us to override any - ;; other font-locking with the comment font. - (cons nagios-comments '(0 font-lock-comment-delimiter-face t)) - - ;; The rest just map regular expressions to font faces. - (cons (regexp-word nagios-directives) font-lock-variable-name-face) - (cons (regexp-word nagios-macros) font-lock-constant-face) - (cons (regexp-word nagios-definitions) font-lock-function-name-face) - (cons (regexp-word nagios-special) font-lock-keyword-face)) - "Rules for highlighting Nagios configuration files." ) +(defvar nagios-mode-syntax-table nil + "Syntax table used in nagios-mode buffers.") +(if nagios-mode-syntax-table + nil + (setq nagios-mode-syntax-table (make-syntax-table)) + (modify-syntax-entry ?# "< b" nagios-mode-syntax-table) ;; Comment style 1 + (modify-syntax-entry ?\; "< b" nagios-mode-syntax-table) ;; Comment style 2 + (modify-syntax-entry ?\n "> b" nagios-mode-syntax-table) ;; End comment + ) + + ;; Main Mode Function (defun nagios-mode() "Major mode for editing Nagios configuration files." (interactive) - - ;; Initializing. This is actually important to cover - ;; up some Emacs stupidity. Font locking won't occur - ;; without it. (kill-all-local-variables) - - ;; Set up indentation handling using the functions - ;; defined earlier. + (make-local-variable 'font-lock-defaults) + (make-local-variable 'comment-start) + (make-local-variable 'comment-start-skip) + (make-local-variable 'comment-end) (make-local-variable 'indent-line-function) - (setq indent-line-function 'nagios-indent-line) + (make-local-variable 'syntax-begin-function) + + (set-syntax-table nagios-mode-syntax-table) - ;; Configure font locking. Set the defaults to something - ;; sensible, defined earlier. - (make-local-variable 'font-lock-defaults) - (setq font-lock-defaults '(nagios-font-lock-keywords nil t)) + (setq mode-name "nagios" + major-mode 'nagios-mode + indent-line-function 'nagios-indent-line + font-lock-defaults '(nagios-font-lock-keywords) + comment-start "#" + comment-start-skip "#\|; +" + comment-end "" + + ;; Since comments and strings do not span multiple lines, + ;; the syntax parser can safely start parsing at the beginning + ;; of any line. + syntax-begin-function 'beginning-of-line + ) ;; Keyboard Mapping (use-local-map nagios-mode-map) - - ;; Rock and roll. - (setq mode-name "nagios" - major-mode 'nagios-mode) ;; I don't /think/ I need to define this before attempting ;; to run it. Users can define it if they want.