From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#54074: 29.0.50; Feature request emacs keymap-set and minor-modes Date: Mon, 21 Feb 2022 16:22:23 -0500 Message-ID: References: <87ley5iclc.fsf.ref@aol.com> <87ley5iclc.fsf@aol.com> <87czjhmior.fsf@gnus.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28289"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Ergus , 54074@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 21 22:23:15 2022 Return-path: Envelope-to: geb-bug-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 1nMG9L-00078k-7V for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 21 Feb 2022 22:23:15 +0100 Original-Received: from localhost ([::1]:53282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMG9K-00039K-9k for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 21 Feb 2022 16:23:14 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:56046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMG99-00038n-03 for bug-gnu-emacs@gnu.org; Mon, 21 Feb 2022 16:23:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45423) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nMG98-0004zM-NN for bug-gnu-emacs@gnu.org; Mon, 21 Feb 2022 16:23:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nMG98-0000KN-Fy for bug-gnu-emacs@gnu.org; Mon, 21 Feb 2022 16:23:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 21 Feb 2022 21:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54074 X-GNU-PR-Package: emacs Original-Received: via spool by 54074-submit@debbugs.gnu.org id=B54074.16454785541204 (code B ref 54074); Mon, 21 Feb 2022 21:23:02 +0000 Original-Received: (at 54074) by debbugs.gnu.org; 21 Feb 2022 21:22:34 +0000 Original-Received: from localhost ([127.0.0.1]:39320 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nMG8f-0000JM-UI for submit@debbugs.gnu.org; Mon, 21 Feb 2022 16:22:34 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:11000) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nMG8d-0000J5-JA for 54074@debbugs.gnu.org; Mon, 21 Feb 2022 16:22:32 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 9F6A9805B1; Mon, 21 Feb 2022 16:22:25 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 26F8C800A5; Mon, 21 Feb 2022 16:22:24 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1645478544; bh=35dzUHLAuajNjOUh+b/DBwGPDwfYSpx+B/i68OdY1FA=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=iNOBLSmtB16w434+VS+CUtFtnelgzC5iAcdqAvWXj4r+uR4ZibbDblJXCen5gcczy cGMaG9NXmiHqd2GjjnVWg7UkNWtoRFAUBZzpnSB5rhByYCXrhUrDG6UtP6G0I+30Ka /yuaLxh9oZ05RD68sUowDj5V9lQf+H5x3jv/7ke04RV92wpY3YzVNYCCmZ6vFSQHe8 VJq2UPaGIPQgSmkET7p2veiqTvJVtDQY0WOE5s51Ym6x+/H6aO4V6NWE71HHfUndQb dr72+so7KzMy8m1AppyGiy1frbUE2D1I1CCHdQLwbzKpzNFh/eKGkP3eSgbKDlm19F vUuzUP2v2zugg== Original-Received: from pastel (unknown [45.72.197.68]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id E47EF120F08; Mon, 21 Feb 2022 16:22:23 -0500 (EST) In-Reply-To: <87czjhmior.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sun, 20 Feb 2022 20:39:16 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:227387 Archived-At: >> Recently I have seen that many packages have a pattern where a global >> minor mode adds a set of keybindings to another (like isearch or >> minibuffer). The issue comes when they want to disable the mode, because >> sometimes they need to iterate or loop over, and then emacs looses the >> previous binding unless they also adds more code to remember it when set >> and then bring it back when unset. > I'm not sure I understand the use case. Isn't the way to do this just > to have my-mode add itself to isearch-mode-hook, and then have my-mode > have a minor mode keymap with the prefix it uses? I think the use case is basically any minor mode which currently uses `define-key` in its body to modify some other package's keymap. > I don't think there's any general mechanism that's possible for this. > Any package may mogrify any variable (destructively or not), and only > the package can know what it has to do to bring things back to normal > when the package is switched off. I think we should provide an API to do that meaningfully. I.e. instead of having a minor mode just bluntly set a variable, associate with each global var a pair (VAL . FUNS) of a base value and a list of functions, where the effective value (the one that should be stored in the `symbol-value`, barring intervention from code that disregards the new API) is (FUN1 (FUN2 (... VAL))). The minor mode can then add/remove a function from the list, and just as is the case with `add-hook`, `add-function`, etc... it will correctly handle the case where the additions/removals are not nested. Stefan