Decouple utop.el from tuareg-mode#511
Decouple utop.el from tuareg-mode#511bbatsov wants to merge 7 commits intoocaml-community:masterfrom
Conversation
tuareg is now loaded on demand only when its functions are actually needed (i.e., when the user is in tuareg-mode). This removes the mandatory (require 'tuareg) and the tuareg entry from Package-Requires, allowing utop.el to work without tuareg installed.
Introduce `utop-mode-compat-alist` that maps major modes to their phrase navigation functions. This replaces the old positional-index dispatch and makes it easy for any OCaml major mode (e.g. neocaml) to register itself without modifying utop.el.
Walk the derived-mode-parent chain when looking up phrase functions, so modes that derive from a known mode (e.g. a mode derived from tuareg-mode) work automatically without explicit registration.
Document `utop-mode-compat-alist` as the way to add support for new major modes, mention derived mode support, and list neocaml alongside the other supported modes.
README.md
Outdated
| sensitive completion, colors, and more. | ||
|
|
||
| It integrates with the Tuareg, caml, ReasonML and typerex modes in Emacs. | ||
| It integrates with the Tuareg, caml, neocaml, ReasonML and typerex modes in Emacs. |
There was a problem hiding this comment.
If I read the code correctly, the integration with neocaml is done on the neocaml side, isn't it?
There was a problem hiding this comment.
Yeah, exactly. I could have added it here, but I thought it's probably better to just provide it in neocaml. IMO that's the best for every major mode, but I didn't want to make changes that might break someone's setup.
There was a problem hiding this comment.
I think it might then be slightly clearer to update the phrasing to
The following Emacs modes are explicitly supported: Tuareg, caml, neocaml, ReasonML and typerex .
to not give the impression that there is explicit integration for neocaml inside utop.
(Because I believe that this important for a community maintained project to be very explicit in term of the state of the code.)
There was a problem hiding this comment.
Fair enough. I'll think about some updated wording for this.
Plist entries like `:next-phrase` and `:discover-phrase` are more readable and easier to extend with new properties in the future than positional cons pairs.
Don't list neocaml alongside the built-in modes — instead mention it as an example of a third-party mode that integrates via the new utop-mode-compat-alist mechanism.
|
I've addressed all feedback. There are a few other unrelated improvements I have in mind, but I'll wait for this PR to get merged first before continuing with additional changes. |
|
I am planning to merge in the beginning of next week to give time for eventual reactions. |
|
Thanks for letting me know. No rush! |
I'm the author of neocaml (a new OCaml major mode for Emacs) and I wanted to make sure it plays nicely with utop.el. Currently utop.el has a hard dependency on tuareg, which makes it difficult for other OCaml major modes to integrate with it.
This PR decouples utop.el from tuareg by:
(require 'tuareg)with lazy loading — tuareg is only loaded when its functions are actually needed (i.e., when the user is intuareg-mode)utop-mode-compat-alist— an extensible alist that maps major modes to their phrase navigation functions, replacing the old hard-coded positional dispatchderived-mode-parentchain in the compat lookup, so modes derived from a known mode work automaticallyWith this change any OCaml major mode can register itself with a simple:
Existing tuareg/caml/typerex/reason users are unaffected — their modes are pre-registered in the alist and tuareg is loaded lazily on first use.