dfdeshom/helm-mt

create keymap for helm-mt?

blaenk opened this issue · 9 comments

It would be nice if helm-mt defined and used its own keymap so that we could add bindings to them. For example, I'd like to add one to open/switch to a terminal in a horizontal split.

I must say, I'm not too familiar with keymaps in emacs. @blaenk could you give an example as to how you'd use this in your emacs config? Thanks!

Sure thing. Here is an example of a helm source I created. 1390 creates the keymap making it derive from helm-map, and then you set it with :keyword the-map when creating the source. That's a helm source I created so I didn't need to access keymap, since I created the keymap myself.

But look at this example where I'm adding a custom binding to a keymap of a custom/third-party helm source (helm-projectile). That's the kind of thing that would be enabled by creating a keymap for the helm source. Basically it creates a keymap specific for that context, so that creating a bind on that keymap would ensure that it only works in that context.

Thanks for the pointers, this makes a little more sense to me now. I've created a pull request here if you want to give some feedback about my approach: #7

Awesome thanks! I'll check it out when I have a chance, possibly later today.

Sorry @dfdeshom but I just barely got a chance to actually try it, and it doesn't seem to be working. Even the binding that you created, C-c m doesn't seem to work. I'm not sure what could account for this, but one difference I know of is the way you're creating the helm source. The way I have seen it done (and the way I do it myself) is using a :keymap key-var. Did C-c m work for you? If so, to rule things out on my end.

@blaenk I changed the shortcut to C-c n : 1432008 . Sorry about that. Still, there's a bug where the shortcut doesn't work when there are candidate terminals still present. I will fix that.

I'm using "old-style" helm sources, so (keymap .,$map) should work. I've been lazy about using the new class. See helm-swoop for example of that old style: https://github.com/ShingoFukuyama/helm-swoop/blob/master/helm-swoop.el

@blaenk here is the fix: 3a5695e . Let me know if that works for you

Cool thanks, but it wasn't just a matter of the bind, I just thought that might have been indicative of a more general problem, didn't know it was rebound.

In any case, the problem I'm having is that I can't add keys to the map like I can with other helm sources, by doing something like this:

(define-key helm-mt/keymap
  (kbd "M-h") 'blaenk/helm-horizontal-split)

For example, I'm able to do this:

  (define-key helm-find-files-map
    (kbd "M-h") 'blaenk/helm-horizontal-split)

  (define-key helm-buffer-map
    (kbd "M-h") 'blaenk/helm-horizontal-split)

And now I can press M-h to call that function within the helm-find-files and helm-buffers-list sources. I did the same with helm-mt/keymap but pressing that has no effect, and I put a (message "triggered") in the function so that I know it's not being called at all.

Haha, I was busy at the time that I looked at the commit so I quickly skimmed it, but yeah turning it into a function does make sense, and it does work now!

Thanks for being quick and helpful @dfdeshom! Great work, I appreciate it.