From ec7589a5032f9f156e46fbb77babaa9ac391a818 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 9 Apr 2010 10:56:43 -0400 Subject: [PATCH] Remove the nagios-comments and nagios-string constants. Don't highlight comments and strings via keywords. Make keyword highlighting case-sensitive. Remove some comments from the main mode function. Added a syntax table. Enable syntax highlighting for comments and strings. Add comment-start and comment-end definitions. --- nagios-mode.el | 63 ++++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 40 deletions(-) diff --git a/nagios-mode.el b/nagios-mode.el index 7c9f663..291b0eb 100644 --- a/nagios-mode.el +++ b/nagios-mode.el @@ -173,16 +173,6 @@ -;; Syntax Highlighting Patterns - -(defconst nagios-comments - (eval-when-compile - (regexp-alt-raw - '("#+.*" - ";+.*"))) - ) - - (defconst nagios-directives (eval-when-compile (concat "^[ \t\r\n]*" @@ -268,24 +258,10 @@ -(defconst nagios-string - (eval-when-compile - "\\(\".*?\"\\)")) - - ;; The One True Font Locking Variable (defvar nagios-font-lock-keywords (list - - ;; Font lock the comments first. - (cons nagios-comments font-lock-comment-delimiter-face) - - ;; Strings have the highest priority. For now, this is broken, - ;; but I guess I would rather have strings miscolored within - ;; comments than the other way around. - (cons nagios-string '(0 font-lock-string-face t)) - (cons nagios-special font-lock-keyword-face) (cons nagios-directives font-lock-variable-name-face) (cons nagios-macros font-lock-constant-face) @@ -296,34 +272,41 @@ +(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-end) (make-local-variable 'indent-line-function) - (setq indent-line-function 'nagios-indent-line) + + (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 t 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-end "" + ) ;; 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. -- 2.44.2