Skip to content

Derive the mode from prog-mode or lisp-data-mode #662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bbatsov opened this issue Sep 4, 2023 · 3 comments
Closed

Derive the mode from prog-mode or lisp-data-mode #662

bbatsov opened this issue Sep 4, 2023 · 3 comments

Comments

@bbatsov
Copy link
Member

bbatsov commented Sep 4, 2023

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-mode and/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.

@andreyorst
Copy link
Contributor

andreyorst commented Sep 4, 2023

Isn't clojure-mode already derived from prog-mode?

(define-derived-mode clojure-mode prog-mode "Clojure"

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 :)

@andreyorst
Copy link
Contributor

andreyorst commented Sep 4, 2023

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)

@bbatsov
Copy link
Member Author

bbatsov commented Sep 4, 2023

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.

@bbatsov bbatsov closed this as completed Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants