From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ergus via "Emacs development discussions." Newsgroups: gmane.emacs.devel Subject: Re: New Context Menu Date: Sat, 21 Aug 2021 06:33:17 +0200 Message-ID: <20210821043317.rve74pfsylir53py@Ergus> References: <20210818120834.i3orh535tb2enpos.ref@Ergus> <20210818120834.i3orh535tb2enpos@Ergus> <87r1epzznt.fsf@mail.linkov.net> <20210819135701.ygypxl7asl4edwbp@Ergus> <87eeaoio3v.fsf@mail.linkov.net> <20210820122126.tp6zna2ei2n5wrbw@Ergus> <87h7fkdq6z.fsf@mail.linkov.net> Reply-To: Ergus Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="h7emrnawgzqkklsl" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33569"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier , emacs-devel@gnu.org To: Juri Linkov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Aug 21 06:34:31 2021 Return-path: Envelope-to: ged-emacs-devel@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 1mHIiF-0008aj-4z for ged-emacs-devel@m.gmane-mx.org; Sat, 21 Aug 2021 06:34:31 +0200 Original-Received: from localhost ([::1]:58576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mHIiD-0000FU-La for ged-emacs-devel@m.gmane-mx.org; Sat, 21 Aug 2021 00:34:29 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mHIhd-000813-Mf for emacs-devel@gnu.org; Sat, 21 Aug 2021 00:33:53 -0400 Original-Received: from sonic313-15.consmr.mail.bf2.yahoo.com ([74.6.133.125]:39410) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mHIha-0004RO-Ju for emacs-devel@gnu.org; Sat, 21 Aug 2021 00:33:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1629520428; bh=22bsoU9dODIomK59nKs4efMm7nw0unmU+UkfgzQZ+EE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject:Reply-To; b=nSpH41hpRzsRIFCKziXn2zmnMAC3QwwU3em+3TTbdVQuHT+ud11E1FA9wXAQK58GdG4Zd6ZOGYk/SaubUuN4l2BETyrR6xj0o2DX/PR1srAhIG0rb4GrbNoU+jT9mbVorBbw5drMz9ushb+5dzAi3bHkkVPM6rpUDFyxFvSGsjOmJ+UXQ5NJiqod9V9a0lJiR5H081j71rTMoQHO7JcpGMQBmsCwNCKVJP+r0cdQAVSiBoKiMyigIT1T5KL+FdDJd68GNioydldjA05Uz6h6u/vH6Wcf8C3kix223R7fwr6D6E7acFQ7e+K3foAio+kMb6XLyD/4S1/gC83YjmxIEQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1629520428; bh=TQ87OAJqIQh+q5DFXfiK3w38BIL4Bn6xSUEbp3ocEma=; h=X-Sonic-MF:Date:From:To:Subject:From:Subject; b=YKVs52NsaFk4HsWXGfgP00gL2TG8BZVv+g/olE7wk2A1tSBkVQXs0/JDI8sFHdqA+bceeUO7hFWnPVAQsxwBY0DwWt7PqbR7z9Crc1T72m/j6YUgEY/KhWgqRM5QhsRVqZ9TzHCfhI6w5MYZq8ay+rLfrvhnb/BKKO8sGSQs/xuiB9Yy2BJeahpZZ1KeGkNc+qq2Eqh5B7l4rI80ajz2FFmZnIvuNKKx/3QK858fWvHxRFZkkJzSKaeQFfvQID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0000 Original-Received: by kubenode524.mail-prod1.omega.ir2.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID b922c69bc3af280712181406b1866f78; Sat, 21 Aug 2021 04:33:43 +0000 (UTC) Content-Disposition: inline In-Reply-To: <87h7fkdq6z.fsf@mail.linkov.net> X-Mailer: WebService/1.1.18850 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.aol Received-SPF: pass client-ip=74.6.133.125; envelope-from=spacibba@aol.com; helo=sonic313-15.consmr.mail.bf2.yahoo.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:272756 Archived-At: --h7emrnawgzqkklsl Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline >> Just a question: >> >> If the context-menu-mode is a minor mode. Why the bindings are not added >> in a context-menu-mode-map and avoids manually saving the -old commands? >> >> Is there an issue with that? > >Thanks for the idea, this should work. > Please check the attached patch. It works for me and simplifies the current code for the bindings. --h7emrnawgzqkklsl Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="context-map.patch" diff --git a/lisp/mouse.el b/lisp/mouse.el index 3441a4787e..86427a02c6 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -440,42 +440,22 @@ context-menu-entry `(menu-item ,(purecopy "Context Menu") ignore :filter (lambda (_) (context-menu-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))))) +(defvar context-menu-mode-map + (let ((map (make-sparse-keymap))) + (define-key map [mouse-3] nil) + (define-key map [down-mouse-3] context-menu-entry) + (when (featurep 'ns) + (define-key map [C-mouse-1] nil) + (define-key map [C-down-mouse-1] context-menu-entry)) + map) + "Context-menu-mode map.") (define-minor-mode context-menu-mode "Toggle Context Menu mode. When Context Menu mode is enabled, clicking the mouse button down-mouse-3 activates the menu whose contents depends on its surrounding context." - :global t :group 'mouse - (if context-menu-mode - (progn - (setq context-menu--saved-bindings nil) - (context-menu--bind-mouse 'mouse-3 'down-mouse-3) - (when (featurep 'ns) - (context-menu--bind-mouse 'C-mouse-1 'C-down-mouse-1))) - (context-menu--restore-bindings))) + :global t :group 'mouse) ;; Commands that operate on windows. --h7emrnawgzqkklsl--