all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Masatake YAMATO <yamato@redhat.com>
To: monnier@IRO.UMontreal.CA
Cc: emacs-devel@gnu.org
Subject: Re: Where the menu should be appeared when C-mouse-3 is triggered
Date: Fri, 20 Jul 2012 13:55:34 +0900 (JST)	[thread overview]
Message-ID: <20120720.135534.2139116803885399180.yamato@redhat.com> (raw)
In-Reply-To: <jwvvchkt9h0.fsf-monnier+emacs@gnu.org>

Hi,

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


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  <yamato@redhat.com>
+
+	* 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  <sds@gnu.org>
 
 	* 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
 `x-popup-menu'.
 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 point
+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))))
+
 \f
 ;;;; 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)))))
 
 \f
 ;;; Window system initialization.




  reply	other threads:[~2012-07-20  4:55 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-19 18:41 [patch] showing menu bar temporarily when f10 is pressed Masatake YAMATO
2012-06-19 20:31 ` Lluís
2012-06-19 21:42 ` Stefan Monnier
2012-06-20  6:17   ` [patch v2] " Masatake YAMATO
2012-07-18 11:29     ` [patch v3] " Masatake YAMATO
2012-07-19  6:54       ` Stefan Monnier
2012-07-19  8:32         ` Where the menu should be appeared when C-mouse-3 is triggered (Was: [patch v3] showing menu bar temporarily when f10 is pressed) Masatake YAMATO
2012-07-19  9:07           ` Where the menu should be appeared when C-mouse-3 is triggered Stefan Monnier
2012-07-20  4:55             ` Masatake YAMATO [this message]
2012-07-20 11:38               ` Stefan Monnier
2012-07-20 11:56                 ` Masatake YAMATO
2012-07-28  9:31                   ` Masatake YAMATO
2012-08-09 11:13                     ` Masatake YAMATO
2012-08-10 12:44                       ` Stefan Monnier
2012-08-10 13:21                         ` Drew Adams
2012-08-10 13:52                         ` Masatake YAMATO
2012-08-10 14:47                         ` Stefan Monnier
2012-07-20 12:48                 ` Masatake YAMATO

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

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

  git send-email \
    --in-reply-to=20120720.135534.2139116803885399180.yamato@redhat.com \
    --to=yamato@redhat.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@IRO.UMontreal.CA \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.