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#74492: 31.0.50; [FR] explicit minor mode precedence Date: Sat, 23 Nov 2024 22:35:53 -0500 Message-ID: References: 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="7300"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 74492@debbugs.gnu.org, Sean Whitton To: Eshel Yaron Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 24 04:37:28 2024 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 1tF3RA-0001nf-5Q for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 24 Nov 2024 04:37:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tF3Qm-0007Rb-OP; Sat, 23 Nov 2024 22:37:04 -0500 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 1tF3Ql-0007RS-1i for bug-gnu-emacs@gnu.org; Sat, 23 Nov 2024 22:37:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tF3Qk-00085i-Ls for bug-gnu-emacs@gnu.org; Sat, 23 Nov 2024 22:37:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=7/7ROc1vym3SBUpAR3e09fNafWxuGLzpeUCqGzfiWm0=; b=jI9YsyOCDZBo/Bi/T0PSMTPcVtZ0tq4bVZoyUCpW2J/bYOr+5IgBdLBeQ0rNjEYS5YySw6KEU/Skzce68nqGrzXYADk43xtFr21+TpiSVKeJsQIgnYhss+45JvNN9NxT2DOuiKTqkoAUZEv9+XFFVg0cVgePXyJEnEygqavpnOIch9Iaj+vM3o9yu34qJnJOK5YDJsY0/RMZwKzAyXjeNAcHr0kUToieCHhiAZrUEF6yb0Cz+LMKqHRo+JjJFbg8fnbcEP1bv37wDC+YQrdx+zzBWmNiEMAOwMEALw3Ljzg93uDcZ4gc/iGjZ1ZGOBKo2InXCwC6CRvP0pVj+xob6Q==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tF3Qk-0008L8-6q for bug-gnu-emacs@gnu.org; Sat, 23 Nov 2024 22:37: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: Sun, 24 Nov 2024 03:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74492 X-GNU-PR-Package: emacs Original-Received: via spool by 74492-submit@debbugs.gnu.org id=B74492.173241936731974 (code B ref 74492); Sun, 24 Nov 2024 03:37:02 +0000 Original-Received: (at 74492) by debbugs.gnu.org; 24 Nov 2024 03:36:07 +0000 Original-Received: from localhost ([127.0.0.1]:60231 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tF3Pq-0008Jd-T2 for submit@debbugs.gnu.org; Sat, 23 Nov 2024 22:36:07 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:10640) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tF3Pm-0008J2-CW for 74492@debbugs.gnu.org; Sat, 23 Nov 2024 22:36:05 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 528C6441268; Sat, 23 Nov 2024 22:35:55 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1732419354; bh=zEreAn0x65c79qgd+dgL0DndCtr+i/G0W8kglUuGqhg=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=HfNLXMXo+LWsTbQGPslC++W5o3XNtjaI1a/JLS1tWxYUnk/pYh+tOE5EyxL6jHV54 EA74bOXW/tc29r+AEuSjhpQS8cmw5M0XqIkvnFLBpqIpw8S1vYGqr0GpGmgHdfHDsH uqfqbx2aoMQLu4FXHgFy9YjIMpQ1rNOKLeiZAtH02Rb6jAWztfQJnXOxQV0wTaP8rl iLw5Zll3LIozL8tH5zcbYKj/jNWubcxp6s9C62APr7hjARyGAz8TD8q/d5IAspP5Zm nZsctg1+U7bGifnSuD7eRJW42vw39ySfiAxoNOKYvVz/lPpyr58dUhjJOyk9RAcOeM zwiGmXytQ3VUQ== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id F3E4944125C; Sat, 23 Nov 2024 22:35:53 -0500 (EST) Original-Received: from pastel (104-195-225-43.cpe.teksavvy.com [104.195.225.43]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id C3E221206EB; Sat, 23 Nov 2024 22:35:53 -0500 (EST) In-Reply-To: (Eshel Yaron's message of "Sat, 23 Nov 2024 14:49:23 +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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:295881 Archived-At: >> BTW, maybe we should add some notion of minor mode precedence since such >> problems are actually fairly common. We could do something similar to >> what we do with `add-hook`, so `add-minor-mode` takes care of obeying >> the ordering constraints. > > Currently, the last minor mode to be defined takes precedence over > previously defined minor modes, at least in terms of keybindings. This > makes it hard-to-impossible for minor modes that need high precedence to > "guard" their keybindings from minor modes defined at any later time. > An explicit mechanism for specifying minor mode precedence could help. We should first try and figure out what it is that's really needed, tho. So I took a quick look at Emacs's own code and so far I found: ;; Define-minor-mode added our keymap to minor-mode-map-alist, but we want it ;; on minor-mode-overriding-map-alist instead. (setq minor-mode-map-alist (delq (assq 'completion-in-region-mode minor-mode-map-alist) minor-mode-map-alist)) in `minibuffer.el` which is related but can't just use a precedence because we want to change the keymap dynamically anyway. ;; Add a custom keymap for `visual-line-mode' so that activating ;; this minor mode does not override Org's keybindings. ;; FIXME: Probably `visual-line-mode' should take care of this. (let ((oldmap (cdr (assoc 'visual-line-mode minor-mode-map-alist))) (newmap (make-sparse-keymap))) (set-keymap-parent newmap oldmap) (define-key newmap [remap move-beginning-of-line] nil) (define-key newmap [remap move-end-of-line] nil) (define-key newmap [remap kill-line] nil) (make-local-variable 'minor-mode-overriding-map-alist) (push `(visual-line-mode . ,newmap) minor-mode-overriding-map-alist)) in `org.el` which is related but couldn't just use a precedence either. ;; Make sure we are first in minor-mode-map-alist (let ((c (assq 'orgtbl-mode minor-mode-map-alist))) ;; FIXME: maybe it should use emulation-mode-map-alists? (and c (setq minor-mode-map-alist (cons c (delq c minor-mode-map-alist))))) in `org-table.el` should could definitely use a precedence. and that's it. There used to be more for things like IDO or Viper, but IIRC that was solved with the introduction of `emulation-mode-map-alists`. I know there are more cases of "minor mode precedence" issues. E.g. I remember seeing recently an issue in VM where the `w3m` minor mode bindings used when rendering some HTML email body shadowed the buffer's major mode, but again a case where precedence between minor modes wouldn't help. I don't think the examples above justify adding the kind of precedences I suggested. Maybe if we find more examples out there in the wild, the picture might change. Otherwise, maybe we should look for something else that would solve the kinds of problems listed here. Stefan