Re: bind a complex key sequence?

Fruhwirth Clemens <clemens endorphin org> writes:

> On Fri, 2005-09-02 at 22:31 +0800, William XWL wrote:
>> A correct one:
>> (setq my-ctrl-c-keymap (make-keymap))
>> (bind-keys my-ctrl-c-keymap "b" 'maximize-window-fullscreen-toggle)
>> (bind-keys global-keymap "C-c" my-ctrl-c-keymap)
>> BUT ! Then i lose "C-c" prefix in Emacs ! sigh, i've to give up.
> Probably you can create a catch all binding in the sub keymap for C-c
> and synthesize the key stroke sequence for the input-focus window if the
> catch all function is hit. But I'm not sure if there is such a catch all
> function for key maps.

`synthesize-event' helps a lot. I finished with following simple
function. At least i get what i wanted. Thank you, guys. 

(defun my-bind-keys (char function &optional preserve-prefix)
  "If optional PRESERVE-PREFIX t, keep prefix untouched in Emacs.
an e.g,

(bind-keys global-keymap \"C-c\"
	   '(my-bind-keys \"b\" popup-window-list \"C-c\"))

This will bind \"C-c b\" to popup-window-list, but not in
Emacs. And in Emacs, you could bind it to call \"sawfish-client
-f popup-window-list\", thus you get the same behaviour of \"C-c
b\" without losing PRESERVE-PREFIX."
  (if (and preserve-prefix
	   (string= (window-class (input-focus)) "Emacs"))
      (synthesize-event preserve-prefix (input-focus))
    (when (grab-keyboard)
      (let ((read-event
	     (lambda ()
	       (throw 'read (event-name (current-event))))))
	      (add-hook 'unbound-key-hook read-event)
	      (when (string= (catch 'read (recursive-edit)) char)
		(funcall function)))
	  (remove-hook 'unbound-key-hook read-event)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]