Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!vsi1!wyse!td2cad!mipos3!omepd!merlyn From: merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) Newsgroups: gnu.emacs Subject: another rebind-this-key (was Re: rebind-key, version 2) Summary: slight hack Message-ID: <4442@omepd.UUCP> Date: 16 May 89 18:16:19 GMT References: Sender: news@omepd.UUCP Reply-To: merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) Distribution: gnu Organization: Stonehenge; netaccess via BiiN, Hillsboro, Oregon, USA Lines: 41 Supersedes: <4440@omepd.UUCP> In-reply-to: bbc@titan.rice.edu (Benjamin Chase) In article , bbc@titan (Benjamin Chase) writes: | (defun rebind-this-key () | "Ask for a new binding for the key sequence that invoked this function. | This function is a useful binding for unused or unallocated function keys." | (interactive) | (let ((tck (this-command-keys))) | (rebind-key global-map tck | (command-execute | '(lambda (func) | (interactive "CFunction to bind to this key: ") func))))) That 'command-execute' looked a little ugly. Here's my hack: (defun rebind-this-key (key command) "Set KEY to invoke COMMAND, preferring a local map if present. Interactively, KEY is the key that invoked this routine, while COMMAND is prompted for, making this function useful to bind unused or unallocated keys." (interactive (let ((tck (this-command-keys))) (list tck (read-command (format "%s is currently undefined; define as: " (key-description tck)))))) (let ((map (current-local-map))) (if map (let ((lk (lookup-key map key))) (if (or (null lk) (numberp lk)) (setq map (current-global-map)))) (setq map (current-global-map))) (define-key map key command))) It's a standalone, and doesn't use your functions, but you can hack it around to do so. Enjoy. -- ***** PLEASE IGNORE THE ADDRESS IN THE HEADER ***** /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095===\ { ...!uunet!agora.hf.intel.com!merlyn } \=Cute quote: "Welcome to Oregon... home of the California Raisins!"=/