From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: Rationale behind conversion of a nil prefix arg to numeric 1 Date: Mon, 5 Sep 2016 09:32:17 -0700 (PDT) Message-ID: <6012db9f-079c-48bd-b51d-64f162e869f9@default> References: <87y437c0qg.fsf@bertrandrussell.Speedport_W_723V_1_40_000> <83oa43d9r8.fsf@gnu.org> <06d4a7f1-f116-fb5c-9bd2-c4d1f98934c9@easy-emacs.de> <83k2ercy5u.fsf@gnu.org> <83bn02cs54.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1473093206 6592 195.159.176.226 (5 Sep 2016 16:33:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 5 Sep 2016 16:33:26 +0000 (UTC) To: Kaushal Modi , Help Gnu Emacs mailing list , =?utf-8?B?QW5kcmVhcyBSw7ZobGVy?= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Sep 05 18:33:23 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bgwpk-0001AW-5Y for geh-help-gnu-emacs@m.gmane.org; Mon, 05 Sep 2016 18:33:20 +0200 Original-Received: from localhost ([::1]:55792 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgwph-0000PO-1K for geh-help-gnu-emacs@m.gmane.org; Mon, 05 Sep 2016 12:33:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40516) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgwou-0000Nd-TL for help-gnu-emacs@gnu.org; Mon, 05 Sep 2016 12:32:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bgwoo-0003Sj-U9 for help-gnu-emacs@gnu.org; Mon, 05 Sep 2016 12:32:27 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:42732) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgwoo-0003SR-KY for help-gnu-emacs@gnu.org; Mon, 05 Sep 2016 12:32:22 -0400 Original-Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u85GWJb0001726 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 5 Sep 2016 16:32:19 GMT Original-Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u85GWJ2t011895 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 5 Sep 2016 16:32:19 GMT Original-Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u85GWHZ3007231; Mon, 5 Sep 2016 16:32:17 GMT In-Reply-To: X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9 (901082) [OL 12.0.6753.5000 (x86)] X-Source-IP: userv0021.oracle.com [156.151.31.71] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 156.151.31.81 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:111269 Archived-At: > > Commands that need to distinguish between those should not use "p". > > Exactly. > Just treat the "p" (lowercase p) interactive form as the special case > where you only need to deal with numeric arguments and the default numeri= c > argument is 1. >=20 > If you need to deal with numeric, nil and other non-numeric arguments lik= e > (4), (16), etc, use the "P" (uppercase p) interactive form. The "P" > interactive form passes the args to the function in their raw, untouched > form. What Eli and Kaushal said. Again, this is a _feature_. You just need to learn what it is about (and what it is not about). The doc is quite clear - give it a try. In particular, if your code wants to know WHETHER a prefix argument was EXPLICITLY provided by the USER, then you need to test the RAW prefix argument. If you then want to know what the NUMERIC value is, use `prefix-numeric-value': (defun foo (arg) (interactive "P") ; <=3D=3D=3D uppercase P: RAW prefix arg (if (not arg) (no-prefix-arg-provided---usual/default-case) (let ((nval (prefix-numeric-value arg))) (cond ((=3D 42 nval) (answer-to-everything-it-seems)) ((> nval 0) (at-least-its-positive)) ((< nval 0) (so-negative!)) (t (nothing-at-all)))))) If you want to check for PARTICULAR non-nil raw prefix values: (if (not arg) (no-prefix-arg-provided---usual/default-case) (cond ((=3D arg '-) (handle-M--)) ((=3D arg '-42) (handle-M---4-2-or-C-u---4-2)) ; etc. ((=3D arg '4) (handle-M-4--or-C-u-4)) ((and (consp arg) (=3D 4 (car arg))) (handle-plain-C-u)) ((and (consp arg) (=3D 16 (car arg))) (handle-plain-C-u-C-u)) ...)) Note that `C-u' gives `(4)' as the raw prefix arg, and `C-u 4' gives `4' as the raw prefix arg. And `prefix-numeric-value' gives `4' in both cases. Experiment: (defun foo (arg) "Show the raw prefix arg and its numeric value." (interactive "P") (message "ARG: %S, Numeric value: %S" arg (prefix-numeric-value arg))) The case that this thread is about is just this one: `M-x foo'. (Much ado about nothing.)