Derive the mode from prog-mode or lisp-data-mode
bbatsov opened this issue · 3 comments
I've noticed on emacs-devel that Lisp-like modes weren't supposed to derive from lisp-mode (which is a major mode for Common Lisp), but rather from lisp-data-mode or directly from prog-mode. There's also a nice related discussion about this in fennel-mode's issue tracker (https://gitlab.com/technomancy/fennel-mode/-/issues/11). Here's the most interesting part for us:
If a buffer is in lisp-mode it has CL code in it. There are many references to "Common-Lisp" in lisp-mode.el and this has long been the status-quo If you want to make a Lisp-like language mode, use
lisp-data-modeand/or a make a major mode that uses the lisp-mode features you're interested in, much like clojure-mode. As with inheritance in general, only inherit from lisp-mode if you can guarantee the "is a" relationship.
And here are the changes done by @andreyorst in fennel-mode to switch to prog-mode as the parent - https://gitlab.com/technomancy/fennel-mode/-/merge_requests/31 I'm guessing we can do something very similar.
That's kind of related the ancient #270 - I've long felt that our original approach to derive from lisp-mode created just as many problems as it solved.
Isn't clojure-mode already derived from prog-mode?
Line 615 in 81b67ec
And here are the changes done by @andreyorst in fennel-mode to switch to prog-mode as the parent - https://gitlab.com/technomancy/fennel-mode/-/merge_requests/31 I'm guessing we can do something very similar.
Also, I did that by actually looking at what clojure-mode does - the syntax table probably was adapted from clojure-mode mostly as is, and some other things as well :)
FWIW it's OK to use stuff from lisp-mode - it's pretty generic and can be tweaked reliably. We do that in fennel-mode without known issues. The fennel-mode defines a REPL integration that is based on comint and inferior-lisp and works well enough in practice by just using the set of lisp-eval-* functions from lisp-mode
I did re-implement these functions for fennel-proto-repl mode because it wasn't possible to reuse them for the most part due to the custom protocol, but it's not a problem for clojure-mode as it doesn't provide interactions with the REPL by itself.
I don't see many references to lisp-mode in clojure-mode apart from lisp-fill-paragraph and stuff like lisp-indent-function which is pretty normal. Decoupling it would mean reimplementing the indent engine, which we decided not to do in fennel-mode for the time being.
With clojure-ts-mode it would be more practical to depend on indentation provided by the tree-sitter engine, but for plain clojure-mode I think it's OK to reuse these particular elements from lisp-mode as it's not forbidden, and works well enough (at least from my perspective clojure-mode works stellar)
I don't see many references to lisp-mode in clojure-mode apart from lisp-fill-paragraph and stuff like lisp-indent-function which is pretty normal. Decoupling it would mean reimplementing the indent engine, which we decided not to do in fennel-mode for the time being.
Indeed. I wasn't too keen on reimplementing the indentation engine.
Thanks for the input! We mostly use list-indent-function and lisp-doc-string-elt-property from lisp-mode, but because we inherit from it complicates a bit the grammar of the mode. Obviously this setup has worked for a while, but I was wondering if we can't simplify it a bit.
Not something particularly important, especially if we hope to replace clojure-mode with clojure-ts-mode in the next few years.