1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Add separate tiny major mode for JSON

* lisp/progmodes/js.el (js-json-mode): New major mode.

* lisp/files.el (auto-mode-alist): Use it for JSON (bug#56682).

* lisp/progmodes/js.el (js--class-decl-matcher):
Skip work if there are no frameworks enabled.
This commit is contained in:
Dmitry Gutov 2022-08-09 04:00:08 +03:00
parent d6ea4894d3
commit d2080e4183
2 changed files with 24 additions and 17 deletions

View file

@ -1830,22 +1830,23 @@ context."
(defun js--class-decl-matcher (limit)
"Font lock function used by `js-mode'.
This performs fontification according to `js--class-styles'."
(cl-loop initially (js--ensure-cache limit)
while (re-search-forward js--quick-match-re limit t)
for orig-end = (match-end 0)
do (goto-char (match-beginning 0))
if (cl-loop for style in js--class-styles
for decl-re = (plist-get style :class-decl)
if (and (memq (plist-get style :framework)
js-enabled-frameworks)
(memq (js-syntactic-context)
(plist-get style :contexts))
decl-re
(looking-at decl-re))
do (goto-char (match-end 0))
and return t)
return t
else do (goto-char orig-end)))
(when js-enabled-frameworks
(cl-loop initially (js--ensure-cache limit)
while (re-search-forward js--quick-match-re limit t)
for orig-end = (match-end 0)
do (goto-char (match-beginning 0))
if (cl-loop for style in js--class-styles
for decl-re = (plist-get style :class-decl)
if (and (memq (plist-get style :framework)
js-enabled-frameworks)
(memq (js-syntactic-context)
(plist-get style :contexts))
decl-re
(looking-at decl-re))
do (goto-char (match-end 0))
and return t)
return t
else do (goto-char orig-end))))
(defconst js--font-lock-keywords
'(js--font-lock-keywords-3 js--font-lock-keywords-1
@ -3490,6 +3491,12 @@ This function is intended for use in `after-change-functions'."
;;(syntax-propertize (point-max))
)
;;;###autoload
(define-derived-mode js-json-mode js-mode "JSON"
;; JSON files can be big. Speed up syntax-ppss.
(setq-local syntax-propertize-function nil)
(setq-local js-enabled-frameworks nil))
;; Since we made JSX support available and automatically-enabled in
;; the base `js-mode' (for ease of use), now `js-jsx-mode' simply
;; serves as one other interface to unconditionally enable JSX in