@@ -124,8 +124,16 @@ This function calls `json-mode--update-auto-mode' to change the
124
124
(modify-syntax-entry ?\" " \" " st)
125
125
; ; Comments
126
126
(modify-syntax-entry ?\n " >" st)
127
+ ; ; Dot in floating point number literal.
128
+ (modify-syntax-entry ?. " _" st)
127
129
st))
128
130
131
+ (defvar json-mode--string-syntax-table
132
+ (let ((st (copy-syntax-table json-mode-syntax-table)))
133
+ (modify-syntax-entry ?. " ." st)
134
+ st)
135
+ " Syntax table for strings." )
136
+
129
137
(defvar jsonc-mode-syntax-table
130
138
(let ((st (copy-syntax-table json-mode-syntax-table)))
131
139
; ; Comments
@@ -135,13 +143,19 @@ This function calls `json-mode--update-auto-mode' to change the
135
143
(modify-syntax-entry ?* " . 23bn" st)
136
144
st))
137
145
146
+ (defvar jsonc-mode--string-syntax-table
147
+ (let ((st (copy-syntax-table jsonc-mode-syntax-table)))
148
+ (modify-syntax-entry ?. " ." st)
149
+ st)
150
+ " Syntax table for strings and comments." )
151
+
138
152
(defun json-mode--syntactic-face (state )
139
153
" Return syntactic face function for the position represented by STATE.
140
154
STATE is a `parse-partial-sexp' state, and the returned function is the
141
155
json font lock syntactic face function."
142
156
(cond
143
157
((nth 3 state)
144
- ; ; This might be a string or a name
158
+ ; ; This might be a string or a name
145
159
(let ((startpos (nth 8 state)))
146
160
(save-excursion
147
161
(goto-char startpos)
@@ -150,14 +164,38 @@ json font lock syntactic face function."
150
164
font-lock-string-face ))))
151
165
((nth 4 state) font-lock-comment-face )))
152
166
167
+ (defun json-mode-forward-sexp (&optional arg )
168
+ " Move point forward an atom or balanced bracket.
169
+
170
+ See `forward-sexp for ARG."
171
+ (interactive " p" )
172
+ (unless arg
173
+ (setq arg 1 ))
174
+ (let ((forward-sexp-function nil )
175
+ (sign (if (< arg 0 ) -1 1 ))
176
+ state)
177
+ (while (not (zerop arg))
178
+ (setq state (syntax-ppss ))
179
+ (if (nth 8 state)
180
+ ; ; Inside a string or comment.
181
+ (progn
182
+ (with-syntax-table
183
+ (if (eq major-mode 'jsonc-mode )
184
+ jsonc-mode--string-syntax-table
185
+ json-mode--string-syntax-table)
186
+ (forward-sexp sign)))
187
+ (forward-sexp sign))
188
+ (setq arg (- arg sign)))))
189
+
153
190
;;;### autoload
154
191
(define-derived-mode json-mode javascript-mode " JSON"
155
192
" Major mode for editing JSON files."
156
193
:syntax-table json-mode-syntax-table
157
194
(setq font-lock-defaults
158
195
'(json-font-lock-keywords-1
159
196
nil nil nil nil
160
- (font-lock-syntactic-face-function . json-mode--syntactic-face))))
197
+ (font-lock-syntactic-face-function . json-mode--syntactic-face)))
198
+ (setq-local forward-sexp-function #'json-mode-forward-sexp ))
161
199
162
200
;;;### autoload
163
201
(define-derived-mode jsonc-mode json-mode " JSONC"
0 commit comments