;; 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...\\)'"
(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"
"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
(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]+"))
)
(defvar nagios-font-lock-keywords
(list
- ;; 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))
+ (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 font-lock-function-name-face)
+
+ ;; We have to (override) un-color the curly braces here because it's
+ ;; possible for them to become colored along with a definition
+ ;; if there is no space between the definition and the open
+ ;; brace. This has to come after the nagios-definitions, otherwise
+ ;; the font-locking will miss the definitions that end with a brace.
+ (cons "[{}]" '(0 nil t))
+
+ ;; And comments take precedence over everything else.
+ (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."
)