Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to change keymap for exwm #107

Open
spiderbit opened this issue Oct 12, 2020 · 2 comments
Open

Try to change keymap for exwm #107

spiderbit opened this issue Oct 12, 2020 · 2 comments

Comments

@spiderbit
Copy link

I have succesfully changed the keymap for exwm (X) buffers, in command mode by removing the commands from the command-map when I switch to that buffers and setting it back when I entering a normal emacs buffer.

(defun sb/keys-change (x)
  "docstring"
  (if (equal 'cons (type-of mode-name))
      (progn 
	(setq xah-fly-command-map (assq-delete-all ?q xah-fly-command-map))
	(setq xah-fly-command-map (assq-delete-all ?c xah-fly-command-map))
	(setq xah-fly-command-map (assq-delete-all ?t xah-fly-command-map))
	(setq xah-fly-command-map (assq-delete-all ?, xah-fly-command-map))
	(setq xah-fly-command-map (assq-delete-all ?f xah-fly-command-map)))
    (progn
       (bind-key (kbd "q") 'xah-cut-line-or-region xah-fly-command-map)
       (bind-key (kbd "c") 'previous-line xah-fly-command-map)
       (bind-key (kbd "t") 'next-line xah-fly-command-map)
       (bind-key (kbd ",") 'xah-shrink-whitespaces xah-fly-command-map)
       (bind-key (kbd "f") 'undo xah-fly-command-map))))
(advice-add 'other-window :after #'sb/keys-change)
(advice-add 'other-frame :after #'sb/keys-change)
(add-hook 'buffer-list-update-hook
	     (lambda () (sb/keys-change nil)))

The Problem is that I create some sort of a whitelist, while in reality I would need more like a blacklist also it's not great to hardcode the rebinding of the buttons I don't want to be active in command mode in X buffers, because if upstream the mapping would change, I would have to update my code.

I thought about saving somewhere a backup of the "full" command-map and just reseting it when I enter a normal emacs buffer with something like that:
(setq sb/shadow-map (copy-keymap xah-fly-command-map))
and instead of the bind-key commands then:
(setq xah-fly-command-map (copy-keymap sb/shadow-map))

But for some reason that does not work, then I looked at the Readme and tried to remap some keys:
(define-key exwm-mode-map [remap next-line] (lambda () (interactive) (insert-char ?t)))

But neither remap it to nil nor insert-char does work, because inserting is not the same as sending the key to the window/buffer, I think the remap does not work for my problem beacuse I need to "unset" the key not set it to something different.

what seems to reset the mapping pretty good is to evaluate the expression:

(xah-fly--define-keys
 xah-fly-command-map...

in xah-fly-keys-el, but that is no function so I can't directly call it.

@spiderbit
Copy link
Author

btw there might be better ways to detect it but mode-name for exwm buffers are cons not a string, so if mode-name is type cons it's a X buffer.

@spiderbit
Copy link
Author

I guess 1 at least partial solution would be to put the xah-fly--define-keys expression in a function, and call it directly afterwards? Then you could call it from outside too, that could replace the else part of my solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant