From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Heime Newsgroups: gmane.emacs.help Subject: Re: Functions which are mode dependent Date: Sat, 24 Aug 2024 11:33:24 +0000 Message-ID: References: <3RfPnnmfz0Qgr0JGJbNKnydaMu1QfnGGBk7xX7qxkXSkzXBNt8snc9Ye1n6AvZtOln0VoPDXmjnYc_X5lGkPVxnvPPlBbjvnuKMQs4cki18=@protonmail.com> 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="33622"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Heime via Users list for the GNU Emacs text editor To: Yuri Khan Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 24 13:34:14 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 1shp26-0008dv-Ib for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 24 Aug 2024 13:34:14 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1shp1R-0005Iw-Jc; Sat, 24 Aug 2024 07:33:33 -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 1shp1Q-0005Il-BD for help-gnu-emacs@gnu.org; Sat, 24 Aug 2024 07:33:32 -0400 Original-Received: from mail-40141.protonmail.ch ([185.70.40.141]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1shp1N-0000EM-OJ for help-gnu-emacs@gnu.org; Sat, 24 Aug 2024 07:33:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1724499207; x=1724758407; bh=Ozisfb3sOJCMiL+jqbi8L44/XMV9+dZR8Q4TLoUyBCA=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=kDwX2wI4ekLUXBNhyCd3KkVReg/NQ5NX1mjWfJOAqp6HO0XQUP3OURuihS3Jnb66Q yszk2rwN9TNZ1mUlGOZgamyqS2gnpLUcFLcZZ25ik2UfsC4YZwvRJE/9x8jBu9yJ4G MxxzGqv8827ooU0mEBDj90hSZuAAtwGoNbczLVrXN6nRZ84UnuGUNmrIt6zQ0anOCB bM/0Zn8kpXuYsD1h/fZ2F2uS99Rw7ozcwFvZd/kj0Gkvd2KWbi8QEq/M43Y9U9CNA/ GjnpvZp6UFOMM2KUKvsqeF3X8+kd6Vx2DMkiEFOPedILepiWpf55N+sidN0uTb6XZZ tph2Qyf6MDRWQ== In-Reply-To: Feedback-ID: 57735886:user:proton X-Pm-Message-ID: f68744443f2dbe138c31a962361baeaa18481272 Received-SPF: pass client-ip=185.70.40.141; envelope-from=heimeborgia@protonmail.com; helo=mail-40141.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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:147797 Archived-At: On Saturday, August 24th, 2024 at 10:20 PM, Yuri Khan wrote: > On Sat, 24 Aug 2024 at 16:46, Heime heimeborgia@protonmail.com wrote: >=20 > > Is this be the correct way for a minor mode to use the variable > > tema-expr-elisp for imenu-generic-expression that will be applied > > when enabling tema-minor-mode on a buffer in emacs-lisp-mode ? >=20 >=20 > No. Consider: >=20 > 1. You open an Elisp file (C-x C-f /home/me/some.el RET). > 2. A buffer is created. > 3. The file=E2=80=99s contents are loaded into the buffer. > 4. The buffer switches to emacs-lisp-mode. > 5. emacs-lisp-mode runs emacs-lisp-mode-hook. At this point, the hook > is empty so nothing special happens. > 6. You enable your minor mode (M-x tema-minor-mode RET). > 7. It adds tema-imenu-expr-elisp to emacs-lisp-mode-hook, but at this > point it is too late for your current buffer. >=20 > Observed result: your minor mode is enabled in the buffer of some.el, > but its configuration is not applied. >=20 > Further: >=20 > 8. You open another Elisp file (C-x C-f /home/me/other.el RET). > 9. A buffer is created. > 10. The file=E2=80=99s contents are loaded into the buffer. > 11. The buffer switches to emacs-lisp-mode. > 12. emacs-lisp-mode runs emacs-lisp-mode-hook. The hook contains the > function added by enabling the minor mode in another buffer, so that > function runs and modifies imenu-generic-expression. >=20 > Observed result: In the buffer of other.el, tema-minor-mode is not > enabled, yet its configuration has been applied. >=20 >=20 > Now drop your focus on the solution. What problem are you solving? Why > do you want to modify imenu-generic-expression for emacs-lisp-mode > buffers but only sometimes? Correct, to modify imenu-generic-expression only sometimes. I want to have a minor mode. When I enable the tema-minor-mode in an emacs-lisp buffer, imenu-generic-expression is set properly and the imenu menubar is added to the emacs menubar. =20 When I disable tema-minor-mode, imenu is also disabled, meaning that imenu menubar is removed, possibly resetting imenu-generic-expression to the emacs default for that major-mode. Thus not keeping the regexp set by tema-minor-mode.=20 =20 > > (defvar tema-expr-elisp > > '(("Functions" "^\\s-(defun\\s-+\\(\\<.?\\>\\)" 1))) > >=20 > > (defun tema-imenu-expr-elisp () > > "Set up a custom imenu expression for the current buffer." > > (setq-local imenu-generic-expression tema-expr-elisp)) > >=20 > > ;;;###autoload > > (define-minor-mode tema-minor-mode > > "DESC." > > :init-value nil > > :lighter " Tema" > >=20 > > (if tema-minor-mode > > (progn > > (add-hook 'sh-mode-hook #'tema-imenu-expr-sh) > > (add-hook 'emacs-lisp-mode-hook #'tema-imenu-expr-elisp)) > > (remove-hook 'sh-mode-hook #'tema-imenu-expr-sh) > > (remove-hook 'emacs-lisp-mode-hook #'tema-imenu-expr-elisp)))