Subject: bug#67463: 30.0.50; Eglot may manage js-json-mode buffers with wrong server

From: João Távora <[email-masked]>
Date: Sun, 7 Jan 2024 01:57:59 +0000

On Sat, Jan 6, 2024 at 6:04 PM Dmitry Gutov <[email-masked]> wrote:
>
> On 06/01/2024 18:01, Stefan Monnier via Bug reports for GNU Emacs, the
> Swiss army knife of text editors wrote:
> > -(define-derived-mode js-json-mode js-mode "JSON"
> > +(define-derived-mode js-json-mode prog-mode "JSON"
> > +  (js-mode) ;; For expediency, reuse js-mode, but not as parent (bug#67463).
>
> Nice.

I agree.  If this works, I think it's quick, but not necessarily
dirty.

On 06/01/2024 18:01, Stefan Monnier

> Add a tool like `derived-mode-remove-parent`.

Also agree, but the things we're doing in that symbol-plist
seem to have gotten rather complicated lately, so I wouldn't
be surpsied this is buggy in some edge case.

(require 'cl-lib)
(defun derived-mode-remove-parent (mode parent)
  (cl-macrolet ((allp (m) `(plist-get (symbol-plist ,m)
'derived-mode--all-parents))
                (dmp (m) `(plist-get (symbol-plist ,m) 'derived-mode-parent)))
    (setf (allp mode) (delq parent (allp mode)))
    (when (eq (dmp mode) parent)
      (setf (dmp mode) (dmp parent)))))

but Pengji can try to use it to do the following in the meantime:

(derived-mode-remove-parent 'js-json-mode 'js-mode)
(derived-mode-remove-parent 'js-json-mode 'js-base-mode)

thought the second one shouldn't strictly be needed at the moment.

João