From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.help Subject: Re: Prefix-Arg (non-interactive!) in Info Date: Fri, 13 Aug 2010 22:33:01 +0300 Message-ID: <831va2ux3m.fsf@gnu.org> References: <878w4avcir.fsf@mean.albasani.net> <838w4av8xg.fsf@gnu.org> <87r5i2ttle.fsf@mean.albasani.net> <837hjuv6jn.fsf@gnu.org> <87fwyitrgv.fsf@mean.albasani.net> NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1281728120 3887 80.91.229.12 (13 Aug 2010 19:35:20 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 13 Aug 2010 19:35:20 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Aug 13 21:35:17 2010 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.69) (envelope-from ) id 1Ok027-0001Be-QY for geh-help-gnu-emacs@m.gmane.org; Fri, 13 Aug 2010 21:35:17 +0200 Original-Received: from localhost ([127.0.0.1]:42977 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ok025-0005C8-Ka for geh-help-gnu-emacs@m.gmane.org; Fri, 13 Aug 2010 15:35:13 -0400 Original-Received: from [140.186.70.92] (port=56364 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ok012-0005B5-8G for help-gnu-emacs@gnu.org; Fri, 13 Aug 2010 15:34:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Ok00z-0007td-Ta for help-gnu-emacs@gnu.org; Fri, 13 Aug 2010 15:34:07 -0400 Original-Received: from mtaout21.012.net.il ([80.179.55.169]:46744) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Ok00z-0007tM-Gv for help-gnu-emacs@gnu.org; Fri, 13 Aug 2010 15:34:05 -0400 Original-Received: from conversion-daemon.a-mtaout21.012.net.il by a-mtaout21.012.net.il (HyperSendmail v2007.08) id <0L7300K00VJH0N00@a-mtaout21.012.net.il> for help-gnu-emacs@gnu.org; Fri, 13 Aug 2010 22:34:04 +0300 (IDT) Original-Received: from HOME-C4E4A596F7 ([77.126.102.143]) by a-mtaout21.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0L7300JRVVORRA90@a-mtaout21.012.net.il> for help-gnu-emacs@gnu.org; Fri, 13 Aug 2010 22:34:04 +0300 (IDT) In-reply-to: <87fwyitrgv.fsf@mean.albasani.net> X-012-Sender: halo1@inter.net.il X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) 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:74624 Archived-At: > From: Memnon Anon > Cc: help-gnu-emacs@gnu.org > Date: Fri, 13 Aug 2010 19:04:30 +0200 > > The function asked for was org-clock-in. > > ,----[ org-clock-in ] > | org-clock-in is an interactive compiled Lisp function. > | > | (org-clock-in &optional SELECT START-TIME) > | > | Start the clock on the current item. > | If necessary, clock-out of the currently active clock. > | With a prefix argument SELECT (C-u), offer a list of recently clocked tasks to > | clock into. When SELECT is C-u C-u, clock into the current task and mark > | is as the default task, a special task that will always be offered in > | the clocking selection, associated with the letter `d'. > `---- > > I knew `C-u' = 4 (and not "t" as someone suggested), so I tried > (global-set-key (kbd "") (lambda () (interactive) (org-clock-in 4))) > ^^^^^^^^^^^^^^^ > This did not work, but I was hardly surprised. You are wrong assuming that the prefix arg is always 4. Its ``value'' depends on how the function accesses it; the node in the ELisp manual that Drew pointed to spells out the possible ``values''. In addition, it matters how the function tests the possible values of the argument; if the function just checks that its argument (in this case, SELECT) is non-nil, then '(4) will do, but so will '(foobar). > (defun multiply-by-seven (number) ; Interactive version. > "Multiply NUMBER by seven." > (interactive "p") > (message "The result is %d" (* 7 number))) > > (multiply-by-seven 2) --> 14 > M-8 M-x multiply-by-seven --> 56 > C-u M-x multiply-by-seven --> 28 > Works for this function... > > So I tried to figure out in what form org-clock-in wanted its argument > of 4 passed in. > > And I found nothing, until I turned to google. It would be better (and more educational) to simply read the code of the function (and submit a bug report regarding the unclear doc string). In there, you'd see that org-clock-in uses (interactive "P"), which assigns the raw prefix argument to SELECT, and it tests its value like this: (when (equal select '(4)) which tells you that it really wants the list '(4) -- not very clean, I'd say. > Now I am really confused: > I expected this to work, but it does not: > (multiply-by-seven '(4)). That's because multiply-by-seven uses (interactive "p") -- lowercase `p' -- which assigns to NUMBER the numerical value of the prefix arg. The meaning of the interactive codes, such as "P" and "p", is explained in the node "Interactive Codes" in the ELisp manual.