From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: HELP: One Bindkey for Two Different Commands Date: Wed, 21 Nov 2007 01:33:57 -0800 Message-ID: References: <85y7cshwhr.fsf@lola.goethe.zz> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1195637757 26855 80.91.229.12 (21 Nov 2007 09:35:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 21 Nov 2007 09:35:57 +0000 (UTC) To: Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Nov 21 10:35:53 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Iulzm-0005M7-QK for geh-help-gnu-emacs@m.gmane.org; Wed, 21 Nov 2007 10:35:47 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IulzY-0000gx-JD for geh-help-gnu-emacs@m.gmane.org; Wed, 21 Nov 2007 04:35:32 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Iulz2-0000c9-3j for help-gnu-emacs@gnu.org; Wed, 21 Nov 2007 04:35:00 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Iulyz-0000Wx-6O for help-gnu-emacs@gnu.org; Wed, 21 Nov 2007 04:34:58 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Iulyy-0000WX-M0 for help-gnu-emacs@gnu.org; Wed, 21 Nov 2007 04:34:56 -0500 Original-Received: from rgminet01.oracle.com ([148.87.113.118]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Iulyx-0001YT-Pj for help-gnu-emacs@gnu.org; Wed, 21 Nov 2007 04:34:55 -0500 Original-Received: from agmgw2.us.oracle.com (agmgw2.us.oracle.com [152.68.180.213]) by rgminet01.oracle.com (Switch-3.2.4/Switch-3.1.6) with ESMTP id lAL9YqTI021085 for ; Wed, 21 Nov 2007 02:34:52 -0700 Original-Received: from acsmt351.oracle.com (acsmt351.oracle.com [141.146.40.151]) by agmgw2.us.oracle.com (Switch-3.2.0/Switch-3.2.0) with ESMTP id lAL4gRsR030125 for ; Wed, 21 Nov 2007 02:34:52 -0700 Original-Received: from dhcp-amer-csvpn-gw1-141-144-64-24.vpn.oracle.com by acsmt350.oracle.com with ESMTP id 3379496781195637624; Wed, 21 Nov 2007 01:33:44 -0800 X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) In-Reply-To: <85y7cshwhr.fsf@lola.goethe.zz> Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 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:49389 Archived-At: > >> Why waste two bindkeys on two similar commands when you can simply > >> write a function to choose the between commands based on context? > >> > >> Unfortunately, this very simple idea doesn't seem to work for me. > >> Here's what I have in my .emacs so far: > >> > >> (defun ya-ya () > >> (if (cdr (window-list)) > >> 'other-window > >> 'switch-to-buffer)) > >> > >> (global-set-key "\M-o" (ya-ya)) > >> Any ideas how this might be accomplished? > > > > To turn a function into a command, add an `interactive' spec. > > > > The functions other-window and switch-to-buffer require arguments. > > Your point being? other-window and switch-to-buffer both have an > interactive spec. Just trying to help. To be more clear: You need to call function `other-window' or `switch-to-buffer', not just return the symbol. And calling them means providing their required arguments - use either (call-interactively 'other-window) or (other-window ). > > The second argument to global-set-key is a command, not a list such as > > you have supplied. > > He does not supply a list. He supplies a command. Sorry, I misread '(ya-ya) instead of (ya-ya). > The problem merely is that he makes his choice of command at > the time of global-set-key, not at keypress time. To be more helpful: You need to pass the symbol `ya-ya', instead of calling the function `ya-ya': (global-set-key "\M-o" 'ya-ya). A key is bound to a command (or its symbol), not to the result of calling the command. This is the opposite mistake from that made with `other-window' (returning the symbol instead of calling the function). As David suggested, you called `ya-ya' at key-binding time, so one of the symbols it returns at that time, not `ya-ya', gets bound to `M-o'.