talgu · 2022-09-25 14:55
I'm not very good at elisp, or programming in general, but I've been reading through Modalka and Boon's source and I haven't really found much that specifically says "this is the modal part" in big neon letters. But I did notice that Modalka defines fewer keymaps than Boon does. Modalka only provides two modes for editing and everything else, while Boon provides more modes.
So I suspect that really what's happening is that they are managing keymaps. Is this actually true? Or am I missing something important?
SequentialDesign · 2022-09-25 15:57
yes, they can be (though, not necessarily). check out my comment on the Modalka github page:
> Note that the target key binding cannot be a prefix key (prefix keys will be ignored).
I'm not sure what you (Mark Karpov) mean by this, but I want to make it clear that this works because it sounds like you mean prefix keys are not possible with Modalka:
```
(setq keymap (make-sparse-keymap))
(define-key keymap "C-x" #'ctl-x-map)
(define-key modalka-mode-map "x" ctl-x-map)
(define-key ctl-x-map (kbd "e") 'eval-last-sexp)
(define-key ctl-x-map (kbd "s") 'save-buffer)
```
`x` works like `CTL-x` does. that is, x acts just like the normal prefix key.
I think it's a game changer. hat tip to u/Horrih for the tip
PS apologies if I misunderstood you.
end of GitHub comment.
Modalka is great. and thanks again to Horrih for the great help
7890yuiop · 2022-09-26 01:22
> I suspect that really what's happening is that they are managing keymaps. Is this actually true?
If you type a key/sequence in Emacs and something happens, it's because of a keymap.
poiu- · 2022-09-26 07:00
Yes. Overriding keymaps, then managing the overrides.
talgu · 2022-09-27 03:46
Thanks, stating it this way makes the whole thing fairly easy to understand. :)
talgu · 2022-09-27 03:47
This sounds like there's a lot of potential for things to become messy. I'm assuming that this means major/minor modes create keymaps to do things. Won't this lead to clashes?
talgu · 2022-09-27 04:41
Could you explain a bit more about what you mean with "though, not necessarily"? That GitHub comment was very valuable thank you! It didn't occur to me that this is possible.
7890yuiop · 2022-09-27 05:15
Read all of https://www.masteringemacs.org/article/mastering-key-bindings-emacs -- it should explain most questions you might have about keymaps and key bindings generally.
Clashes are in part covered by https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Binding-Conventions.html
SequentialDesign · 2022-09-27 07:50
yeah, so, with Modalka, you can tap into other keymaps with Modalka's standard translation abilities, e.g.
```
(modalka-define-kbd "a" "C-a") ; move-beginning-of-line
(modalka-define-kbd "e" "C-e") ; move-end-of-line
```
or you can create your own Modalka map that does not rely on anything else
```
(define-key modalka-mode-map (kbd "a") #'move-beginning-of-line)
(define-key modalka-mode-map (kbd "e") #'move-end-of-line)
```
I think the "correct" way, if such a thing exists, is to tap into other keymaps so that they are accessible when I'm not in Modalka, like using `ctl-x-map` above. I believe this is proper technique. it's easier to remember and accessible everywhere
talgu · 2022-09-27 21:08
This is a really awesome idea thanks! :) Do you think one could use this technique to have one prefix key that defaults to the current major mode? Or would this have to be set for every mode?
talgu · 2022-09-27 21:08
Thank you, I'll read through that. :)
SequentialDesign · 2022-09-28 08:07
interest idea. i hadn't thought about it. i don't know