help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [External] : Re: Making a function than can only be used interactive


From: Drew Adams
Subject: RE: [External] : Re: Making a function than can only be used interactively
Date: Fri, 8 Jul 2022 20:29:35 +0000

> It looks as if the easiest understanding of mandatory versus optional
> function arguments occurs when using a function interactively.
> 
> For the interactive case, it is quite complicated, depending on whether
> the function uses code characters or a list.
> 
> My proposition would be to include the corresponding explanation on
> using in either the "Emacs Lisp Reference Manual" or the "Introduction to
> Programming in Emacs Lisp".

Dunno whether it's a coincidence (I'm guessing no),
but in the past couple of weeks there've been a
boatload of similar questions on emacs.SE.  Here
are some of them:

What is a raw prefix argument?

https://emacs.stackexchange.com/q/13886

Numeric prefix argument for use with interactive command

https://emacs.stackexchange.com/q/72365

Changing of function arguments

https://emacs.stackexchange.com/q/72393

Using current prefix argument value

https://emacs.stackexchange.com/q/72425

Function arguments and interactive

https://emacs.stackexchange.com/q/72428

Getting prefix as argument

https://emacs.stackexchange.com/q/72454
_____

(I voted to close some of them as duplicates.)

Anyway, (I think) I see confusion there similar to
what (I think) I'm seeing here now.

FWIW, here are some comments I wrote to the last of
those questions.  That doesn't seem to have done
much good.  But maybe they'll help here.
____

1. There's no connection between an argument being
   optional and it being provided as a prefix
   argument - none.

2. The only implication of an arg being mandatory or
   optional is for calling the function.  If it's
   mandatory then omitting it raises an error;
   otherwise, no error. That's all.

3. Using a prefix arg does not necessarily pass an
   argument to the function.

   A prefix arg is not necessarily an arg to the
   function, and vice versa.

   A prefix arg need not be optional.

   And you can use C-u with M-x.

   I suggest you read the Emacs manual about prefix
   args:

   
https://www.gnu.org/software/emacs/manual/html_node/elisp/Prefix-Command-Arguments.html
 

   Start by `C-h k C-u'.

   A prefix arg is used (can be used) by the
   following command.  It is not necessarily
   associated with any argument to that function.
   You can think of it as a global variable, if you
   like - the function has access to it, but it
   need not be one of the function's arguments.
____

Back to this mail thread...

Instead of looking for some general guideline for
when to use a prefix arg, or when to make this or
that argument optional, my advice is to just learn
what each thingie is/_does_.

Learn how a prefix arg behaves (raw and numeric).
Learn how an optional arg behaves.  Learn some of
the predefined chars for a string arg to
`interactive'.  Learn how to give a list arg to
`interactive'.

Play with those things.  Once you know what each
does you'll know what you can do with them.  And
you'll know when you might want to use this or
that thingie.  Only you know what you want, but
you need to know what the tools in your toolbox
look like and do.

This whole discussion feels like a quest for
advice about when to use the number one or zero -
or a negative number or a positive number or ...
There is no single "when".  There's just knowing
the properties/behaviors of things.     
____

tl;dr (too late, I know):

Don't ask when to use X.  Just get to know X.
When and how and why to use it will come to you
when you know it.

(Just one opinion.)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]