atlas-engineer / nyxt

Nyxt - the hacker's browser.
https://nyxt-browser.com/
9.91k stars 416 forks source link

Forbid disabling of base-mode #1341

Open Ambrevar opened 3 years ago

Ambrevar commented 3 years ago

Currently the user can call the command base-mode which disables it, since it's enabled by default everywhere (except in the prompt buffer).

This breaks Nyxt because disabling base-mode removes enable-mode* commands and base-mode itself from execute-command. Oops.

It would be more meaningful to forbid the disabling of base-mode. How would we achieve this? Maybe re-enable base-mode in its destructor?

Thinking forward, this could be solved more elegantly if buffers had a mandatory major-mode as suggested in #909. Since we can't disable the major mode, all we would have to do is have major modes inherit from base-mode (except for prompt-buffer-mode).

Thoughts?

jmercouris commented 3 years ago

I don't think we should disable disabling base-mode. It would make our API have special cases and inconsistent. I believe if the user wishes to shoot themselves in the foot, let them do so. Otherwise we limit their power.

aadcg commented 3 years ago

How would we achieve this?

Doesn't #1198 alone cover it?

EDIT: It wouldn't suffice of course, I understand your point. I agree with @jmercouris that users should shoot themselves in the foot if they want.

Regarding modes, indeed, I think most of the modes we currently have are minor modes, if one were to use the parlance of Emacs. Conceptually, I can't understand what would be the major modes in Nyxt.

jmercouris commented 3 years ago

Alternatively, we add support for disabling mode togglers as André has pointed out, and voila! We just disable the mode toggle for base mode!

aadcg commented 3 years ago

We just disable the mode toggle for base mode!

Still, and I think @Ambrevar meant this as well, the user can programmatically do it. But I'd agree with @jmercouris that users should be able to have their mess served hot :)

Ambrevar commented 3 years ago

It would make our API have special cases and inconsistent.

base-mode is already a special case: see list-commands.

I don't think we should disable disabling base-mode. I believe if the user wishes to shoot themselves in the foot, let them do so. Otherwise we limit their power.

I don't think this is a matter of power: the way we implement "commands accessible everywhere" is clunky in my opinion.

Maybe we don't need base-mode at all, just global commands.

Ambrevar commented 3 years ago

André Alexandre Gomes @.***> writes:

How would we achieve this?

Doesn't #1198 alone cover it?

Maybe, but I'm not sure it's the right way to do it.

Regarding modes, indeed, I think most of the modes we currently have are minor modes, if one were to use the parlance of Emacs. Conceptually, I can't understand what would be the major modes in Nyxt.

Maybe this: "a major mode is unique per buffer and cannot be disabled".

The benefit is that it creates equivalence classes for buffers in various modes. For instance, we could list buffers in "shell-mode", since it's a major mode. However listing buffers that have proxy-modes enabled does not return "proxy buffers" since it's a minor mode.

Does that make sense?

jmercouris commented 3 years ago

I strongly believe that major modes and minor modes are a concept we do not need. Modes are simply modes. If we want modes to be non-togglable, Andre's solution is more than satisfactory.

aadcg commented 3 years ago

Maybe, but I'm not sure it's the right way to do it.

Just a remark to make it clear: it would prevent users from shooting themselves in the foot interactively, but not programmatically.

"a major mode is unique per buffer and cannot be disabled"

This is the definition I also have in mind.

The benefit is that it creates equivalence classes for buffers in various modes.

Here's exactly where I struggle! Not with the abstract idea of major modes, but with their equivalence classes in Nyxt!

In Emacs these are (taken from the Emacs manual):

Most major modes fall into three major groups. The first group contains modes for normal text, either plain or with mark-up. It includes Text mode, HTML mode, SGML mode, TeX mode and Outline mode. The second group contains modes for specific programming languages. These include Lisp mode (which has several variants), C mode, Fortran mode, and others. The third group consists of major modes that are not associated directly with files; they are used in buffers created for specific purposes by Emacs. Examples include Dired mode for buffers made by Dired (note Dired::), Message mode for buffers made by ‘C-x m’ (note Sending Mail::), and Shell mode for buffers used to communicate with an inferior shell process (*note Interactive Shell::).

Overall, you have convinced me. That is, it should be impossible to disable base-mode.

aadcg commented 3 years ago

Modes are simply modes.

I agree with that, as long as there's a single (tacit) "major-mode". That is, if we can find an unifying umbrella under which all buffers fall. In other words, the equivalence classes would be trivial.

Ambrevar commented 3 years ago

With https://github.com/atlas-engineer/nyxt/commit/2040bc4985dc51469219e1c16844b44c875b367c onward we don't use base-mode anymore to list togglers, instead we have global commands. I'm removing the bug and the high labels because the user can no longer remove the togglers from the listing.