Documentation on modes

Is there any documentation (article, blog post, commented example, …) that gives an overview of what modes can do? Answering questions such as “What behavior can a mode implement?”, “What features of one mode can I override in another mode?” etc.?

Concrete example: I am trying to modify (filter) the links shown as element hints for a specific Web site. I know I can add a mode for that site that will override the behavior defined in web-mode. But I don’t know if I can modify the hint generation code in web mode. I am sure someone here could answer that specific question, but I am even more interested in how I would figure this out for myself.

The basic info on Modes you can find in the “Modes” section of the Nyxt manual.

Those essentially are buffer-specific objects that export some commands and run some initialization/destruction code. They have access to anything inside Nyxt, so it’s really hard to draw the boundary for what they can do.

Regarding your particular question, the selector for the element hints can be passed to query-hints to override the selection. To do so in every command, you need to either

  • redefine every query-hints-reliant-command, or
  • redefine query-hints itself, with some hacking like
(let ((old-query-hints #'nyxt/web-mode:query-hints))
  (setf (symbol-function 'nyxt/web-mode::query-hints)
        (lambda (prompt function &key multi-selection-p
                                   annotate-visible-only-p
                                   (selector "a"))
          (funcall old-query-hints prompt function :multi-selection-p multi-selection-p
                                                   :annotate-visible-only-p annotate-visible-only-p
                                                   :selector selector))))

Redefining the selector in the mode settings would be much prettier, though…

Thanks for your reply! I had read the section in the manual, but it doesn’t go into any details. After your reply, it looks like there aren’t many relevant details. Modes are pretty much packages that can contain arbitrary code. And “overriding” then applies mainly to key bindings.

For my specific use case, I’d probably better subclass web-mode to make a replacement, rather than add a mode to override pieces. One more to-do item on my agenda :slight_smile: