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

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

Re: Function passing flag


From: Corwin Brust
Subject: Re: Function passing flag
Date: Tue, 8 Mar 2022 14:15:16 -0600

Apologies, I answered only half of your question, I think.  As to
where you can read about this:

I recommend reading the entire Functions section of the elisp manual
however you can get to the specific section that introduces optional
arguments via:

  M-: (info "(elisp)Defining Functions")  RET

On Tue, Mar 8, 2022 at 2:09 PM Corwin Brust <corwin@bru.st> wrote:
>
> On Tue, Mar 8, 2022 at 1:36 PM goncholden <goncholden@protonmail.com> wrote:
> >
> > How does one do it with an optional argument?  Where can I read about this?
> >
>
> A function with an optional argument ARG might look like this:
>
> (defun my:own-fun (&optional arg)
>   "Do something. When ARG is non-nil do it a lot."
>   (if arg
>       ;; when ARG is true we run this
>       (do-stuff)
>     ;; else we run this
>     (do-more-or-different-stuff)))
>
> Note, if you are defining a command (a function you will bind to a key
> or otherwise use interactively), you will want to to use
> (interactive), usually placed at the start of the function definition,
> so just after the docstring.



reply via email to

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