From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: storm@cua.dk (Kim F. Storm) Newsgroups: gmane.emacs.devel Subject: Re: Suggestion: Simple way to make conditional key bindings. Date: 23 Aug 2002 15:16:11 +0200 Sender: emacs-devel-admin@gnu.org Message-ID: <5xadnd3eck.fsf@kfs2.cua.dk> References: <3D49FF140074EFAE@mel-rta7.wanadoo.fr> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1030104982 31897 127.0.0.1 (23 Aug 2002 12:16:22 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 23 Aug 2002 12:16:22 +0000 (UTC) Cc: Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17iDMS-0008IM-00 for ; Fri, 23 Aug 2002 14:16:20 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 17iDpo-0001Zn-00 for ; Fri, 23 Aug 2002 14:46:41 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17iDNd-000376-00; Fri, 23 Aug 2002 08:17:33 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 17iDLw-00034d-00 for emacs-devel@gnu.org; Fri, 23 Aug 2002 08:15:48 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 17iDLu-00034R-00 for emacs-devel@gnu.org; Fri, 23 Aug 2002 08:15:48 -0400 Original-Received: from mail.filanet.dk ([195.215.206.179]) by monty-python.gnu.org with esmtp (Exim 4.10) id 17iDLu-00034M-00 for emacs-devel@gnu.org; Fri, 23 Aug 2002 08:15:46 -0400 Original-Received: from kfs2.cua.dk.cua.dk (kfs2.local.filanet.dk [192.168.1.182]) by mail.filanet.dk (Postfix) with SMTP id 56F597C016; Fri, 23 Aug 2002 12:15:45 +0000 (GMT) Original-To: "David PONCE" In-Reply-To: <3D49FF140074EFAE@mel-rta7.wanadoo.fr> (added by postmaster@wanadoo.fr) Original-Lines: 58 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:6790 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:6790 "David PONCE" writes: > > (global-set-key "\C-y" > > '(cond > > ((and kill-ring (table-recognize-table (car kill-ring))) > > yank-with-properties) > > (t yank))) > > > > > > It seems that you can do something similar this way: > > (global-set-key "\C-y" '(menu-item "my-filter" :filter my-filter)) > > (defun my-filter (&rest ignore) > (cond > ((and kill-ring (table-recognize-table (car kill-ring))) > 'yank-with-properties) > (t 'yank))) > > Am I wrong? Not at all [that's more or less how it is implemented]. But IMO, the `menu-item' syntax is awful, and using a filter function is an added complexity which is pretty unflexible. I failed to mention a very important benefit of integrating this in the keymaps directly: It will then be quite trivial to enhance `define-key' to handle conditional bindings: (define-key global-map "\C-y" 'yank) ; this sets the default (define-key global-map "\C-y" 'yank-with-properties '(and kill-ring (table-recognize-table (car kill-ring)))) The second call would automatically changes the non-cond binding into a cond binding with the previous binding as default. To remove a conditional binding, we could use either of the following: (define-key global-map "\C-y" 'yank-with-properties t) (define-key global-map "\C-y" nil '(and kill-ring (table-recognize-table (car kill-ring)))) Removing the last condtional binding could collapse the resulting (cond ((t yank))) back into 'yank. -- Kim F. Storm http://www.cua.dk