unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ergus via "Emacs development discussions." <emacs-devel@gnu.org>
To: Juri Linkov <juri@linkov.net>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>, emacs-devel@gnu.org
Subject: Re: New Context Menu
Date: Sat, 21 Aug 2021 06:33:17 +0200	[thread overview]
Message-ID: <20210821043317.rve74pfsylir53py@Ergus> (raw)
In-Reply-To: <87h7fkdq6z.fsf@mail.linkov.net>

[-- Attachment #1: Type: text/plain, Size: 357 bytes --]


>> 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.



[-- Attachment #2: context-map.patch --]
[-- Type: text/plain, Size: 2112 bytes --]

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)
 
 \f
 ;; Commands that operate on windows.

  reply	other threads:[~2021-08-21  4:33 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210818120834.i3orh535tb2enpos.ref@Ergus>
2021-08-18 12:08 ` New Context Menu Ergus
2021-08-18 12:26   ` Eli Zaretskii
2021-08-18 12:43     ` Ergus
2021-08-18 13:30       ` Eli Zaretskii
2021-08-18 17:17         ` Ergus
2021-08-18 17:21           ` Eli Zaretskii
2021-08-18 17:32             ` Ergus
2021-08-18 16:50       ` Eli Zaretskii
2021-08-18 18:10         ` Ergus
2021-08-18 18:17           ` Eli Zaretskii
2021-08-18 19:23             ` Ergus
2021-08-18 19:28               ` Eli Zaretskii
2021-08-18 19:53                 ` Ergus
2021-08-19  6:31                   ` Eli Zaretskii
2021-08-19  7:07                     ` Juri Linkov
2021-08-18 19:34               ` Eli Zaretskii
2021-08-18 18:58         ` Juri Linkov
2021-08-18 19:12           ` Eli Zaretskii
2021-08-19  7:05             ` Juri Linkov
2021-08-19  7:51               ` Eli Zaretskii
2021-08-20  7:13                 ` Juri Linkov
2021-08-20 11:26                   ` Eli Zaretskii
2021-08-20 11:41                     ` Eli Zaretskii
2021-08-20 16:44                       ` Juri Linkov
2021-08-20 12:26                     ` Ergus
2021-08-20 12:36                       ` Eli Zaretskii
2021-08-20 12:59                         ` Ergus
2021-08-20 13:03                         ` Ergus
2021-08-20 13:34                           ` Eli Zaretskii
2021-08-20 17:36                             ` Ergus
2021-08-20 18:05                               ` Eli Zaretskii
2021-08-20 18:08                                 ` Ergus
2021-08-20 19:07                                   ` Eli Zaretskii
2021-08-21  6:20                                     ` Ergus
2021-08-21  6:53                                       ` Eli Zaretskii
2021-08-21 15:04                                         ` Ergus
2021-08-20 18:15                                 ` Ergus
2021-08-20 23:15                                   ` Michael Welsh Duggan
2021-08-18 14:04   ` Jean-Christophe Helary
2021-08-18 16:38     ` Iñigo Serna
2021-08-19  0:38       ` Jean-Christophe Helary
2021-08-19  7:08         ` Juri Linkov
2021-08-19 14:22           ` Jean-Christophe Helary
2021-08-19  7:01   ` Juri Linkov
2021-08-19  8:03     ` Eli Zaretskii
2021-08-19 14:11       ` Ergus
2021-08-19 15:48         ` Eli Zaretskii
2021-08-19 16:34           ` Yuri Khan
2021-08-20  7:14       ` Juri Linkov
2021-08-20 11:29         ` Eli Zaretskii
2021-08-20 16:49           ` Juri Linkov
2021-08-20 18:01             ` Eli Zaretskii
2021-08-23  7:33               ` Juri Linkov
2021-08-23 11:36                 ` Eli Zaretskii
2021-08-23 16:04                   ` Juri Linkov
2021-08-23 16:35                     ` Eli Zaretskii
2021-08-23 17:42                       ` Juri Linkov
2021-08-23 18:02                         ` Ergus
2021-08-24  6:35                           ` Juri Linkov
2021-08-24  8:00                             ` Ergus
2021-08-24 11:44                               ` Yuri Khan
2021-08-24 16:05                                 ` Ergus
2021-08-24 19:41                                   ` Yuri Khan
2021-08-24 20:48                                     ` Ergus
2021-08-19 13:57     ` Ergus
2021-08-20  7:24       ` Juri Linkov
2021-08-20 12:21         ` Ergus
2021-08-20 16:41           ` Juri Linkov
2021-08-21  4:33             ` Ergus via Emacs development discussions. [this message]
2021-08-22  8:56               ` Juri Linkov
2021-08-27  6:21   ` New Context Menu and mouse-1 Juri Linkov
2021-08-27  6:55     ` Eli Zaretskii
2021-08-27 17:03       ` Juri Linkov
2021-08-27 22:01         ` Stefan Monnier
2021-08-28 18:52           ` Juri Linkov
2021-08-29 16:53           ` Juri Linkov
2021-08-30  7:22             ` Juri Linkov
2021-08-30 12:54               ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210821043317.rve74pfsylir53py@Ergus \
    --to=emacs-devel@gnu.org \
    --cc=juri@linkov.net \
    --cc=monnier@iro.umontreal.ca \
    --cc=spacibba@aol.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).