[Top][All Lists]

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

Re: Where the menu should be appeared when C-mouse-3 is triggered

From: Masatake YAMATO
Subject: Re: Where the menu should be appeared when C-mouse-3 is triggered
Date: Fri, 20 Jul 2012 13:55:34 +0900 (JST)


>> I don't this is easy to fix.
>> For KEYBOARD USER it is nice to popped up at point.
>> Howto, it is not nice for MOUSE USER.
> We can easily check what kind of event was used to run the command and
> then decide whether to popup near point or near the mouse.
> Such distinction is already used to decide whether to use a dialog-ox or
> the minibuffer to read a file-name.

Thank you for suggestion. Please, see the patch. 
Do I understand what you wrote?

>> Emacs has many useful commands(mouse oriented commands) which are
>> expected to be triggered from MOUSE. Some of them, including
>> C-mouse-3, are not suitable for keyboard operatoin.
> It's currently unsuitable, but we can make it suitable.

With the patch f10 can show the same menu items as 
C-mouse-3 shows. The menu is shows at point or mouse
cursor; last-nonmenu-event is referred to decide the
postion. The menu items reflects (current-buffer) when
the menu is shown at point.

I think a function showing menu at point may be useful
other elisp program, so I introduced `point-pixel-position'
and 'point' constant for POSITION parameter of `popup-menu'.

If this one is acceptable, I'd like to withdraw the original
f10 patch. 

Masatake YAMATO

=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog      2012-07-19 14:38:01 +0000
+++ lisp/ChangeLog      2012-07-20 03:57:05 +0000
@@ -1,3 +1,15 @@
+2012-07-20  Masatake YAMATO  <address@hidden>
+       * term/x-win.el (x-menu-bar-open): Use `frame-parameter'
+       to check whether menu-bar is shown or not. If not shown,
+       show the menu-bar as a popup menu instead of using tmm.
+       * subr.el (point-pixel-position): New function.
+       * mouse.el (popup-menu): Use the value returned from
+       `point-pixel-position' as POSITION if POSITION is
+       `point' when `popup-menu' is invoked.
 2012-07-19  Sam Steingold  <address@hidden>
        * vc/vc-dispatcher.el (vc-compilation-mode): Add, based on

=== modified file 'lisp/mouse.el'
--- lisp/mouse.el       2012-07-08 08:26:21 +0000
+++ lisp/mouse.el       2012-07-20 03:43:27 +0000
@@ -102,7 +102,8 @@
 MENU can be a keymap, an easymenu-style menu or a list of keymaps as for
 POSITION can be a click event or ((XOFFSET YOFFSET) WINDOW) and defaults to
-  the current mouse position.
+  the current mouse position. If POSITION is a symbol, `point' the current 
+position is used.
 PREFIX is the prefix argument (if any) to pass to the command."
   (let* ((map (cond
               ((keymapp menu) menu)
@@ -112,9 +113,16 @@
                                   (plist-get (get map 'menu-prop) :filter))))
                    (if filter (funcall filter (symbol-function map)) map)))))
         event cmd)
-    (unless position
-      (let ((mp (mouse-pixel-position)))
-       (setq position (list (list (cadr mp) (cddr mp)) (car mp)))))
+  (setq position
+       (cond
+        ((eq position 'point)
+         (let ((pp (point-pixel-position)))
+           (list (list (cadr pp) (cddr pp)) (car pp))))
+        ((not position)
+         (let ((mp (mouse-pixel-position)))
+           (list (list (cadr mp) (cddr mp)) (car mp))))
+        (t
+         position)))
     ;; The looping behavior was taken from lmenu's popup-menu-popup
     (while (and map (setq event
                          ;; map could be a prefix key, in which case

=== modified file 'lisp/subr.el'
--- lisp/subr.el        2012-07-19 06:24:04 +0000
+++ lisp/subr.el        2012-07-20 01:28:19 +0000
@@ -1148,6 +1148,12 @@
 be a list of the form returned by `event-start' and `event-end'."
   (nth 9 position))
+(defun point-pixel-position (&optional pos window)
+  "Return the pxiel position of point as (WINDOW X . Y).
+Analogous to `mouse-pixel-position'."
+  (let ((pp (posn-at-point pos window)))
+    (cons (posn-window pp) (posn-x-y pp))))
 ;;;; Obsolescent names for functions.

=== modified file 'lisp/term/x-win.el'
--- lisp/term/x-win.el  2012-04-27 05:40:46 +0000
+++ lisp/term/x-win.el  2012-07-20 03:39:48 +0000
@@ -1305,12 +1305,18 @@
 (declare-function accelerate-menu "xmenu.c" (&optional frame) t)
 (defun x-menu-bar-open (&optional frame)
-  "Open the menu bar if `menu-bar-mode' is on, otherwise call `tmm-menubar'."
+  "Open the menu bar if it is shown.
+`popup-menu' is used if it is off "
   (interactive "i")
-  (if (and menu-bar-mode
-          (fboundp 'accelerate-menu))
-      (accelerate-menu frame)
-    (tmm-menubar)))
+  (cond
+   ((and (not (zerop (or (frame-parameter nil 'menu-bar-lines) 0)))
+        (fboundp 'accelerate-menu))
+    (accelerate-menu frame))
+   (t
+    (popup-menu (mouse-menu-bar-map)
+               (if (listp last-nonmenu-event)
+                   nil
+                 'point)))))
 ;;; Window system initialization.

reply via email to

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