From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ergus 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: Sun, 20 Feb 2022 23:09:31 +0100 Message-ID: <20220220220931.524xf6jeihqkhay3@Ergus> References: <87ley5iclc.fsf.ref@aol.com> <87ley5iclc.fsf@aol.com> <87czjhmior.fsf@gnus.org> Reply-To: Ergus Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23812"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 54074@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 20 23:11:12 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 1nLuQB-00065W-L9 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Feb 2022 23:11:11 +0100 Original-Received: from localhost ([::1]:55076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nLuQA-00085S-95 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Feb 2022 17:11:10 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:37190) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nLuQ3-00084u-0L for bug-gnu-emacs@gnu.org; Sun, 20 Feb 2022 17:11:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40179) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nLuQ2-0006LV-KM for bug-gnu-emacs@gnu.org; Sun, 20 Feb 2022 17:11:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nLuQ2-00042p-GX for bug-gnu-emacs@gnu.org; Sun, 20 Feb 2022 17:11:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ergus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 20 Feb 2022 22:11: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.164539502415498 (code B ref 54074); Sun, 20 Feb 2022 22:11:02 +0000 Original-Received: (at 54074) by debbugs.gnu.org; 20 Feb 2022 22:10:24 +0000 Original-Received: from localhost ([127.0.0.1]:34076 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nLuPP-00041u-RH for submit@debbugs.gnu.org; Sun, 20 Feb 2022 17:10:24 -0500 Original-Received: from sonic310-15.consmr.mail.bf2.yahoo.com ([74.6.135.125]:41137) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nLuPN-00041h-Nv for 54074@debbugs.gnu.org; Sun, 20 Feb 2022 17:10:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1645395016; bh=6Mu0cQxkQCGt7vVBpfLQdMOUfUh2X6F7krxyemkwEYU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject:Reply-To; b=UqJGPIYCo67hLc9EJedWhdSgrAoFMqly28BI5fHkuE2dOEBRAZkmLDN/2X5Atf75LgmLLdyQp4JDUCGTt+dU/tva7ggj56HCkzpXqiBMwqegBCA4TLDkYQbJrIkYh8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HOWyY.xR3BgORMSY F1OnjIXshfiNYAaAiux8c_VB6VmnG6t94eizLfJO3ECxKTo9F9gaHQ2_SiDct3S4wQo_.BYlaNhF cuLds4PgtYyactrdZVsnB8U9pjPnOH6vZ9ablfVOMezCBMIrS0winhrUQYaxEKLPbKFCUalhHFHG 9ulxC807GcXfUSfKIPJH.3y4JKZnQGaxQGm.XAxDld89P.iqcmEATTjltsALwbsm2JJ7ldb9PQ6b pGXeoREsFXsl55xfKJxtrL3xH3mh9KgRjz5nlolIa0Azh1NpOEcANCsVFsR.lurlxmrit8cAWEOc ENX_T3FDpPkfa321siSTg5FDXvArYRdk9oSJLFmBxLehn2K.zc8yZg_BbG9iNqYPegpPLDl3pke7 y2M7wEp_5GNZRtxbIahc7kxfLnFwM6xLstzzvCSoKdBsSCY89Cwc0UOLh0R18J.jERVpK4AKiyk2 rZlX2zKpok.Js3ZuzbD4j3b5hFNhzKrnHBsua9mQAL X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.bf2.yahoo.com with HTTP; Sun, 20 Feb 2022 22:10:16 +0000 Original-Received: by kubenode501.mail-prod1.omega.ir2.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 21f7059d869fe736bd5b775abc1bbdd2; Sun, 20 Feb 2022 22:10:10 +0000 (UTC) Content-Disposition: inline In-Reply-To: <87czjhmior.fsf@gnus.org> X-Mailer: WebService/1.1.19797 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.aol 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:227283 Archived-At: On Sun, Feb 20, 2022 at 08:39:16PM +0100, Lars Ingebrigtsen wrote: >Ergus writes: > >> 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. Hi Lars.. thanks for replying! > >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? > Yes this is actually the common way to do it, but it is cumbersome with no reason for simpler cases... and when more than one keymap can be affected. Basically I mean to have a way to add an entry: (keymap …) to another... Because from the manual: "If an element of a keymap is itself a keymap, it counts as if this inner keymap were inlined in the outer keymap." So, simpler cleaner and eventually not needing execute or start a mode every time in a hook... Now keymap-set allows to add a command or keymap to a prefix in another, but not just append a keymap as is with no prefix and then remove it completely in a clean way... >> Something similar happens to some variables that are modified in minor >> modes and then should be restored... this forces sometimes to restart >> emacs... (for example completion-styles in fido-mode or some hooks that >> are always added and then need to be removed... all these is very >> mechanic and increases code and sources of errors...). >> >> The best approach for this one is to save the original value in an alist >> and assign with a wrapper around setq... and use a loop when disabling >> the mode to restore the original values.... it is not perfect, but works >> in many cases... > >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. > The common is just to save and the restore... isn't it the typical idea behind a mode? Right now the modes cleanup is a source of issues and code replication here and there for many mechanical thinks like add-hook/remove-hook, set variable, unset them, and so on... when the general idea is that all that may follow the same philosophy than keybindings set-unset... Best, Ergus