From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#54074: 29.0.50; Feature request emacs keymap-set and minor-modes Date: Mon, 21 Feb 2022 10:28:07 +0200 Organization: LINKOV.NET Message-ID: <86zgmkk5tk.fsf@mail.linkov.net> References: <87ley5iclc.fsf.ref@aol.com> <87ley5iclc.fsf@aol.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23638"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: 54074@debbugs.gnu.org To: Ergus Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 21 09:37:43 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 1nM4CU-0005wZ-FY for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 21 Feb 2022 09:37:42 +0100 Original-Received: from localhost ([::1]:49952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nM4CS-00021m-FU for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 21 Feb 2022 03:37:40 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:56776) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nM4Bq-00020n-Ot for bug-gnu-emacs@gnu.org; Mon, 21 Feb 2022 03:37:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41083) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nM4Bq-0000et-F5 for bug-gnu-emacs@gnu.org; Mon, 21 Feb 2022 03:37:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nM4Bq-0000Bx-DS for bug-gnu-emacs@gnu.org; Mon, 21 Feb 2022 03:37:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 21 Feb 2022 08:37: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.1645432574676 (code B ref 54074); Mon, 21 Feb 2022 08:37:02 +0000 Original-Received: (at 54074) by debbugs.gnu.org; 21 Feb 2022 08:36:14 +0000 Original-Received: from localhost ([127.0.0.1]:34980 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nM4B4-0000Aq-Hc for submit@debbugs.gnu.org; Mon, 21 Feb 2022 03:36:14 -0500 Original-Received: from relay11.mail.gandi.net ([217.70.178.231]:53113) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nM4B2-0000Aa-Tf for 54074@debbugs.gnu.org; Mon, 21 Feb 2022 03:36:13 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 99601100002; Mon, 21 Feb 2022 08:36:05 +0000 (UTC) In-Reply-To: <87ley5iclc.fsf@aol.com> (Ergus via's message of "Sun, 20 Feb 2022 20:04:31 +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:227309 Archived-At: > 1) > > With that then could be trivial to implemented something like > use-packages :bind, so > > (define-minor-mode my-mode > :global t > :keymap (my-mode-map > :map isearch-mode-map my-mode-isearch-map)) > > > or similar... I am wondering how nobody have requested this before, when > it is a very common issue I find in many packages around. You might be interested in how the composite keymaps are defined here: ``` (define-minor-mode outline-minor-mode :keymap (easy-mmode-define-keymap `(([menu-bar] . ,outline-minor-mode-menu-bar-map) (,outline-minor-mode-prefix . ,outline-mode-prefix-map)) :inherit outline-minor-mode-cycle-map) ``` Maybe such keymap definitions could be simplified. > 2) > > 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... > [...] > Does it makes sense?? Yes, this makes sense. We used the functions copied below until you proposed to move keybindings to context-menu-mode-map: ``` (defvar context-menu--saved-bindings nil "Alist of bindings to restore when `context-menu-mode' is disabled.") (defun context-menu--bind-mouse (click-sym down-sym) "Enable `context-menu-mode' mouse bindings. CLICK-SYM and DOWN-SYM are the mouse click and down key symbols to use." (let ((click (vector click-sym)) (down (vector down-sym))) (push (cons click-sym (global-key-binding click)) context-menu--saved-bindings) (global-unset-key click) (push (cons down-sym (global-key-binding down)) context-menu--saved-bindings) (global-set-key down context-menu-entry))) (defun context-menu--restore-bindings () "Restore saved `context-menu-mode' bindings." (pcase-dolist (`(,sym . ,binding) context-menu--saved-bindings) (let ((key (vector sym))) (if binding (global-set-key key binding) (global-unset-key key))))) ```