From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.help Subject: Re: Functions which are mode dependent Date: Sat, 24 Aug 2024 17:20:38 +0700 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="13498"; mail-complaints-to="usenet@ciao.gmane.io" 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 Sat Aug 24 12:21:11 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 1shntO-0003Ka-G0 for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 24 Aug 2024 12:21:10 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1shnt9-000540-H0; Sat, 24 Aug 2024 06:20:55 -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 1shnt8-00053c-2I for help-gnu-emacs@gnu.org; Sat, 24 Aug 2024 06:20:54 -0400 Original-Received: from mail-ua1-x936.google.com ([2607:f8b0:4864:20::936]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1shnt6-0005aE-FB for help-gnu-emacs@gnu.org; Sat, 24 Aug 2024 06:20:53 -0400 Original-Received: by mail-ua1-x936.google.com with SMTP id a1e0cc1a2514c-842efa905a5so778363241.0 for ; Sat, 24 Aug 2024 03:20:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724494850; x=1725099650; darn=gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=cBLrbMRsbsHajT3oX3PMhvqdiArVV7Tfn5MyKLpjiNE=; b=Oug4Z8eIZlIwpOIdP5Ag/cS3QgEcqfLMPNtO6dUoIkY0FzDRI5X4fpHNnE9Cy/AsFg jnurShEfJYHSPcK83PpyqJR6eO/Bq05XKwoBehcIKn5JkMsu0NjahQE/xmj5zCabf+J2 hXaOVAYFydplGZWgoTJrjL/fgaPcX7tMstfbEOYkOiQsmKXaMWfu4AVYoqtVoiXhw3kO oa7Er+AmqFcF5Lbrcpgpq2HsaxmGP5yN7kQMzIoRYjYmf86qrPM1Um8qNS6LByjTpIHO Py23kHrhYcGHSJXiKheuWxkRl7entmPtmz3i4aQForPYkbEEgLDTw/G2g/TJ1PsdnR/d tMmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724494850; x=1725099650; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cBLrbMRsbsHajT3oX3PMhvqdiArVV7Tfn5MyKLpjiNE=; b=pCk1kgcamX025VZzi+jRPWoMuaGuBfyqpo0966rH/vIeur3+a+8WZnGvMGbCk5O2iw gB/4QGYtdjic02+hf2/HICtUac60yagABzywTV+z3olhq6v0PYgPuKoWJ5qw/5vqmrez p3UW87bj/7S/HgGi0kqFRwGWKghV+Kn5GbaR+Er8lfVOUAi2G1h10b00cgJoEM3on9uQ clIQQ2LtpiAKUWvjFXNYSNu3Nw2NqBFMPOsOFhdr0+pwGzr4LRPOWkLMwYcGD8EfR6PQ r9Xa2oBV0vexdciap86feeD1ttoC3t8kViY36TRVWSXWk061GgKBmf/EQjlZo6gDoFBJ IziA== X-Gm-Message-State: AOJu0YzAO8g5l7SI0QP6An3KgNqpfYyiXiNcTyWiyzJZh1KpNXHp5KbA 2ULVxBo+jOdNUOo/jm2oqfIDg9nEIf885F03QbtUMlTPwMDkuEYwxyLr+7CElP+DkpXe0ZclJFM Q5Fuue/vHkpSFFgiHs2A30ogFp6A= X-Google-Smtp-Source: AGHT+IFEkLI8WS+KP/gSiyAb/G6XoLOWEXAwAF3crQtbckjkbGAFkhA38lLoO2pnTt75kM6nnjVFMQT9gsuuqMRIXt4= X-Received: by 2002:a05:6102:6c9:b0:492:9ef9:9d1b with SMTP id ada2fe7eead31-498f46ea98fmr5901331137.22.1724494850411; Sat, 24 Aug 2024 03:20:50 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::936; envelope-from=yurivkhan@gmail.com; helo=mail-ua1-x936.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, 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:147795 Archived-At: On Sat, 24 Aug 2024 at 16:46, Heime wrote: > > 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 ? No. Consider: 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. Observed result: your minor mode is enabled in the buffer of some.el, but its configuration is not applied. Further: 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. Observed result: In the buffer of other.el, tema-minor-mode is not enabled, yet its configuration has been applied. 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? > (defvar tema-expr-elisp > '(("Functions" "^\\s-(defun\\s-+\\(\\_<.?\\_>\\)" 1))) > > (defun tema-imenu-expr-elisp () > "Set up a custom imenu expression for the current buffer." > (setq-local imenu-generic-expression tema-expr-elisp)) > > ;;;###autoload > (define-minor-mode tema-minor-mode > "DESC." > :init-value nil > :lighter " Tema" > > (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)))