all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuri Khan <yuri.v.khan@gmail.com>
To: mflynn@scu.edu
Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: ELisp Interactive Calls
Date: Sat, 20 Dec 2014 03:38:21 +0700	[thread overview]
Message-ID: <CAP_d_8UXq7HOV+7DJu-BhkWiK9e1eHBzumHzwmFbFnRYbfsfdw@mail.gmail.com> (raw)
In-Reply-To: <f222a1d9-a29b-41f3-8d44-c0564e1bacb3@googlegroups.com>

On Sat, Dec 20, 2014 at 2:13 AM,  <mflynn@scu.edu> wrote:

> (defun my-test-function (arg1 arg2)
>   "DOC: Multiply two numbers."
>   (interactive "p p")
>   (message "The product of the args is: %d" (* arg1 arg2))
> )
>
> How do I call this?  If I type Ctrl-U 8 8 Esc-x my-test-function
>
> the call fails with a Wrong number of args message.   The second 8 I type just shows up in the scratch buffer.

Have you read the documentation on “interactive”? (C-h f interactive)

“To get several arguments, concatenate the individual strings,
separating them by newline characters.”

(defun my-test-function (arg1 arg2)
  "DOC: Multiply two numbers."
  (interactive "p\np")
  (message "The product of the args is: %d" (* arg1 arg2)))

C-u 8 M-x my-test-function
=> The product of the args is: 64

It kind of works, but is kind of useless, because the universal prefix
gets fed into *both* arguments.

“n -- Number read using minibuffer.
N -- Numeric prefix arg, or if none, do like code `n'.
p -- Prefix arg converted to number.  Does not do I/O.”

Now this looks useful.

(defun my-test-function (arg1 arg2)
  "DOC: Multiply two numbers."
  (interactive "N\nn")
  (message "The product of the args is: %d" (* arg1 arg2)))

C-u 8 M-x my-test-function
7
=> The product of the args is: 56

M-x my-test-function
8
7
=> The product of the args is: 56

“Usually the argument of `interactive' is a string containing a code
letter followed optionally by a prompt.”

Let’s use that to give useful prompts.

(defun my-test-function (arg1 arg2)
  "DOC: Multiply two numbers."
  (interactive "NMultiply what: \nnMultiply by: ")
  (message "The product of the args is: %d" (* arg1 arg2)))

C-u 8 M-x my-test-function
Multiply by: 7
=> The product of the args is: 56

M-x my-test-function
Multiply what: 8
Multiply by: 7
=> The product of the args is: 56



  reply	other threads:[~2014-12-19 20:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-19 20:13 ELisp Interactive Calls mflynn
2014-12-19 20:38 ` Yuri Khan [this message]
2014-12-19 21:22 ` mflynn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAP_d_8UXq7HOV+7DJu-BhkWiK9e1eHBzumHzwmFbFnRYbfsfdw@mail.gmail.com \
    --to=yuri.v.khan@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=mflynn@scu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.