[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:42:07 -0600 |
On Tue, Mar 8, 2022 at 2:28 PM goncholden <goncholden@protonmail.com> wrote:
>
> Would like to use arg as a switch so I can enable or disable some emacs modes
> (customarily using
> value of 1 to enable, and -1 to disable). If no arg is supplied, I would
> like to enable the modes.
>
> How would I define the parameter outside the function, and then pass it
> through. I might require
> a buffer local variable.
>
One typical way of doing this would be to use the "universal
argument", also known as a "prefix argument":
(info "(elisp)Prefix Command Arguments")
Here's an example that would create an interactive command that
enables tool-bars and scroll-bars or, with a prefix argument, disables
them.
(defun my:enable-bars (&optional arg)
"Enable `tool-bar-mode' and `scroll-bar-mode'.
When ARG is non-nill, disable them."
(interactive "P")
(if arg
(progn (tool-bar-mode -1)
(scroll-bar-mode -1))
(tool-bar-mode 1)
(scroll-bar-mode 1)))
Once you evaluate this you can ensure both tool-bar and scroll bar
modes are active with:
M-x my:enable-bar RET
Or, to ensure both tool-bar and scroll-bar modes are disabled:
C-u M-x my:enable-bar RET
- Function passing flag, goncholden, 2022/03/08
- Re: Function passing flag, Emanuel Berg, 2022/03/08
- Re: Function passing flag, goncholden, 2022/03/08
- Re: Function passing flag, Emanuel Berg, 2022/03/08
- Re: Function passing flag, goncholden, 2022/03/08
- Re: Function passing flag, Corwin Brust, 2022/03/08
- Re: Function passing flag, Corwin Brust, 2022/03/08
- Re: Function passing flag, goncholden, 2022/03/08
- Re: Function passing flag,
Corwin Brust <=
- Re: Function passing flag, goncholden, 2022/03/08