From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: Defining minor mode with minor-mode condition Date: Tue, 04 May 2021 09:01:20 +0200 Message-ID: <87lf8v560d.fsf@fastmail.fm> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16478"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.5.12; emacs 27.2 Cc: help-gnu-emacs@gnu.org To: Christopher Dimech Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 04 09:17:02 2021 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 1ldpIj-00048w-M1 for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 04 May 2021 09:17:01 +0200 Original-Received: from localhost ([::1]:54564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldpIi-0001mo-Pe for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 04 May 2021 03:17:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldpCI-0004L8-7r for help-gnu-emacs@gnu.org; Tue, 04 May 2021 03:10:22 -0400 Original-Received: from out3-smtp.messagingengine.com ([66.111.4.27]:41625) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldpC9-0004ix-Qq for help-gnu-emacs@gnu.org; Tue, 04 May 2021 03:10:22 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 2C4935C012B; Tue, 4 May 2021 03:10:13 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 04 May 2021 03:10:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= references:from:to:cc:subject:date:in-reply-to:message-id :mime-version:content-type; s=fm3; bh=c6PQVGh881MjCjAV+Cq90wx238 FXTmIrDAtF7lGdGUo=; b=vQ7wBuB70/02TXPwOzzVQa85AqJQff/IRhqjQs35nE fiT5HSjh1iiwaal0xcu6X6mfHKS37qVpTefCHpRMfSbZPsOSgVU2oCYou/AqQ04E R48uCo6VekzPYMgYaJawXcd6Jiikv1PJ32ATovCb3JXNi3p3B7YkTP5AVEcb1XkX iykDWx1e/eK50YGQFKGf+m+1DBCA8o4gEtv7AeQNKSgxzxYQzA1KlGXn/1z0BRjr IjSUM1re3oDj7YF6KB3F8uBDEm85LAOt7H61KIvySmYhWxBfoejPuBkawFyaArz7 UvXHsBIr0zUlferkAVC1BRzRelGIaZKmy5xqBXEaTSeg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=c6PQVG h881MjCjAV+Cq90wx238FXTmIrDAtF7lGdGUo=; b=KLdakPv8DdZpzhyQYgQCr2 FNnU1fST2crYePTuCR/hVwOETcuD/+Kn4nYyPJAb5LvN6/q/VWg9IcrNvntTQiIh MAx6OiT+v/reE+XAkJWvrEFRhs82NxV/hfpQBTmFZ0HXsRJFBWMGKTMtK4SI+h5q YdFC4h0JGEavjmEb7qmMPDMAP2HRWQopkyTNMW6c+L9XdLOwPD3d4bdOmmGTEQGy mRr0BQYUbjBinjwiv+lV2YZujCUpBDzb8Q6zPUFEdGTssmXL3VJ8lvEXa14E2bBq Zqk31MX4PSdJTdb88K/5hahB2y3fXWp48HxpyQmEHgFehStKar4uvNJyBBC5J6lA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdefhedguddujecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpehffgfhvffuffgjkfggtgesthdtredttdertdenucfhrhhomheplfhoohhs thcumfhrvghmvghrshcuoehjohhoshhtkhhrvghmvghrshesfhgrshhtmhgrihhlrdhfmh eqnecuggftrfgrthhtvghrnhepvdeihfetueevkeduteehudeihedvlefgieejhedvteef geelleehhfejudeijeevnecukfhppeefuddrudejrddvhedurdduleelnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepjhhoohhsthhkrhgvmhgv rhhssehfrghsthhmrghilhdrfhhm X-ME-Proxy: Original-Received: from Lenovo.fastmail.com (ip1f11fbc7.dynamic.kabel-deutschland.de [31.17.251.199]) by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 4 May 2021 03:10:12 -0400 (EDT) In-reply-to: Received-SPF: pass client-ip=66.111.4.27; envelope-from=joostkremers@fastmail.fm; helo=out3-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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:129406 Archived-At: On Tue, May 04 2021, Christopher Dimech wrote: > Is it valid to define a minor mode "crucibulum-minor-mode" and then > have a "when" condition using crucibulum-minor-mode inside of it? > > Regards > Christopher > > ;;;###autoload > (define-minor-mode crucibulum-minor-mode > "Minor mode for assisting with superior & inferior typeface." > :init-value nil > :global nil > :lighter " Crucibulum" > > (when crucibulum-minor-mode > (enable-texcom-typeface) > (enable-ricci-notation)) ) Yes, AFAIK it's the normal way of doing this. Note that what you're defining with `define-minor-mode` is a function with the name `crucibulum-minor-mode` *plus* a variable of the same name. When executed, the function `crucibulum-minor-mode` runs the code in the body of the `define-minor-mode`, but before that, it does some other stuff, among which is setting the variable `crucibulum-minor-mode`. So that's why this code works. Note that when `define-minor-mode` is executed, it does *not* run the code in its body. It just uses it to construct the function `crucibulum-minor-mode`. Note also that the normal form is not with a `when` but with an `if`, since normally you'll also want to add code to disable the minor mode. So it would look something like: ``` ;;;###autoload (define-minor-mode crucibulum-minor-mode "Minor mode for assisting with superior & inferior typeface." :init-value nil :global nil :lighter " Crucibulum" (if crucibulum-minor-mode (progn (enable-texcom-typeface) (enable-ricci-notation)) (disable-texcom-typeface) (disable-ricci-notation))) ``` -- Joost Kremers Life has its moments