xahlee / xah-fly-keys

the most efficient keybinding for emacs
http://xahlee.info/emacs/misc/xah-fly-keys.html
483 stars 83 forks source link

Can't make xah-fly-keys work properly with exwm #132

Open spiderbit opened 2 years ago

spiderbit commented 2 years ago

Basically what I want is to have in exwm buffers to have only a few commands in command mode and handle the rest like in insert-mode so that the X buffers can use this keys.

As example in a exwm buffer i/k or in dvorak c/t for forward-line / backward-line doesn't make sense.

(defvar xah-fly-exwm-command-map (cons 'keymap xah-fly-shared-map))
(xah-fly--define-keys
 xah-fly-exwm-command-map
("a" . xah-fly-M-x)
("u" . xah-fly-insert-mode-activate)
...)

(defun xah-fly--update-key-map ()
  (setq xah-fly-key-map (if xah-fly-insert-state-q
                            xah-fly-insert-map
              (if (eq major-mode 'exwm-mode)
                  xah-fly-exwm-command-map
                              xah-fly-command-map))))

shouldn't that setup the exwm-command-map instead of the normal command-map in exwm buffers? the comparsion works, but despite I have not defined forward-line in exwm-command-map it's still defined.

Tried to overwrite it with "nil": ("t" . nil)

But it is still bound to forward line, till now I used that as hook: (setq xah-fly-command-map (assq-delete-all ?t xah-fly-command-map))

That kind of worked... do I have to change something else to add such hybrid-keymap / alternative command-map into fly-keys?

spiderbit commented 2 years ago

If I change the xah-fly-command-mode-init to set the transient-map I want depending on mode, it works when I go first in insert mode and back to command mode afterwards, but always keeps that keymap when I switch windows, and not updates it back to the other command mode:

(defun xah-fly-command-mode-init ()
  "Set command mode keys.
Version 2020-04-28"
  (interactive)
  (setq xah-fly-insert-state-q nil)
  (xah-fly--update-key-map)
  (let ((map
     (if (eq major-mode 'exwm-mode)
         xah-fly-exwm-command-map
       xah-fly-command-map)))
    (setq xah-fly--deactivate-command-mode-func
      (set-transient-map map (lambda () t))))
  (modify-all-frames-parameters (list (cons 'cursor-type 'box)))
  (setq mode-line-front-space "C")
  (force-mode-line-update))

Do I have to make the keymaps local or something to not get overwritten by other buffers?

spiderbit commented 2 years ago

Adding that advises seem to fix it but it's a ugly hack:

(advice-add 'other-window :after (lambda (x)
                   (xah-fly-insert-mode-activate)
                   (xah-fly-command-mode-activate)))
(advice-add 'other-frame :after (lambda (x)
                  (xah-fly-insert-mode-activate)
                  (xah-fly-command-mode-activate)))
(advice-add 'switch-to-buffer :after (lambda (x)
                  (xah-fly-insert-mode-activate)
                  (xah-fly-command-mode-activate)))
spiderbit commented 2 years ago

my attempt to add exwm support to fly-keys