How to get a keyscheme-map via swank?

This is rather a Common Lisp beginner’s question. Not sure if it’s okay to ask this here:

I’m trying to query the CUA keybindings of the document mode via swank.

I don’t know how to get the document-mode (instance) directly, but I can list all modes of the current buffer:

(modes (current-buffer))

I see that document-mode is the seventh in this case, so I tried:

NYXT-USER> (keyscheme-map (seventh (modes (current-buffer))))
#<HASH-TABLE :TEST EQUAL :COUNT 4 {1006341723}>

Using this function, I can list all keys of the hash table:

(defun hash-keys (hash-table)
  (loop for key being the hash-keys of hash-table collect key))
NYXT-USER> (hash-keys (keyscheme-map (seventh (modes (current-buffer)))))
(#<NKEYMAPS/CORE:KEYSCHEME default {1001250413}>
 #<NKEYMAPS/CORE:KEYSCHEME cua {1001250473}>
 #<NKEYMAPS/CORE:KEYSCHEME emacs {1001250363}>
 #<NKEYMAPS/CORE:KEYSCHEME vi-normal {1001250323}>)

When I try to get the cua value, I always get nil:

NYXT-USER> (gethash 'cua (keyscheme-map (seventh (modes (current-buffer)))))

I also tried cua, :cua, "cua", keyscheme:cua, nkeymaps/core/keyscheme:cua.

Any hints what I’m doing wrong?

The following should lead you in the right direction:

(loop for keymap in (current-keymaps)
      collect (loop for keyspec
                      being the hash-keys in (keymaps:keymap-with-parents->map keymap)
                        using (hash-value bound-value)
                    collect keyspec))

I think you’re missing the fact that keyshemes belong to the package nyxt/keyscheme, which means that CUA needs to referenced as nyxt/keyscheme:cua.

The function below may be of help to you.

;; Example:
;; (mode->map (current-mode :document-mode) nyxt/keyscheme:cua)
(defun mode->map (mode keyscheme)
  (keymaps:keymap->map (nkeymaps:get-keymap keyscheme (keyscheme-map mode))))
1 Like