From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: goncholden Newsgroups: gmane.emacs.help Subject: Re: Function passing flag Date: Tue, 08 Mar 2022 20:55:26 +0000 Message-ID: References: <87pmmwpbni.fsf@zoho.eu> <877d94p87y.fsf@zoho.eu> Reply-To: goncholden Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40499"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Help Gnu Emacs mailing list , Emanuel Berg To: Corwin Brust Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Mar 08 21:56:14 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nRgsP-000AKn-PO for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 08 Mar 2022 21:56:13 +0100 Original-Received: from localhost ([::1]:51450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRgsO-0008UQ-Jb for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 08 Mar 2022 15:56:12 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:43074) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRgrl-0008UF-Ni for help-gnu-emacs@gnu.org; Tue, 08 Mar 2022 15:55:34 -0500 Original-Received: from mail-40137.protonmail.ch ([185.70.40.137]:45402) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRgrj-0002en-J5 for help-gnu-emacs@gnu.org; Tue, 08 Mar 2022 15:55:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1646772929; bh=JF7qbwk2wVZvMzd4ofJFDNbeNqo/38X6qMvD7hgYulE=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=lsZLvYXLdv1sjRk/nPJi6p0HJv+G4kYR3YC0f0y5ZVXvjbdDT3eRZi+fu5bruSe9Z plppme7sGVqx6kHCx3cS1IE001CmeDipm/LNcXhoONY3Jn48/p3KEQwyIGeqlQK470 2km9Dr/X9QJdGjYmSI3DU7yHIEZanHTDLQt7fHflcOyCwTvmKxT/0H1FdwvUIHS0k6 9SOuEjvYQgaXKBiiu7cF0g40hNYqCUbqA7NVylk/cEBRKdudkp3rsh1ZFjsdVTRqCz 6abANcSOglAwbht9VLAk12a5rz/DuAMv5vn1J/vJnknh2y7Gguzfy5XqRfvYVUdn/K 1vTejEdDdicRQ== In-Reply-To: Received-SPF: pass client-ip=185.70.40.137; envelope-from=goncholden@protonmail.com; helo=mail-40137.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:136409 Archived-At: ------- Original Message ------- On Tuesday, March 8th, 2022 at 8:42 PM, Corwin Brust wrote: > 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 woul= d 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.