From 314c939d1e182b8d015fc9c63d445274e0494748 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 14 Jan 2024 22:17:13 -0500 Subject: [PATCH] (js-json-mode): Don't derive from `js-mode` (bug#67463) * lisp/progmodes/js.el (js--mode-setup): New function, extracted from `js-mode`. (js-mode): Use it. (js-json-mode): Use it instead of inheriting from `js-mode`. --- etc/NEWS | 5 +++++ lisp/progmodes/js.el | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/etc/NEWS b/etc/NEWS index da0253e97dc..03b8c3b517a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1002,6 +1002,11 @@ which calls 'xref-find-definitions'. If the previous one worked better for you, use 'define-key' in your init script to bind 'js-find-symbol' to that combination again. +** Json mode +`js-json-mode` does not derive from `js-mode` any more so as not +to confuse tools like Eglot or YASnippet into thinking that those +buffers contain Javascript code. + ** Python mode --- diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 0115feb0e97..947d91c9b1a 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -3702,6 +3702,9 @@ Currently there are `js-mode' and `js-ts-mode'." (define-derived-mode js-mode js-base-mode "JavaScript" "Major mode for editing JavaScript." :group 'js + (js--mode-setup)) + +(defun js--mode-setup () ;; Ensure all CC Mode "lang variables" are set to valid values. (c-init-language-vars js-mode) (setq-local indent-line-function #'js-indent-line) @@ -3924,7 +3927,9 @@ See `treesit-thing-settings' for more information.") (put-text-property (1- ne) ne 'syntax-table syntax))))) ;;;###autoload -(define-derived-mode js-json-mode js-mode "JSON" +(define-derived-mode js-json-mode prog-mode "JSON" + :syntax-table js-mode-syntax-table + (js--mode-setup) ;Reuse most of `js-mode', but not as parent (bug#67463). (setq-local js-enabled-frameworks nil) ;; Speed up `syntax-ppss': JSON files can be big but can't hold ;; regexp matchers nor #! thingies (and `js-enabled-frameworks' is nil). -- 2.39.2