From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: Keybindings and minor modes Date: Thu, 29 Dec 2005 12:23:52 -0700 Message-ID: References: <1135822695.537535.182680@f14g2000cwb.googlegroups.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1135884330 4017 80.91.229.2 (29 Dec 2005 19:25:30 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 29 Dec 2005 19:25:30 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 29 20:25:28 2005 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Es3Ox-0000tf-I8 for geh-help-gnu-emacs@m.gmane.org; Thu, 29 Dec 2005 20:25:28 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Es3QJ-000472-Tz for geh-help-gnu-emacs@m.gmane.org; Thu, 29 Dec 2005 14:26:52 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Es3PH-0003oJ-Fl for help-gnu-emacs@gnu.org; Thu, 29 Dec 2005 14:25:47 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Es3PE-0003lx-Th for help-gnu-emacs@gnu.org; Thu, 29 Dec 2005 14:25:46 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Es3PE-0003ln-Ld for help-gnu-emacs@gnu.org; Thu, 29 Dec 2005 14:25:44 -0500 Original-Received: from [80.91.229.2] (helo=ciao.gmane.org) by monty-python.gnu.org with esmtp (TLS-1.0:RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1Es3Pd-0000ut-0y for help-gnu-emacs@gnu.org; Thu, 29 Dec 2005 14:26:09 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Es3Ng-0000Ow-0H for help-gnu-emacs@gnu.org; Thu, 29 Dec 2005 20:24:08 +0100 Original-Received: from 207.167.42.60 ([207.167.42.60]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 29 Dec 2005 20:24:07 +0100 Original-Received: from ihs_4664 by 207.167.42.60 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 29 Dec 2005 20:24:07 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-To: help-gnu-emacs@gnu.org Original-Lines: 47 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 207.167.42.60 User-Agent: Mozilla Thunderbird 0.9 (X11/20041105) X-Accept-Language: en-us, en In-Reply-To: <1135822695.537535.182680@f14g2000cwb.googlegroups.com> X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:32291 Archived-At: batkins57@gmail.com wrote: > I'd like to bind a command to tab in a minor mode I'm writing, but I'd > also like to preserve any command that might have been attached to that > key before making my binding (such as indentation). In other words, > I'd like to add functionality to an existing keybinding without > completely overwriting the binding. > > The solution I came up with was to simply store the currently bound > command in a buffer-local variable whenever the minor mode is invoked. > Then the keys are bound to functions that provide my additional > functionality and then funcall the old bindings. This works, but I > wonder if there isn't a cleaner way to pass a keychord event on to the > next handler. The code I have now is pretty ugly, since a key bound to > self-insert-command has to be handled separately so that > self-insert-command will get an argument of 0. I think you could avoid storing the command in a local variable by accessing the local binding (defined by the major mode) or global binding dynamically. That would simplify things a little. I'll admit, I don't understand the point of calling (self-insert-command 0). Perhaps a better approach altogether would be to add a pre-command-hook that would check the key that was used to invoke it: (defun ehinter-pre-command-hook () "Run `ehinter-hint' in Ehinter Minor Mode, when invoked via SPC, TAB, or RET." (when (and ehinter-mode (let ((key (this-single-command-keys))) (and (= (length key 1)) (member (aref key 0) '(? ?\t ?\r))))) ; SPC, TAB, or RET (ehinter-hint))) (add-hook 'pre-command-hook 'ehinter-pre-command-hook) Then the ehinter-mode function just needs to set or unset the buffer-local ehinter-mode variable. You could tweak that to have the ehinter-mode function add or remove ehinter-pre-command-hook from the buffer-local pre-command-hook, to avoid affecting other buffers. -- Kevin Rodgers