Trying to re-bind keys in web-mode

Hi, I’m new to Nyxt. I know a little about Common Lisp, and have been using Emacs for years.

The key bindings are giving me problems. So far, the only thing I’ve gotten to work is in (define-configuration buffer using the override-map.

Now I’m trying to use the code in https://github.com/aartaka/nyxt-config/keybinds.lisp. I put in my init.lisp what I regard to be a somewhat simplified version of that code:

(define-configuration web-mode
  (
    (web-mode::keymap-scheme
      (define-scheme ("web" :import %slot-default%)
	scheme:emacs
	(list
	  "C-c p" 'copy-password
	  "C-c y" 'autofill
	  '(:remap f3) 'nothing
	  "C-s k" 'nothing
	  '(:remap "C-s s") 'nothing
	  '(:remap "C-s h") 'nothing
	  "M-s h" 'history-all-query
	  "C-s" 'search-buffer
	  )))
    )
  )

However, none of the bindings seem to work when I open a web page with Nyxt (I have 2.2.4, SBCL 2.2.2, on FreeBSD).
Is :remap the right thing? Are some of my “simplifications” wrong?
Help would be appreciated.

So far, the only thing I’ve gotten to work is in (define-configuration buffer using the override-map .

Yep that's what I have in my init.lisp

(define-configuration buffer
    ;;If you want to reuse the default map,
    ;;you can use %slot-default instead of (make-keymap ...)
    ((override-map (define-key %slot-default%
                       "S-x" 'execute-command
		       "M-d" 'delete-buffer
		       "M-v" 'nyxt/visual-mode:visual-mode
		       "C-s" 'nyxt/web-mode:search-buffer
                       "C-w" 'delete-current-buffer))))

You’re close, it’s just one thing: you don’t have to write (:remap ...) out – you can simply provide the keybinding and it will be rebound. Right now, it seems, '(:remap "C-s s") confuses the keymap library…

And insterting unquoted f3 can be a source of yet another error here. Unlike Emacs, we only allow strings as key designators – no chars, numbers, or symbols :slight_smile:

Thanks. I tried what you suggested, and now I have

(define-configuration web-mode
  (
    (web-mode::keymap-scheme
      (define-scheme ("web" :import %slot-default%)
	scheme:emacs
	(list
	  "C-c p" 'copy-password
	  "C-c y" 'autofill
	  "f3" 'nothing
	  "C-s k" 'nothing
	  "C-s s" 'nothing
	  "C-s h" 'nothing
	  "M-s h" 'history-all-query
	  "C-s" 'search-buffer
	  )))
    )
  )

Nevertheless, it still seems that things aren’t working. E.g. if I visit a web page, f3 is still active, and “C-s” simply writes Pressed keys: "C-s" in the minibuffer.

Oh wait, web-mode should be nyxt/web-mode:web-mode, and web-mode::keymap-scheme should be nyxt/web-mode:keymap-scheme :slight_smile:

Does it work with these changes?

I now have (see inline comments)

(define-configuration nyxt/web-mode:web-mode
  (
    (nyxt/web-mode::keymap-scheme
      (define-scheme (:name-prefix "web" :import %slot-default%)
	scheme:emacs
	(list
	  "C-c p" 'copy-password   ; appears to work
	  "C-c y" 'autofill                 ; can't check right now
	  "f3" 'nothing             ; works
	  "C-s k" 'nothing       ; works
	  "C-s s" 'nothing       ; works
	  "C-s h" 'nothing       ; works
	  "M-s h" 'history-all-query  ; does not work
	  "C-s" 'search-buffer          ; does not work
	  )))
    )
  )

I see. I’ve just experimented with your snippet, and using "C-s" 'nyxt/web-mode:search-buffer instead of "C-s" 'search-buffer seems to fix it – keymap is extremely sensitive about what you provide it with. In this case, the problem was that there’s no nyxt:search-buffer, there’s only nyxt/web-mode:search-buffer.

Hmm, I don’t understand this. We are configuring web-mode aren’t we? And nyxt/web-mode:search-buffer to me says that search-buffer “belongs” to web-mode.

Anyhow, I conclude that configuring key bindings is highly non-trivial! Perhaps that could be improved in the future?