On 7/4/10 5:14 PM, Michał Kazior wrote: > Hello, > > What I'd like to do is to bind a function to a key sequence (not a > single-byte one - e.g. F1, Arrow Up, etc.). > > One would try: > > hello() { echo world; } > bind -x '"ab": hello' > > The above works if typed "ab". But then: > > hello() { echo world; } > bind -x '"abc": hello' > > does not and prints (when "abc" is typed): > > ./script: line 6: bash_execute_unix_command: cannot find keymap for command
Yeah, this is a problem without a clean solution. Readline implements multi-character key sequences using a chain of keymaps. (This is how "ab", "abx", and "abc" can all be bound to different things.) When it dispatches to the bound function, bash_execute_unix_command here, the function has access only to the first keymap in the chain and the last. Bash implements `bind -x' by keeping a parallel set of keymaps holding the command to be invoked as a macro. The readline key sequence resolves to bash_execute_unix_command. You can see the problem. For key sequences longer than two characters, bash_execute_unix_command doesn't have any good way to follow the chain of keymaps to find the right command. It knows only the first keymap, the final keymap, and the key in the final keymap. There is one good way to fix it, but it requires changing the readline external interface, which will have to wait until the next major version is released. There is probably a clumsy way to do it now, but the code doesn't implement it. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/