[Top][All Lists]

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

Re: Function passing flag

From: goncholden
Subject: Re: Function passing flag
Date: Tue, 08 Mar 2022 20:55:26 +0000

------- Original Message -------
On Tuesday, March 8th, 2022 at 8:42 PM, Corwin Brust <> wrote:
> On Tue, Mar 8, 2022 at 2:28 PM goncholden 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

Have done like this

(defun romona (&optional action)
  "Enables or disables Emacs Bars"

  ;; If action in nil, set action to enable the bar modes
  (unless action (setq action 1))
  (if action
      (progn  (tool-bar-mode 1)
        (scroll-bar-mode 1))
    (progn  (tool-bar-mode -1)
      (scroll-bar-mode -1)) ))

Could just need a defvar.

reply via email to

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