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

remapping keys for ido-mode #108

Open
spiderbit opened this issue Oct 26, 2020 · 8 comments
Open

remapping keys for ido-mode #108

spiderbit opened this issue Oct 26, 2020 · 8 comments

Comments

@spiderbit
Copy link

spiderbit commented Oct 26, 2020

I read in the project readme about remapping keys which seems a good idea, yet it seems to be focused more or major modes at least if we use the with-eval-after-load I got what I want work with a lambda based mapping with a condition:

(use-package xah-fly-keys
...
:bind
(:map xah-fly-command-map
	("n" . (lambda () (interactive)
		 (cond ((ido-active) (ido-next-match))
		       (t (forward-char)))))
	("h" . (lambda () (interactive)
		 (cond ((ido-active) (ido-prev-match))
		       (t (backward-char)))))))

But this seems not very elegant to execute this code for every key-press of h and n and can lead to small lags.

But that seem to not work:
(define-key ido-completion-map [remap forward-char] #'ido-next-match)

Also with global-map it does not work, and if it would work I would need the correct hooks or whatever to make it remove it from global-map.

Any Idea what I do wrong. (btw that is with dvorak therefor h/n for forward/backward)

@wofwofwof
Copy link

Hello spiderboit,

I use here for example on doc-view:

(with-eval-after-load 'doc-view
(define-key doc-view-mode-map [remap scroll-up-command] #'doc-view-scroll-up-or-next-page)
(define-key doc-view-mode-map [remap scroll-down-command] #'doc-view-scroll-down-or-previous-page)
)

This should also work for you. I haven't combined this with use-package jet but I think this could work there, too.

@spiderbit
Copy link
Author

hmm I wander what should I then use instead of doc-view ido-mode or what?...

@wofwofwof
Copy link

I don't how ido is named but ido-mode is a good guess. Most packages are called [name]-mode or just [name]. If not sure you can look into the source.

@spiderbit
Copy link
Author

do you know what ido is? It's a minibuffer completion framework basically, so it's no real major-mode it's active in minibuffer. There are hooks to it like ido-setup-hook or ido-minibuffer-setup-hook.

I just searched with-eval-after-load and ido and found that:
https://emacs.stackexchange.com/questions/37235/ido-rebind-c-j-to-c-ret

I will test out the solution there if that works for me, I use xah-fly-keys so I am not sure it will work but it should, will report back after testing their solution or a adaptation of it.

@spiderbit
Copy link
Author

Well just looked at the code and not created a new sparsemap as child map like in that solution but took the 'ido and ido-common-complition-map and it works:

(with-eval-after-load 'ido
  (define-key ido-common-completion-map [remap forward-char] #'ido-next-match)
  (define-key ido-common-completion-map [remap backward-char] #'ido-prev-match))

So that stackexchange bug helped me to find the correct names.

@dvdkhlng
Copy link

Everybody seems to be reinventing the wheel here. I found a different solution for making the pseudo-arrow keys in command-mode work everywhere (though not extensively tested yet, this may badly break your emacs). See also #137 .

(defun dk-arrow-up ()
  "Do what <Up> would do."
  (interactive)
  (call-interactively (key-binding [up])))

(defun dk-arrow-down ()
  "Do what <Down> would do."
  (interactive)
  (call-interactively (key-binding [down])))

(defun dk-arrow-left ()
  "Do what <Left> would do."
  (interactive)
  (call-interactively (key-binding [left])))

(defun dk-arrow-right ()
  "Do what <Right> would do."
  (interactive)
  (call-interactively (key-binding [right])))

(xah-fly--define-keys xah-fly-command-map
                      '(
                        ("t" . dk-arrow-down)
                        ("c" . dk-arrow-up)
                        ("h" . dk-arrow-left)
                        ("n" . dk-arrow-right))) 

@spiderbit
Copy link
Author

The problem with that solution is that in command mode generally this keybindings are active, but I use exwm and that would also translate this buttons in exwm buffers. For browser windows that wouldn't hurt, but for xterm window at least currently I can type this letters in command mode :)

At least it has pros and cons.

@dvdkhlng
Copy link

dvdkhlng commented Feb 18, 2022

The problem with that solution is that in command mode generally this keybindings are active, but I use exwm and that would also translate this buttons in exwm buffers. For browser windows that wouldn't hurt, but for xterm window at least currently I can type this letters in command mode :)

I haven't been bold enough to do the move to exwm yet, so this is beyond my current level of experience. But as stated in other comments here, I currently think about treating command mode like a sticker Hyper modifier key (using e.g. the key-translation-map faciltiy, see #133. That would turn those letters "tchn" into H-t H-c H-h H-n respectively, for use in ido's keymap as required. Yes I see you already commented on that idea in #133.

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

3 participants