reddit / emacs

Why do major modes exist?

M-x_ · 2022-04-22 22:37
This question might sound provocative but it isn't my intention. I'm genuinely curious why emacs has the concepts of "major" and "minor" modes. I'm no elisp guru but to me it seems that a minor mode can do everything a major mode can: they both have hooks, key bindings, custom variables, etc. The only *real* difference AFAIK is that major modes are mutually exclusive. And even the latter wouldn't be hard to implement for minor modes by adding something like a boolean variable `is-mutually-exclusive` or a parameter. Yet the separation increases code complexity by separating the two and adding little idiosyncrasies to each. Moreover, the distinction introduces undue cognitive overhead by having us think of a mode as being the "main" or "most important" one in any given context. Why is that? Why e.g. should I think of `js-mode` as being somehow more "major" than `lsp-mode` even though the latter is the main driver of my editing process? It feels like maybe major and minor modes were abstractions designed to guide the process of creating packages but nowadays I see that as doing more harm than good. So, why not treat them on an equal footing? Do away with major and minor, and just have *modes*. To me it would decrease code complexity and reduce the cognitive overhead. But I'm not the expert here so I'm really curious about what you think about all this.
BettaGeorge · 2022-04-22 23:12
I always thought it was because that's how it was in the olden days and changing it now would break too much stuff.
BunnyLushington · 2022-04-23 00:15
It's not just that major modes are mutually exclusive but that every buffer must possess a major mode (so not just "only one" but "one and only one"). Once you indicate both `is-mutually-exclusive` and `possible-base-mode` (lsp-mode, e.g., would be an inappropriate hypothetical `possible-base-mode` ... what would fontification look like?) you're right back to major and minor modes.
deerpig · 2022-04-23 00:36
My understanding, and this might well be mistaken, is that a major modes shape and provide a baseline environment, (look and feel) and behavior (how things work) that trump global settings. You can only run a single major mode at one time, otherwise you run into conflicting settings. And don't forget that many major modes are built on top of other major modes. I once wrote a major mode on top of org-mode. In this way I didn't have to reinvent the wheel and use the existing org environment which people are already familiar with. Minor modes modify a set of features and settings globally across many major modes.
M-x_ · 2022-04-23 00:49
Great points, thanks. I guess the derived mode functionality *is* a big difference between the two. And also it shows how syntax is really only addressed by major modes. Too bad there isn't a mechanism similar to how `:filetype` works in vim (God forbid! \s).
Failware_ · 2022-04-23 01:52
From what I understand, Nyxt conceptually only has minor modes. Their discussions in [#1341](https://github.com/atlas-engineer/nyxt/issues/1341), [#1790](https://github.com/atlas-engineer/nyxt/issues/1790), and related issues may be of interest here.
DrReadIt · 2022-04-23 16:51
Because Nyxt is the Major Mode.
crawsphi · 2022-04-23 18:15
I would say the biggest thing a major mode provides is probably the syntax table. That provides the fundamentals for a surprising amount of behavior, and it's hard to see how multiple minor modes could collaborate to sensibly define it.
emaxor · 2022-04-27 01:54
woah