🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.emacs
Article #8198

Re: GNU Emacs special form "interactive"

#8198
From: Ashwin Ram
Date: Fri, 30 Dec 1988 19:27
46 lines
2775 bytes
In article <8812301512.AA10827@decwrl.dec.com>, ellis@ultra.dec.com (David Ellis) writes:
> To have a GNU Emacs command prompt for string argument input using a fixed 
> prompt string, the command should include in its body the form
> 	(interactive "s(This is a prompt string) : ")
> 
> What I'd like to do is have a function taking an argument that gets
> inserted into a prompt string. [...]
> I can do this if I can get the special form "interactive" to take as its
> argument a string-valued expression in place of a specific string [...]
> 	(interactive (format "s(This is a %s prompt string) : " foo-arg))
> 
> Unfortunately, GNU Emacs rewards this effort with the error message
> 	Wrong type argument: listp, "s(This is a Type A prompt string) : "
> saying that "interactive" expects a list (huh?) but has been given a string.

The "interactive" function expects either a string or an s-exp to evaluate to
get a list of arguments to pass to the function.  From the documentation for
"interactive":

    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.
    If the argument is not a string, it is evaluated to get a list of
     arguments to pass to the function.

For your example, you should use:

    (interactive (list (read-string (format "s(This is a %s prompt string): " foo-arg))))

The argument to interactive is responsible for returning a list of arguments
for the function, NOT another interactive spec.  See docs for more info.

Note that foo-arg cannot be one of the arguments to the function since if
that function is called interactively, its arguments will not yet be defined.
In other words,

    (define foo (foo-arg)
       (interactive (list (read-string (format "s(This is a %s prompt string): " foo-arg))))      
       ...)

is meaningless and will give you a "Symbol's value as variable is void:
foo-arg" error (unless of course foo-arg is already defined in a larger
context outside foo).

-- Ashwin.
Technical Details
Message-ID: <46707@yale-celray.yale.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!cmcl2!yale!Ram-Ashwin
References: <8812301512.AA10827@decwrl.dec.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!cmcl2!yale!Ram-Ashwin
From: Ram-Ashwin@cs.yale.edu (Ashwin Ram)
Newsgroups: comp.emacs
Subject: Re: GNU Emacs special form "interactive"
Message-ID: <46707@yale-celray.yale.UUCP>
Date: 30 Dec 88 19:27:15 GMT
References: <8812301512.AA10827@decwrl.dec.com>
Sender: root@yale.UUCP
Reply-To: Ram-Ashwin@cs.yale.edu (Ashwin Ram)
Organization: Computer Science, Yale University, New Haven, CT 06520-2158
Lines: 46
In-reply-to: ellis@ultra.dec.com (David Ellis)