Today, I wanted to remap some keys in Nyxt (actually it was yesterday but that’s not relevant).
And so, I told to myself: “Well, I don’t know anything about the Common Lisp that’s being used in the config files for Nyxt. Why not looking for the way the main contributors of Nyxt does it in their own dotfiles? It ought to be a simple, elegant way to do this, as it is something expected to be basic, coming from that kind of software, right?”
That’s why I was really surprised when I realized that they all does it in a seemingly very different way!
So, here are the relevant parts of the configs of
Ambrevar, jmercouris and aartaka:
–
(defvar *my-keymap* (make-keymap "my-map"))
; ...
(define-key *my-keymap* "C-M-p" 'copy-password)
(define-key *my-keymap* "C-m-u" 'copy-username)
; etc...
; ...
(define-mode my-mode ()
"Dummy mode for the custom key bindings in `*my-keymap*'."
((keymap-scheme (keymap:make-scheme
scheme:cua *my-keymap*
scheme:emacs *my-keymap*
scheme:vi-normal *my-keymap*))))
(define-configuration (buffer web-buffer nosave-buffer)
((default-modes (append '(my-mode vi-normal-mode) %slot-default%))))
It seems that we are defining a whole new scheme (is it a good idea to call a keymap a scheme in lisp…?), then it looks like that we sort of merge it with the base config in a new mode by calling make-scheme
? And then we add this new mode to the default mode later in the config file?
–
(define-configuration buffer
((default-modes (append '(emacs-mode) %slot-default%))
(override-map (let ((map (make-keymap "my-override-map")))
(define-key map
"C-o" 'execute-command
"C-q" 'quit
; etc...)
map))))
OK, so it seems that here we’re actually overriding some keymap for the buffer configuration by making a temporary new keymap and using the override-map
method in the current context. It is very similar to the above solution without the burden of creating a whole new mode for it?
–
(define-configuration nyxt/web-mode:web-mode
((nyxt/web-mode::keymap-scheme
(nyxt::define-scheme (:name-prefix "web" :import %slot-default%)
scheme:emacs
(list
"C-c p" 'copy-password
"C-c y" 'autofill
; etc...)))))
And lastly, here it looks like we’re redefining the keymap-scheme in web-mode by importing the default slot and adding our own list of bindings to it. It seems to be the most low-level solution of all three?
I should note that this solution prints warning at start when we’re redefining some keys, unlike the firsts.
By the way, is it expected to prints almost a dozen times the “redefining key” warning when nyxt starts?
It looks to me like it’s loading the init-file numerous times…
–
Could you please explain what’s happening in each of these solutions, why and how do they work, the pros and the cons of each and why the heck each major devs of Nyxt is using its own different solution?
Please note that I don’t want to start a war on “what’s better?” and I don’t want to judge anyone about their way of configuring (I know this is something very personal).
It’s just that I really wonder about where does thoses differences come from and how it may or may not affect the community and accessibility of the software.
I guess (it’s a wild guess) redefining keymaps would be one of the first thing user would want to do when using Nyxt (maybe apart from changing the theme which seems to be easier in v3 adding blocker mode or that sort of stuff that the Common Settings can do IIRC).
I don’t think I found anything relevant in the documentation or the manual about this, and I think having “one official way of doing it” would be nice, as it gives a better accessibility to the features for newcomers and it would be easier to help people when we already know how they’re supposed to do it.
What do you all think?