[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Making a function than can only be used interactively
From: |
Yuri Khan |
Subject: |
Re: Making a function than can only be used interactively |
Date: |
Fri, 8 Jul 2022 13:08:43 +0700 |
On Fri, 8 Jul 2022 at 05:14, carlmarcos--- via Users list for the GNU
Emacs text editor <help-gnu-emacs@gnu.org> wrote:
> I want to know a few specific things. If I want to use the prefix argument,
> I should include
> a variable in the argument list, right? Let us call the variable "prefix".
> Now, should the prefix
> be mandatory or optional? Should it always be the first argument?
>
> (defun funname (prefix arg-a arg-b)
> "docstring"
> (interactive "P\ns Name:\n s City")
> (message "executed funname"))
It does not matter for interactive use. Your (interactive) spec, if it
were written correctly[see below], would describe three arguments, and
Emacs would therefore pass three arguments to your function.
‘&optional’ comes into play if you use this function
non-interactively, from Lisp:
(defun funname (prefix arg-a arg-b)
nil)
(funname 0 1 2)
⇒ nil
(funname)
⇒ (wrong-number-of-arguments (lambda (prefix arg-a arg-b) nil) 0)
(defun funname (&optional prefix arg-a arg-b)
nil)
(funname 0 1 2)
⇒ nil
(funname)
⇒ nil
Now about (interactive) spec syntax: you have three spaces there. The
one immediately after the ‘\n’ breaks things — the first character of
an argument specification specifies the way it is produced, and space
is not a valid code letter. The other two spaces (after ‘s’) become
part of the prompt so the prompt is displayed not at the window edge
but one character to the right. Your spec should be:
(interactive "P\nsName:\nsCity")
- Re: Making a function than can only be used interactively, (continued)
- Re: Making a function than can only be used interactively, carlmarcos, 2022/07/04
- Re: Making a function than can only be used interactively, Stefan Monnier, 2022/07/04
- Re: Making a function than can only be used interactively, Jean Louis, 2022/07/05
- Re: Making a function than can only be used interactively, Christopher Dimech, 2022/07/06
- Re: Making a function than can only be used interactively, Jean Louis, 2022/07/07
- Re: Making a function than can only be used interactively, Christopher Dimech, 2022/07/07
- Re: Making a function than can only be used interactively, carlmarcos, 2022/07/07
- Re: Making a function than can only be used interactively, Emanuel Berg, 2022/07/07
- Re: Making a function than can only be used interactively, carlmarcos, 2022/07/07
- Re: Making a function than can only be used interactively, Emanuel Berg, 2022/07/07
- Re: Making a function than can only be used interactively,
Yuri Khan <=
- Re: Making a function than can only be used interactively, Emanuel Berg, 2022/07/08
- Re: Making a function than can only be used interactively, Yuri Khan, 2022/07/08
- Re: Making a function than can only be used interactively, carlmarcos, 2022/07/08
- Re: Making a function than can only be used interactively, Emanuel Berg, 2022/07/08
- Re: Making a function than can only be used interactively, Emanuel Berg, 2022/07/10
- Re: Making a function than can only be used interactively, carlmarcos, 2022/07/08
- Re: Making a function than can only be used interactively, Christopher Dimech, 2022/07/08
- Message not available
- Re: Making a function than can only be used interactively, carlmarcos, 2022/07/08
- Re: Making a function than can only be used interactively, Christopher Dimech, 2022/07/08
- RE: [External] : Re: Making a function than can only be used interactively, Drew Adams, 2022/07/08