@@ -60,6 +60,9 @@ Return the new `auto-mode-alist' entry"
60
60
(add-to-list 'auto-mode-alist new-entry)
61
61
new-entry))
62
62
63
+ ; ;; make byte-compiler happy
64
+ (defvar json-mode--auto-mode-entry )
65
+
63
66
;;;### autoload
64
67
(defcustom json-mode-auto-mode-list '(
65
68
" .babelrc"
@@ -105,6 +108,10 @@ This function calls `json-mode--update-auto-mode' to change the
105
108
(defconst json-mode-number-re (rx (group (one-or-more digit)
106
109
(optional ?\. (one-or-more digit)))))
107
110
(defconst json-mode-keyword-re (rx (group (or " true" " false" " null" ))))
111
+ (defconst json-mode-line-comments-re
112
+ (rx (and bol (0+ space) (group (and " //" (*? nonl) eol)))))
113
+ (defconst json-mode-block-comments-re
114
+ (rx (group (and " /*" (*? anything) " */" ))))
108
115
109
116
(defconst json-font-lock-keywords-1
110
117
(list
@@ -113,13 +120,28 @@ This function calls `json-mode--update-auto-mode' to change the
113
120
(list json-mode-keyword-re 1 font-lock-constant-face )
114
121
(list json-mode-number-re 1 font-lock-constant-face )
115
122
)
116
- " Level one font lock." )
123
+ " Level one font lock for `json-mode' ." )
124
+
125
+ (defconst jsonc-font-lock-keywords-1
126
+ (list
127
+ (list json-mode-line-comments-re 1 font-lock-comment-face )
128
+ (list json-mode-block-comments-re 1 font-lock-comment-face )
129
+ (list json-mode-quoted-key-re 1 font-lock-keyword-face )
130
+ (list json-mode-quoted-string-re 1 font-lock-string-face )
131
+ (list json-mode-keyword-re 1 font-lock-constant-face )
132
+ (list json-mode-number-re 1 font-lock-constant-face ))
133
+ " Level one font lock for `jsonc-mode' ." )
117
134
118
135
;;;### autoload
119
136
(define-derived-mode json-mode javascript-mode " JSON"
120
137
" Major mode for editing JSON files"
121
138
(set (make-local-variable 'font-lock-defaults ) '(json-font-lock-keywords-1 t )))
122
139
140
+ ;;;### autoload
141
+ (define-derived-mode jsonc-mode json-mode " JSONC"
142
+ " Major mode for editing JSON files with comments"
143
+ (set (make-local-variable 'font-lock-defaults ) '(jsonc-font-lock-keywords-1 t )))
144
+
123
145
; ; Well formatted JSON files almost always begin with “{” or “[”.
124
146
;;;### autoload
125
147
(add-to-list 'magic-fallback-mode-alist '(" ^[{[]$" . json-mode))
0 commit comments