modalka icon indicating copy to clipboard operation
modalka copied to clipboard

A function to list all modalka state bindings

Open sriramkswamy opened this issue 8 years ago • 5 comments

Is it possible to add a function, say modalka-describe-bindings, which just lists all the bindings bound in modalka state (preferably with the function it is bound to)? This can be useful when I know I bound something but I forgot what I bound it too.

sriramkswamy avatar May 10 '16 22:05 sriramkswamy

Yes, that's possible. Not sure when I get to it, though, but I like the idea.

mrkkrp avatar May 11 '16 03:05 mrkkrp

Now that #10 is implemented and modalka-mode-map is using symbols, a convenient way to facilitate this might be to add a target-key symbol property at the point when each key is defined.

(At present it looks like this information is captured only in the lexical closure for each anonymous function, and the manual recommends against relying on the current closure implementation, so a new property seems like a better option than inspecting the closure environment.)

A way to list all modalka bindings would then be to iterate through the keymap and, for each key, get the target-key symbol property, look up the current binding for that target, and display them both (much as the docstring for a single binding now does).

(put SYM 'target-key target-key) ;; where SYM is the (make-symbol) value

(let ((sym (lookup-key modalka-mode-map KEY))) ;; obtain symbol
  (key-binding (get sym 'target-key))) ;; the target binding

phil-s avatar May 31 '16 07:05 phil-s

Even cooler would be a way to get the normal keymap descriptions (e.g. C-h b) to output the target bindings, but I can't see how to do that. We're well into C code territory (the describe_map and get_keyelt C functions are responsible, I believe). From a look at the latter function I'm guessing that using the fancy menu-item form of key binding might facilitate a solution via its :filter option, but I don't know very much about that.

phil-s avatar May 31 '16 08:05 phil-s

@phil-s, Do you want to make a PR for this feature? I'm quite busy these days, unfortunatelly. You seem to be advanced ELisp user who can handle it.

mrkkrp avatar May 31 '16 16:05 mrkkrp

Definitely maybe? I'll try to take a look at this sometime soon.

phil-s avatar May 31 '16 22:05 phil-s