Skip to content

Commit c13fa62

Browse files
authored
Merge pull request #15 from zonuexe/feature/comment-syntax-table
Use syntax table instead of font-lock regexp
2 parents a04cef3 + f33abe7 commit c13fa62

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

nginx-mode.el

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
;;; nginx-mode.el --- major mode for editing nginx config files
32

43
;; Copyright 2010 Andrew J Cosgriff <[email protected]>
@@ -7,7 +6,7 @@
76
;; Maintainer: Andrew J Cosgriff <[email protected]>
87
;; Created: 15 Oct 2010
98
;; Version: 1.1.6
10-
;; Keywords: nginx
9+
;; Keywords: languages, nginx
1110

1211
;; available from http://github.com/ajc/nginx-mode
1312

@@ -50,10 +49,15 @@
5049
"*Indentation can insert tabs in nginx mode if this is non-nil."
5150
:type 'boolean :group 'nginx)
5251

52+
(defvar nginx-mode-syntax-table
53+
(let ((table (make-syntax-table)))
54+
(modify-syntax-entry ?# "< b" table)
55+
(modify-syntax-entry ?\n "> b" table)
56+
table)
57+
"Syntax table for `nginx-mode'.")
5358

5459
(defvar nginx-font-lock-keywords
55-
(list '("#.*" . font-lock-comment-face)
56-
'("^\\([ \t]+\\)?\\([A-Za-z09_]+\\)" 2 font-lock-keyword-face t)
60+
(list '("^\\([ \t]+\\)?\\([A-Za-z09_]+\\)" 2 font-lock-keyword-face t)
5761
;; uncomment the next one if you want your eyes to bleed
5862
;; (it'll highlight parentheses and curly braces)
5963
;;'("\\(\{\\|\}\\|\(\\|\)\\)" . font-lock-pseudo-keyword-face)
@@ -158,16 +162,14 @@ of the closing brace of a block."
158162
"Keymap for editing nginx config files.")
159163

160164
;;;###autoload
161-
(defun nginx-mode ()
165+
(define-derived-mode nginx-mode prog-mode "Nginx"
162166
"Major mode for highlighting nginx config files.
163167
164168
The variable nginx-indent-level controls the amount of indentation.
165169
\\{nginx-mode-map}"
166-
(interactive)
167-
(kill-all-local-variables)
170+
:syntax-table nginx-mode-syntax-table
171+
168172
(use-local-map nginx-mode-map)
169-
(setq mode-name "Nginx"
170-
major-mode 'nginx-mode)
171173

172174
(set (make-local-variable 'comment-start) "# ")
173175
(set (make-local-variable 'comment-start-skip) "#+ *")

0 commit comments

Comments
 (0)