From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: tpeplt Newsgroups: gmane.emacs.help Subject: Re: Change of mode does not activate the associated hook Date: Thu, 04 Apr 2024 00:25:24 -0400 Message-ID: <87cyr592kr.fsf@gmail.com> References: 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="11916"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Heime via Users list for the GNU Emacs text editor To: Heime Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Apr 04 06:26:09 2024 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 1rsEfx-0002ov-4H for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 04 Apr 2024 06:26:09 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rsEfJ-0006R4-SO; Thu, 04 Apr 2024 00:25:29 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rsEfI-0006Qu-R1 for help-gnu-emacs@gnu.org; Thu, 04 Apr 2024 00:25:28 -0400 Original-Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rsEfH-0005Q2-2x for help-gnu-emacs@gnu.org; Thu, 04 Apr 2024 00:25:28 -0400 Original-Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-78be3087929so37745785a.1 for ; Wed, 03 Apr 2024 21:25:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712204725; x=1712809525; darn=gnu.org; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iKaI4QynTFxcHPRto5n8peW8SGfbitBIF/YYKlr3CDc=; b=Dg1hIpdhZwpRKVagwFLOcdmwcUI7gEqfG6aaQAlcYtBzSFjqWo+22KZWO8GE9fwH65 zurvSX23ERezIjVIvDJFRudhVpXYV6fTmIRC62MKf2xgYZYCm+9ls50jPtJdEHea/eQQ +9/1q1oTWL4U0uLSVZh0CT5bWl/iJ2MyhILGOVUOG+4ErYiyvq/qZIijlt4oykV+SVZp ElrDD8XBD4sB7YlMpPLkUYle+hpM9aAtGC/gPp8k2MLSyU/OZXCtAOj8dfDEucK60qu6 HKxnVpi7tqhIB2do5mCTJyxHSuhp62J/Eeh1zgqxxLBfEhPuljhJB2ZWUteNmMV449HS 1GJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712204725; x=1712809525; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=iKaI4QynTFxcHPRto5n8peW8SGfbitBIF/YYKlr3CDc=; b=xJ5BeLleXSzOa35qG3NQSQIduZAA+NjHsm3nmhK977mK/DAT1eTf52oFm1+UO03Fho 5zfVGpq59ZtAcRrUcv0901wkOL2QKTiiFV+wY5US/0pogh/b6X5Ra5ogMqa46WXkYIMx TVv+2Zzu+imAMXQNC4eKBMAjUqlUpzV0kRPzJw8MfWq+Cu1uY6ACBImUV+GqUbxHvbAG Mfhwc/5Rp7rrA6Il+3YL/36WQL1ZPUG0I9rmKwbPrzDyjWPS0v6E0PrpBOPuWfMu08/4 p68itp3iYq9/bMZNeINX76Vr7+EMskfaBgCFWXo5Ezo1ZYjhQsa4z2bERwjjNHFEff+9 BWQQ== X-Gm-Message-State: AOJu0Yx40z8lJ9j2bCRaIWSm54gwN6azyg4z5En7KLJHVgjayBXzZiQk BGj8vvkEbhZ9Awo+ZXTTdwCfQEaNLpEVxnxhUHjDYhuWyy/DJY9x X-Google-Smtp-Source: AGHT+IGenfNnLZkn5P0PBbcxAmZAet4JoDl43OGk4u4vYC3wGvZeLtEGV1rTFul7GYdOky6ucNSPCg== X-Received: by 2002:a05:620a:8529:b0:78b:e0fa:e347 with SMTP id pe41-20020a05620a852900b0078be0fae347mr1352623qkn.34.1712204725577; Wed, 03 Apr 2024 21:25:25 -0700 (PDT) Original-Received: from t530.local ([2600:8806:a821:2b00::bba2]) by smtp.gmail.com with ESMTPSA id g10-20020a05620a218a00b0078835bfddb8sm5565814qka.84.2024.04.03.21.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 21:25:25 -0700 (PDT) In-Reply-To: (Heime's message of "Thu, 04 Apr 2024 01:46:17 +0000") Received-SPF: pass client-ip=2607:f8b0:4864:20::731; envelope-from=tpeplt@gmail.com; helo=mail-qk1-x731.google.com 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_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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.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-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:146238 Archived-At: Heime writes: > Have made a minor mode named "ark" that uses mode hooks. > For a buffer with f90-mode enabled, the functionality in > the file avus-f90.el would be activated. This works well > when I open an file named "transform.f90". > > But if I am in a lisp-interaction buffer and change the > major mode to f90-mode followed by "M-x ark-minor-mode", > the associated mode hook for f90-mode is not activated. > > What is going on ? > > (defun ark-gali () > (interactive) > (cond > ((eq major-mode 'f90-mode) > (require 'avus-f90)) > > (defun ark-mode-hooks () > (add-hook 'f90-mode-hook #'ark-gali)) > > (define-minor-mode ark-minor-mode > (if ark-minor-mode > (ark-mode-hooks) > (message "%s" "TEST"))) 1. The code that you provided will not compile without errors. If you byte-compile your code, then you=E2=80=99ll be able to find and fix those errors, which will make it more likely that someone can help with the problem that you are having. 2. The first =E2=80=98defun=E2=80=99 is missing some trailing parentheses. 3. The expression for defining the minor mode is missing some arguments. a. Using C-h f define-minor-mode, the docstring says: (define-minor-mode MODE DOC [KEYWORD VAL ... &rest BODY]) so, unlike =E2=80=98defun=E2=80=99, the docstring (DOC) is required. b. Farther down in the docstring is the following requirement for BODY: "If you provide BODY, then you must provide at least one keyword argument (e.g. =E2=80=98:lighter nil=E2=80=98)." Your =E2=80=98define-minor-mode=E2=80=99 did not provide at least one= keyword argument. These two could be fixed as follows, for example: (define-minor-mode ark-minor-mode "a docstring for =E2=80=98ark-minor-mode=E2=80=99" :lighter " Ark" (if ark-minor-mode (ark-mode-hooks) (message "%s" "TEST"))) Once these changes have been made, the code should compile without errors. Once that has been done, if the expressions are evaluated, you should be able to type M-x ark-minor-mode and "Ark" will appear in your mode line. You should also see the message "Ark minor mode enabled in current buffer." If you type M-x ark-minor-mode a second time, then the "Ark" will disappear from the mode line and you should see the message TEST. --