From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: A simple implementation of context-sensitive keys Date: Wed, 10 Sep 2008 13:49:48 -0400 Message-ID: References: <87y72079mg.fsf@thinkpad.tsdh.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1221069007 9504 80.91.229.12 (10 Sep 2008 17:50:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 10 Sep 2008 17:50:07 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Sep 10 19:51:03 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 1KdTqI-0007zY-H8 for ged-emacs-devel@m.gmane.org; Wed, 10 Sep 2008 19:51:02 +0200 Original-Received: from localhost ([127.0.0.1]:34574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KdTpI-00053H-5y for ged-emacs-devel@m.gmane.org; Wed, 10 Sep 2008 13:50:00 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KdTpD-00052q-6a for emacs-devel@gnu.org; Wed, 10 Sep 2008 13:49:55 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KdTpA-00052D-Vk for emacs-devel@gnu.org; Wed, 10 Sep 2008 13:49:54 -0400 Original-Received: from [199.232.76.173] (port=36268 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KdTpA-000523-J1 for emacs-devel@gnu.org; Wed, 10 Sep 2008 13:49:52 -0400 Original-Received: from ironport2-out.pppoe.ca ([206.248.154.182]:38135 helo=ironport2-out.teksavvy.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KdTpA-0002Tm-4P for emacs-devel@gnu.org; Wed, 10 Sep 2008 13:49:52 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhwGAOSlx0hFxIqP/2dsb2JhbACBZbcxgWSBBg X-IronPort-AV: E=Sophos;i="4.32,373,1217822400"; d="scan'208";a="26620042" Original-Received: from 69-196-138-143.dsl.teksavvy.com (HELO pastel.home) ([69.196.138.143]) by ironport2-out.teksavvy.com with ESMTP; 10 Sep 2008 13:49:49 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id A680285E5; Wed, 10 Sep 2008 13:49:48 -0400 (EDT) In-Reply-To: <87y72079mg.fsf@thinkpad.tsdh.de> (Tassilo Horn's message of "Wed, 10 Sep 2008 09:17:27 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. 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:103774 Archived-At: > 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. Another way to get a similar result is: (define-key '(menu-item "dummy" :filter (lambda (binding) (when binding)))) It's tempting to use the :enable property instead of :filter, but sadly, the :enable property is only obeyed by the menu-construction code, not by the key-lookup code. In any case, the main problem with such things (whichever way they're implemented) is that the rest of Emacs doesn't know and/or expect such condition bindings, so C-h k gives only partial information, and similarly where-is doesn't know how to tell the whole story. Stefan