GNU bug report logs - #2723
Emacs 23: `interactive': prefix argument "P" and region "r" are mutually exclusive.

Previous Next

Package: emacs;

Reported by: Alan Mackenzie <acm <at> muc.de>

Date: Thu, 19 Mar 2009 19:25:03 UTC

Severity: normal

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 2723 in the body.
You can then email your comments to 2723 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2723; Package emacs. (Thu, 19 Mar 2009 19:25:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alan Mackenzie <acm <at> muc.de>:
New bug report received and forwarded. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Thu, 19 Mar 2009 19:25:04 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: bug-gnu-emacs <at> gnu.org
Subject: Emacs 23: `interactive': prefix argument "P" and region "r" are
	mutually exclusive.
Date: Thu, 19 Mar 2009 19:15:24 +0000
Hi, Emacs!

In the following:

#########################################################################
(defun echo-prefix (arg)
  "Echo the command prefix"
  (interactive "P")
  (message "Command prefix: %s" arg))

(defun echo-region (beg end)
  "Echo the region boundaries"
  (interactive "r")
  (message "Region: (%s %s)" beg end))

(defun echo-region-prefix (beg end arg)
  "Echo the region and prefix parameters."
  (interactive "rP")
  (message "region: (%s %s); prefix: %s" beg end arg))
#########################################################################

, echo-prefix and echo-region work as expected.  echo-region-prefix
throws this error:

    Wrong number of arguments: (lambda (beg end arg) "Echo the region and
    prefix parameters." (interactive "rP") (message "region: (%s %s);
    prefix: %s" beg end arg)), 2

It seems that `(interactive "rP")' is only supplying the defun with two
parameters.

-- 
Alan Mackenzie (Nuremberg, Germany).





Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2723; Package emacs. (Thu, 19 Mar 2009 20:25:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to Leo <sdl.web <at> gmail.com>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Thu, 19 Mar 2009 20:25:05 GMT) Full text and rfc822 format available.

Message #10 received at 2723 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Leo <sdl.web <at> gmail.com>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 2723 <at> debbugs.gnu.org
Subject: Re: bug#2723: Emacs 23: `interactive': prefix argument "P" and region "r" are mutually exclusive.
Date: Thu, 19 Mar 2009 20:16:12 +0000
On 2009-03-19 19:15 +0000, Alan Mackenzie wrote:
> (defun echo-region-prefix (beg end arg)
>   "Echo the region and prefix parameters."
>   (interactive "rP")
>   (message "region: (%s %s); prefix: %s" beg end arg))

They have to be separated by "\n" as follows.

(defun echo-region-prefix (beg end arg)
  "Echo the region and prefix parameters."
  (interactive "r\nP")
  (message "region: (%s %s); prefix: %s" beg end arg))

I tested it in GNU Emacs 23.0.60.1 (i686-pc-linux-gnu, GTK+ Version
2.12.0) of 2008-12-15.

-- 
.:  Leo  :.  [ sdl.web AT gmail.com ]  .: I use Emacs :.

               www.git-scm.com
    git - the one true version control system




Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Thu, 19 Mar 2009 20:45:04 GMT) Full text and rfc822 format available.

Notification sent to Alan Mackenzie <acm <at> muc.de>:
bug acknowledged by developer. (Thu, 19 Mar 2009 20:45:04 GMT) Full text and rfc822 format available.

Message #15 received at 2723-done <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 2723-done <at> debbugs.gnu.org
Subject: Re: bug#2723: Emacs 23: `interactive': prefix argument "P" and region "r" are mutually exclusive.
Date: Thu, 19 Mar 2009 16:40:11 -0400
> It seems that `(interactive "rP")' is only supplying the defun with two
> parameters.

Read C-h f interactive RET, and if you read carefully enough you'll see
you need (interactive "r\nP")


        Stefan





Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2723; Package emacs. (Thu, 19 Mar 2009 21:55:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alan Mackenzie <acm <at> muc.de>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Thu, 19 Mar 2009 21:55:05 GMT) Full text and rfc822 format available.

Message #20 received at 2723 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 2723 <at> debbugs.gnu.org
Subject: Re: bug#2723: Emacs 23: `interactive': prefix argument "P" and region
	"r" are mutually exclusive.
Date: Thu, 19 Mar 2009 21:49:04 +0000
Hi, Stefan!

On Thu, Mar 19, 2009 at 04:40:11PM -0400, Stefan Monnier wrote:
> > It seems that `(interactive "rP")' is only supplying the defun with two
> > parameters.

> Read C-h f interactive RET, and if you read carefully enough you'll see
> you need (interactive "r\nP")

No.  I've read closely and it doesn't say this, neither in the doc
string or the Elisp manual.  The pertinent bit of the Elisp manual reads
thusly:

   * It may be a string; then its contents should consist of a code
     character followed by a prompt (which some code characters use and
     some ignore).  The prompt ends either with the end of the string
     or with a newline.  Here is a simple example:

, i.e. the \n terminates the prompt rather than separating it from the
next thing.  This bit of the manual is oblivious to the existence of
descriptors lacking prompts ("p", "P", "r", "d", "i", "m"), and looks
like it could have been written early in Emacs's development, before "p"
and friends existed (if there was such a time).

The only bit of the doc string which is relevant is

    To prompt for multiple arguments, give a code letter, its prompt, a
    newline, and another code letter, etc.

, which implies that the \n is required only where there's prompting
going on, which clearly isn't the case for "P", "r", etc.

Is there any reason why there needs to be a \n separating "P" and "r"?
After all, in a shell, we can write

    tar -xf emacs.tar.gz

, rather than having to do

    tar -x -f emacs.tar.gz

, which is somewhat analagous.  Aternatively, why does the interactive
call function not give an error message?

OK, I'll write the patches for the Elisp manual and `interactive''s doc
string.  Just not tonight.  Should I reopen this bug, submit a new bug,
or just submit the patch?

>         Stefan
> 

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2723; Package emacs. (Fri, 20 Mar 2009 08:05:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to Miles Bader <miles <at> gnu.org>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Fri, 20 Mar 2009 08:05:06 GMT) Full text and rfc822 format available.

Message #25 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Miles Bader <miles <at> gnu.org>
To: gnu-emacs-bug <at> moderators.individual.net
Subject: Re: bug#2723: Emacs 23: `interactive': prefix argument "P" and region "r" are mutually exclusive.
Date: Fri, 20 Mar 2009 16:59:17 +0900
Alan Mackenzie <acm <at> muc.de> writes:
> Is there any reason why there needs to be a \n separating "P" and "r"?
> After all, in a shell, we can write

An interesting question, but it does keep open the possibility of adding
optional sub-parameters after the operation letter...

-Miles

-- 
Patience, n. A minor form of despair, disguised as a virtue.





Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2723; Package emacs. (Fri, 20 Mar 2009 13:25:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Fri, 20 Mar 2009 13:25:05 GMT) Full text and rfc822 format available.

Message #30 received at 2723 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 2723 <at> debbugs.gnu.org
Subject: Re: bug#2723: Emacs 23: `interactive': prefix argument "P" and region "r" are mutually exclusive.
Date: Fri, 20 Mar 2009 09:19:51 -0400
>> > It seems that `(interactive "rP")' is only supplying the defun with two
>> > parameters.
>> Read C-h f interactive RET, and if you read carefully enough you'll see
>> you need (interactive "r\nP")
> No.

I see two bugs:
1 - the doc is unclear about the need for a newline.
2 - arguments without prompts should signal a warning when provided with
    a prompt (this would have helped you find your problem).


        Stefan




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2723; Package emacs. (Fri, 20 Mar 2009 14:45:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juanma Barranquero <lekktu <at> gmail.com>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Fri, 20 Mar 2009 14:45:05 GMT) Full text and rfc822 format available.

Message #35 received at 2723 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Juanma Barranquero <lekktu <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Alan Mackenzie <acm <at> muc.de>, 2723 <at> debbugs.gnu.org
Subject: Re: bug#2723: Emacs 23: `interactive': prefix argument "P" and region 
	"r" are mutually exclusive.
Date: Fri, 20 Mar 2009 15:39:29 +0100
On Fri, Mar 20, 2009 at 14:19, Stefan Monnier <monnier <at> iro.umontreal.ca> wrote:

> 1 - the doc is unclear about the need for a newline.

As witnessed by

 - org/org-table.el (uses "rP")
 - progmodes/idlwave.el (uses "eP")
 - emulation/viper-util.el (uses "s x")

    Juanma




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2723; Package emacs. (Sat, 21 Mar 2009 15:35:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alan Mackenzie <acm <at> muc.de>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sat, 21 Mar 2009 15:35:02 GMT) Full text and rfc822 format available.

Message #40 received at 2723 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 2723 <at> debbugs.gnu.org, Juanma Barranquero <lekktu <at> gmail.com>,
        Leo <sdl.web <at> gmail.com>, Miles Bader <miles <at> gnu.org>
Subject: Re: bug#2723: Emacs 23: `interactive': prefix argument "P" and region
	"r" are mutually exclusive.
Date: Sat, 21 Mar 2009 15:25:12 +0000
Hi, Stefan et al.,

On Fri, Mar 20, 2009 at 09:19:51AM -0400, Stefan Monnier wrote:
> >> > It seems that `(interactive "rP")' is only supplying the defun with two
> >> > parameters.
> >> Read C-h f interactive RET, and if you read carefully enough you'll see
> >> you need (interactive "r\nP")
> > No.

> I see two bugs:
> 1 - the doc is unclear about the need for a newline.
> 2 - arguments without prompts should signal a warning when provided with
>     a prompt (this would have helped you find your problem).

OK, here's a pair of patches for bug 1.  Any comments before I commit
them?


2009-03-21  Alan Mackenzie  <acm <at> muc.de>

        * callint.c (Finteractive): Clarify the doc string - even
        promptless elements need \n separators.


*** callint.c.orig	2009-03-08 14:56:05.000000000 +0000
--- callint.c	2009-03-21 14:49:33.360805672 +0000
***************
*** 68,85 ****
  DEFUN ("interactive", Finteractive, Sinteractive, 0, UNEVALLED, 0,
         doc: /* Specify a way of parsing arguments for interactive use of a function.
  For example, write
!   (defun foo (arg) "Doc string" (interactive "p") ...use arg...)
! to make ARG be the prefix argument when `foo' is called as a command.
  The "call" to `interactive' is actually a declaration rather than a function;
   it tells `call-interactively' how to read arguments
   to pass to the function.
  When actually called, `interactive' just returns nil.
  
! The argument of `interactive' is usually a string containing a code letter
!  followed by a prompt.  (Some code letters do not use I/O to get
!  the argument and do not need prompts.)  To prompt for multiple arguments,
!  give a code letter, its prompt, a newline, and another code letter, etc.
!  Prompts are passed to format, and may use % escapes to print the
   arguments that have already been read.
  If the argument is not a string, it is evaluated to get a list of
   arguments to pass to the function.
--- 68,86 ----
  DEFUN ("interactive", Finteractive, Sinteractive, 0, UNEVALLED, 0,
         doc: /* Specify a way of parsing arguments for interactive use of a function.
  For example, write
!  (defun foo (arg buf) "Doc string" (interactive "P\\nbbuffer: ") .... )
!  to make ARG be the raw prefix argument, and set BUF to an existing buffer,
!  when `foo' is called as a command.
  The "call" to `interactive' is actually a declaration rather than a function;
   it tells `call-interactively' how to read arguments
   to pass to the function.
  When actually called, `interactive' just returns nil.
  
! Usually the argument of `interactive' is a string containing a code letter
!  followed optionally by a prompt.  (Some code letters do not use I/O to get
!  the argument and do not use prompts.)  To get several arguments, concatenate
!  the individual strings, separating them by newline characters.
! Prompts are passed to format, and may use % escapes to print the
   arguments that have already been read.
  If the argument is not a string, it is evaluated to get a list of
   arguments to pass to the function.



2009-03-21  Alan Mackenzie  <acm <at> muc.de>

        * commands.texi (Using Interactive): Clarify string argument to
        `interactive' - even promptless elements need \n separators.


*** commands.texi.orig	2009-02-12 12:10:45.000000000 +0000
--- commands.texi	2009-03-21 14:55:01.964850264 +0000
***************
*** 158,181 ****
  or more arguments.
  
  @item
! It may be a string; then its contents should consist of a code character
! followed by a prompt (which some code characters use and some ignore).
! The prompt ends either with the end of the string or with a newline.
! Here is a simple example:
  
  @smallexample
! (interactive "bFrobnicate buffer: ")
  @end smallexample
  
  @noindent
! The code letter @samp{b} says to read the name of an existing buffer,
! with completion.  The buffer name is the sole argument passed to the
! command.  The rest of the string is a prompt.
! 
! If there is a newline character in the string, it terminates the prompt.
! If the string does not end there, then the rest of the string should
! contain another code character and prompt, specifying another argument.
! You can specify any number of arguments in this way.
  
  @c Emacs 19 feature
  The prompt string can use @samp{%} to include previous argument values
--- 158,179 ----
  or more arguments.
  
  @item
! It may be a string; its contents are a sequence of elements separated
! by newlines, one for each parameter <at> footnote{Some elements actually
! supply two parameters.}.  Each element consists of a code character
! (@pxref{ Interactive Codes}) optionally followed by a prompt (which
! some code characters use and some ignore).  Here is an example:
  
  @smallexample
! (interactive "P\nbFrobnicate buffer: ")
  @end smallexample
  
  @noindent
! The code letter @samp{P} sets the command's first argument to the raw
! command prefix (@pxref{Prefix Command Arguments}).  @samp{bFrobnicate
! buffer: } prompts the user with @samp{Frobnicate buffer: } to enter
! the name of an existing buffer, which becomes the second and final
! argument.
  
  @c Emacs 19 feature
  The prompt string can use @samp{%} to include previous argument values

> 
>         Stefan

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2723; Package emacs. (Sat, 21 Mar 2009 19:15:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sat, 21 Mar 2009 19:15:03 GMT) Full text and rfc822 format available.

Message #45 received at 2723 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 2723 <at> debbugs.gnu.org, Juanma Barranquero <lekktu <at> gmail.com>,
        Leo <sdl.web <at> gmail.com>, Miles Bader <miles <at> gnu.org>
Subject: Re: bug#2723: Emacs 23: `interactive': prefix argument "P" and region "r" are mutually exclusive.
Date: Sat, 21 Mar 2009 15:07:14 -0400
> OK, here's a pair of patches for bug 1.  Any comments before I commit them?

Only one comment from me: thank you,


        Stefan




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> emacsbugs.donarmstrong.com. (Sun, 19 Apr 2009 14:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 16 years and 66 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.