emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: poplife-mode


From: Stefan Monnier
Subject: Re: poplife-mode
Date: Sun, 12 Nov 2017 13:06:56 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> I think this should actually be provided in core: down-mouse-3 should be
> bound to a command implementing this, with some standardized way to find
> a contextual menu (looking at local char-properties, and if not
> found, buffer-local variable).

Maybe with something like the patch below.


        Stefan


diff --git a/lisp/mouse.el b/lisp/mouse.el
index 5eeee1ec52..90357806a1 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -50,10 +49,15 @@ mouse-drag-copy-region
 This affects `mouse-save-then-kill' (\\[mouse-save-then-kill]) in
 addition to mouse drags."
   :type 'boolean
-  :version "24.1"
-  :group 'mouse)
+  :version "24.1")
+
+(defcustom mouse-long-click-time 450
+  "Time after which a click is considered long.")
 
-(defcustom mouse-1-click-follows-link 450
+(defcustom mouse-1-click-follows-link
+  ;; FIXME: Maybe values 1 and -1 should be used to mean
+  ;; "use mouse-long-click-time".
+  mouse-long-click-time
   "Non-nil means that clicking Mouse-1 on a link follows the link.
 
 With the default setting, an ordinary Mouse-1 click on a link
@@ -2455,12 +2451,22 @@ function-key-map
 (if (not (eq system-type 'ms-dos))
     (global-set-key [S-down-mouse-1] 'mouse-appearance-menu))
 ;; C-down-mouse-2 is bound in facemenu.el.
-(global-set-key [C-down-mouse-3]
-  `(menu-item ,(purecopy "Menu Bar") ignore
-    :filter (lambda (_)
-              (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
-                  (mouse-menu-bar-map)
-                (mouse-menu-major-mode-map)))))
+(let ((default-context-menu
+        `(menu-item ,(purecopy "Menu Bar") ignore
+          :filter (lambda (_)
+                    (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
+                        (mouse-menu-bar-map)
+                      (mouse-menu-major-mode-map))))))
+  (global-set-key [C-down-mouse-3] default-context-menu)
+  (global-set-key [context-menu] default-context-menu))
+
+(global-set-key [down-mouse-3] #'mouse-maybe-context-menu)
+(defun mouse-maybe-context-menu (event)
+  "Bring up a context menu for a long click.
+See `mouse-long-click-time' and `mouse-context-menu-function'."
+  (interactive "@e")
+  (if (sit-for (/ mouse-long-click-time 1000.0))
+      (push (cons 'context-menu (cdr event)) unread-command-events)))
 
 ;; Binding mouse-1 to mouse-select-window when on mode-, header-, or
 ;; vertical-line prevents Emacs from signaling an error when the mouse




reply via email to

[Prev in Thread] Current Thread [Next in Thread]