4

I am writing a small window navigation and manipulation package. Windows are numbered very much like WindowNumberingMode.

To make this concrete I have a series of commands:

"C-, 1"   ; Move focus to (select) window #1
..        ; ..
"C-, 9"   ; Move focus to (select) window #9
"C-, m 1" ; Move current buffer and focus to window #1
..        ; ..
"C-, m 9" ; Move current buffer and focus to window #9
"C-, x 1" ; Exchange current buffer and focus with window #1
..        ; ..
"C-, x 9" ; Exchange current buffer and focus with window #9
..        ; ..

At the time that I type "C-," I would like to offer visual prompts (similar to switch-window):

Can I do this and continue collecting the remainder of my key-sequence? Do I need "C-," to switch to a new minor-mode?

Glorfindel
  • 234
  • 1
  • 5
  • 13
John Yates
  • 201
  • 1
  • 5
  • 5
    I am not trying to demotivate your package development, but I believe the ace-window package gives this or similar functionality. You can study that package to see how it implements it. – Kaushal Modi Sep 17 '15 at 14:15
  • Do I need "C-," to switch to a new minor-mode? Yes. – Jordon Biondo Sep 17 '15 at 14:57
  • 1
    You can also look at hydra : C-, would be bound to the hydra body, and 1, 9... would be hydra heads. See :pre and :post to set up visual hints. – François Févotte Sep 17 '15 at 18:43
  • @kaushalmodi: Thanks for reminding me. I had ace-window installed but never really had started using it. It looks like just be behavior I want. – John Yates Sep 17 '15 at 22:35
  • @Francesco - Seems like it could work but a steeper learning curve that I want to invest in for this project. – John Yates Sep 17 '15 at 22:39
  • 2
    IIUC, this question is not a duplicate of Emacs bind key to prefix: in this question the OP wants the prefix to do something while still allowing the user to subsequently press keys to terminate the action. In the other question, the OP wants to "alias" a prefix sequence to a key binding, in such a way that for example pressing C-x C-x a is the same as pressing C-c a. – François Févotte Sep 18 '15 at 07:11
  • @Drew: I am not looking to create an alias. Given a key sequence '"C-, m 2"' I want '"C-h k"' to recognize it and tell me its overall effect. At the same time I want the mere act of typing '"C-,"' to put up the window prompts and establish the subsequent keymap. I know that such a design goes very much against the grain of emacs. But, hey... nothing ventured, nothing gained :-) The avy library (used by ace-window) and the hydra mechanism both can implement the prompting behavior. The problem is that neither makes the key sequences discoverable via traditional means. – John Yates Sep 18 '15 at 12:50
  • Meme combat, IMHO. That's why I pointed you to the answer I gave to that question, in addition to pointing you to that question. I believe that that answer answers your (slightly different, yes) question: If you want to have the prefix key act as both a single command and as a prefix key then that is of course impossible -- a key is bound to either a command or a keymap (or to a command that is a keymap). The behavior you are looking for is tantamount to the prefix key being bound to a command (perform an action) and being bound to a keymap (allow for other keys to follow). – Drew Sep 18 '15 at 14:48
  • What you can do is fiddle with set-transient-map (or overriding-terminal-local-map directly), to get the effect you want (an action possibly followed by additional keys with actions), but C-h k will still not show what you want to show. – Drew Sep 18 '15 at 14:51
  • @Drew: (Not sure what "meme combat" is. I think that you are suggesting that is what I am engaged in. Might be, but you would have to explain.) I understand "a key is bound to either a command or a keymap". What does your parenthetical "or to a command that is a keymap" mean? – John Yates Sep 18 '15 at 20:27
  • @Drew: Actually set-transient-map looks promising. Assuming that they are looking for disjoint sets of keys, does emacs handle properly multiple requests to set-transient-map from pre-command-hook functions? IOW were I to use set-transient-map would I be setting myself up for collision with other packages? – John Yates Sep 18 '15 at 20:38
  • 1
    I think that you can do what you want using set-transient-map. You can find examples of its use. I don't think there should be a problem with multiple requests, whether from pre-command-hook or otherwise - they are handled sequentially, after all. But give it a try, to see. – Drew Sep 18 '15 at 21:30
  • 1
    Wrt my parenthetical remark: A key can be bound to a command that, when invoked, returns a keymap. See C-h f keymapp and the Elisp manual, node Format of Keymaps. IOW, this is one possibility for (keymapp f): (and (symbolp f) (fboundp f) (keymapp (symbol-function f))) – Drew Sep 18 '15 at 21:35
  • @Drew: What you expressed as "a command that is a keymap" I now understand to be a form that returns a keymap. (I am C++ programmer learning lisp so I still get thrown by casual usage. This is my first serious project.) Anyway, thanks so much. Once again you have helped me out. Fun stuff to work on this weekend :-) – John Yates Sep 19 '15 at 01:43
  • Yes, but it is also a keymap, because it satisfies the predicate keymapp. Again, see that Elisp manual node. The notion of keymap includes this case. – Drew Sep 19 '15 at 04:26

0 Answers0