From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Lennart Borgman (gmail)" Newsgroups: gmane.emacs.devel Subject: Re: A simple implementation of context-sensitive keys Date: Wed, 10 Sep 2008 12:36:10 +0200 Message-ID: <48C7A31A.3000500@gmail.com> References: <87y72079mg.fsf@thinkpad.tsdh.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1221043614 5988 80.91.229.12 (10 Sep 2008 10:46:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 10 Sep 2008 10:46:54 +0000 (UTC) To: emacs-devel@gnu.org, Tassilo Horn Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Sep 10 12:47:49 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KdNEj-0004Yc-9M for ged-emacs-devel@m.gmane.org; Wed, 10 Sep 2008 12:47:49 +0200 Original-Received: from localhost ([127.0.0.1]:57388 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KdNDi-0005fc-72 for ged-emacs-devel@m.gmane.org; Wed, 10 Sep 2008 06:46:46 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KdN3j-000350-Ia for emacs-devel@gnu.org; Wed, 10 Sep 2008 06:36:28 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KdN3f-00033f-NE for emacs-devel@gnu.org; Wed, 10 Sep 2008 06:36:25 -0400 Original-Received: from [199.232.76.173] (port=50116 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KdN3e-00033P-RR for emacs-devel@gnu.org; Wed, 10 Sep 2008 06:36:23 -0400 Original-Received: from ch-smtp01.sth.basefarm.net ([80.76.149.212]:48666) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KdN3d-00089b-1E for emacs-devel@gnu.org; Wed, 10 Sep 2008 06:36:21 -0400 Original-Received: from c83-254-151-87.bredband.comhem.se ([83.254.151.87]:59797 helo=[127.0.0.1]) by ch-smtp01.sth.basefarm.net with esmtp (Exim 4.68) (envelope-from ) id 1KdN3a-0003VC-6H; Wed, 10 Sep 2008 12:36:19 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666 In-Reply-To: <87y72079mg.fsf@thinkpad.tsdh.de> X-Enigmail-Version: 0.95.7 X-Antivirus: avast! (VPS 080909-0, 2008-09-09), Outbound message X-Antivirus-Status: Clean X-Originating-IP: 83.254.151.87 X-Scan-Result: No virus found in message 1KdN3a-0003VC-6H. X-Scan-Signature: ch-smtp01.sth.basefarm.net 1KdN3a-0003VC-6H 24e0d0f855da17827fe46715318e42cd X-detected-kernel: by monty-python.gnu.org: Error: [-] ERROR: /var/run/p0f.sock: Connection refused X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:103756 Archived-At: Tassilo Horn wrote: > Hi all, > > to get the full power out of emacs, I use quite a lot of different minor > modes with a ton of home-brewn functions. To make them quickly > accessible, I've bound them to some key. But "good" keys are rare, and > so I started writing special dispatching commands which DTRT dependend > on the context they're used in. But that's quite cumbersome, because > ideally you have to recognize each command which would normally be bound > to the key, too. > > So I've come up with this macro, which creates such a dispatching > command automagically. If none of the context predicates match, the > default command bound to the key will be executed. > > --8<---------------cut here---------------start------------->8--- > (defmacro define-context-key (mode key preds-funs) > "Bind KEY to an anonymous dispatching command in MODE. > PREDS-FUNS is an alist with elements of the form Hi Tassilo I think there are a number of packages out there doing quite similar things: smart-tab, tabkey2, hippi-expand. Those are all focused on completion, but that is more a conceptual focus (which I think is good). By default they bind the Tab key (which you also did in your example). Maybe it would be good to generalize that as you did here. In tabkey2.el (did you notice it when I sent it to this list?) I have tried to write the supporting functions needed to make the key bindings transparent to the user. You are welcome to contribute to it if you want too. The latest version is always in nXhtml on Launchpad. BTW Yasnippet is a kind of completion function.