unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [patch] showing menu bar temporarily when f10 is pressed
@ 2012-06-19 18:41 Masatake YAMATO
  2012-06-19 20:31 ` Lluís
  2012-06-19 21:42 ` Stefan Monnier
  0 siblings, 2 replies; 18+ messages in thread
From: Masatake YAMATO @ 2012-06-19 18:41 UTC (permalink / raw)
  To: emacs-devel

Hi,

Are you using menu bar?

Menu bar is useful to know what kind of major commands are available.
M-x [tab] shows too many commands.:-P 

As you may know you can activate menu bar with `menu-bar-open'.  In
addition These days, as far as I know \C-n, \C-p, \C-f, \C-b, and \C-g
are available in choosing menu items. So even if you don't use mouse,
menu bar is still useful.

However, menu bar occupies one line. If menu bar is turend off, emacs
can show one more text line for editing or viewing.  I guess you,
experts of Emacs, may turn off menu bar. I know many of you may be
eager for more area to show source code lines. Me, too. However,
sometimes I want to use menu bar. Especially in gud mode.

This patch enhances the behavior of f10(`menu-bar-open').
With this patch, `menu-bar-open' shows menu bar temporarily
even if menu-bar-mode is turned off. After choosing something
menu item or \C-g, the menu bar is hidden automatically.

Even without this patch, you can choose menu item with tmm.  you can
choose a menu item with specifying the first character of menu item
you want to choose recursively. But I would like to choose a menu item
with positionally/geometrically operation. I guess you would, too.


Masatake YAMATO


=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2012-06-14 14:22:37 +0000
+++ lisp/ChangeLog	2012-06-19 17:52:08 +0000
@@ -1,3 +1,8 @@
+2012-06-19  Masatake YAMATO  <yamato@redhat.com>
+
+	* term/x-win.el (x-menu-temorary-visibility): New custom var.
+	(x-menu-bar-open): Show menu bar temporarily if `x-menu-temorary-visibility'.
+
 2012-06-14  Andreas Schwab  <schwab@linux-m68k.org>
 
 	* play/doctor.el (doctor-doc): Remove parameter and use

=== 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-06-19 17:50:31 +0000
@@ -1190,6 +1190,15 @@
 		      (const TEXT)))
   :group 'killing)
 
+(defcustom x-menu-temorary-visibility t
+  "Control whether use menu bar or `tmm-menubar' when `x-menu-bar-open' is invoked.
+Non-nil means showing menu bar temporarily even if `menu-bar-mode' is turned off.
+If nil, the behavior is changed whether `menu-bar-mode' is on or off. See `x-menu-bar-open'
+for more detail."
+  :type 'boolean
+  :group 'x
+  :version "24.2")
+
 ;; Get a selection value of type TYPE by calling x-get-selection with
 ;; an appropriate DATA-TYPE argument decided by `x-select-request-type'.
 ;; The return value is already decoded.  If x-get-selection causes an
@@ -1305,11 +1314,28 @@
 (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 `menu-bar-mode' is on or `x-menu-temorary-visibility' is non-nil, otherwise call `tmm-menubar'."
   (interactive "i")
-  (if (and menu-bar-mode
-	   (fboundp 'accelerate-menu))
-      (accelerate-menu frame)
+  (if (fboundp 'accelerate-menu)
+      (cond
+       (menu-bar-mode
+	(accelerate-menu frame))
+       (x-menu-temorary-visibility
+	(let ((visible menu-bar-mode)
+	      r)
+	  (unless visible
+	    (menu-bar-mode 1))
+	  (setq r (accelerate-menu frame))
+	  (unless visible
+	    (letrec ((turn-the-mode (lambda ()
+				      (remove-hook 'deactivate-menubar-hook
+						   'turn-off-menu-bar-mode)
+				      (menu-bar-mode -1))))
+	      (add-hook 'deactivate-menubar-hook
+			turn-the-mode)))
+	  r))
+       (t
+	(tmm-menubar)))
     (tmm-menubar)))
 
 \f

=== modified file 'src/ChangeLog'
--- src/ChangeLog	2012-06-14 04:02:35 +0000
+++ src/ChangeLog	2012-06-19 17:57:06 +0000
@@ -1,3 +1,11 @@
+2012-06-19  Masatake YAMATO  <yamato@redhat.com>
+
+	* xmenu.c (popup_deactivate_callback): Run Qdeactivate_menubar_hook.
+
+	* keyboard.c (Qdeactivate_menubar_hook): Define a new hook.
+
+	* keyboard.c (Qdeactivate_menubar_hook): Declare the new hook.
+
 2012-06-14  Paul Eggert  <eggert@cs.ucla.edu>
 
 	* .gdbinit (xgetint): Fix recently-introduced paren typo.

=== modified file 'src/keyboard.c'
--- src/keyboard.c	2012-06-02 19:21:34 +0000
+++ src/keyboard.c	2012-06-19 17:10:11 +0000
@@ -257,6 +257,7 @@
 static Lisp_Object Qdeactivate_mark;
 
 Lisp_Object Qrecompute_lucid_menubar, Qactivate_menubar_hook;
+Lisp_Object Qdeactivate_menubar_hook;
 
 static Lisp_Object Qecho_area_clear_hook;
 
@@ -11535,6 +11536,7 @@
 
   DEFSYM (Qrecompute_lucid_menubar, "recompute-lucid-menubar");
   DEFSYM (Qactivate_menubar_hook, "activate-menubar-hook");
+  DEFSYM (Qdeactivate_menubar_hook, "deactivate-menubar-hook");
 
   DEFSYM (Qpolling_period, "polling-period");
 

=== modified file 'src/keyboard.h'
--- src/keyboard.h	2012-02-10 18:58:48 +0000
+++ src/keyboard.h	2012-06-19 17:08:30 +0000
@@ -212,6 +212,7 @@
 extern Lisp_Object internal_last_event_frame;
 \f
 extern Lisp_Object Qrecompute_lucid_menubar, Qactivate_menubar_hook;
+extern Lisp_Object Qdeactivate_menubar_hook;
 
 /* This holds a Lisp vector that holds the properties of a single
    menu item while decoding it in parse_menu_item.

=== modified file 'src/xmenu.c'
--- src/xmenu.c	2012-02-10 18:58:48 +0000
+++ src/xmenu.c	2012-06-19 17:07:58 +0000
@@ -686,12 +686,14 @@
 static void
 popup_deactivate_callback (GtkWidget *widget, gpointer client_data)
 {
+  safe_run_hooks (Qdeactivate_menubar_hook);
   popup_activated_flag = 0;
 }
 #else
 static void
 popup_deactivate_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
 {
+  safe_run_hooks (Qdeactivate_menubar_hook);
   popup_activated_flag = 0;
 }
 #endif




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [patch] showing menu bar temporarily when f10 is pressed
  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
  1 sibling, 0 replies; 18+ messages in thread
From: Lluís @ 2012-06-19 20:31 UTC (permalink / raw)
  To: Masatake YAMATO; +Cc: emacs-devel

Masatake YAMATO writes:

> This patch enhances the behavior of f10(`menu-bar-open').
> With this patch, `menu-bar-open' shows menu bar temporarily
> even if menu-bar-mode is turned off. After choosing something
> menu item or \C-g, the menu bar is hidden automatically.

I'd love that :)


Lluis

-- 
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [patch] showing menu bar temporarily when f10 is pressed
  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
  1 sibling, 1 reply; 18+ messages in thread
From: Stefan Monnier @ 2012-06-19 21:42 UTC (permalink / raw)
  To: Masatake YAMATO; +Cc: emacs-devel

> +	  (unless visible
> +	    (menu-bar-mode 1))

Here we have a problem: if you have several frames, some of which have
a menu-bar and some don't, this will add a menu-bar to all of them, and
then (menu-bar-mode -1) will remove it from all the frames.

Why do you need the menu-bar?  Why not pop up the menu usually bound to
C-mouse-3?


        Stefan



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [patch v2] showing menu bar temporarily when f10 is pressed
  2012-06-19 21:42 ` Stefan Monnier
@ 2012-06-20  6:17   ` Masatake YAMATO
  2012-07-18 11:29     ` [patch v3] " Masatake YAMATO
  0 siblings, 1 reply; 18+ messages in thread
From: Masatake YAMATO @ 2012-06-20  6:17 UTC (permalink / raw)
  To: monnier; +Cc: emacs-devel

>> +	  (unless visible
>> +	    (menu-bar-mode 1))
> 
> Here we have a problem: if you have several frames, some of which have
> a menu-bar and some don't, this will add a menu-bar to all of them, and
> then (menu-bar-mode -1) will remove it from all the frames.

Thank you for reviewing.
I've revised my patch to handle the case you pointed out. 
In the new patch, I deal with only frame local parameter.
I don't touch the minor mode.
I have still one un solved(TODO) item. 

> Why do you need the menu-bar?  Why not pop up the menu usually bound to
> C-mouse-3?

To be honest, I didn't know that.
I've just tried C-mouse-3; and found some advantages of C-mouse-3
comparing with f10 for KEYBOARD USER. 

1. With C-mouse-3, the menu is pop up where mouse pointer is.
   With f10, the menu is appeared at the top of frame.
   With f10, the position is predictable.

   Following the cases user may lost the mouse pointer:

   * using large display,
   * editing text with keyboard long time, and/or
   * turning on mouse-avoidance-mode.
   
   In addition it seems that emacs hides the mouse pointer 
   while the user editing text continuously. 

   So with C-moues-3, the user have to search the menu
   popup'ed. Time taking searching is very short but
   some user may feel frustration when the menu appeared
   on somewhere far away from (point). 

   In other hand, with f10, the user can predict the 
   place where menu appears. No mental overload.

2. With C-mouse-3, the contents of menu is chosen based
   on the window where the mouse pointer is.

   Consider a frame is splited into two windows.
   Each window holds different buffer. And different
   major modes are activated on buffers:

   Window A -> Buffer B -> Major mode C.
   Window D -> Buffer D -> Major mode E.

   Consider the following situation:
      You are editing text on buffer B, and
      Mouse pointer is at D.

   When C-mouse-3 is operated in this situation, a popup menu(P0)
   which includes a menu entry for major mode E will be appeared. But
   user may exepct a popup menu(P1) which includes a menu entry for
   major mode C is appeared.

   To show P1 in this situation, the user must move the
   mouse pointer to somewhere Window A.
   It doesn't take long time to move the mouse pointer to 
   Window A. some user may feel frustration. 

Moving the mouse cursor to (point) automatically before
C-mouse-3 may convers two disadvantage of C-mouse-3 with
keyboard operation. This is interesting idea, However, I 
feel extending [f10] is natural.

Masatake YAMATO
   

=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2012-06-14 14:22:37 +0000
+++ lisp/ChangeLog	2012-06-20 03:28:45 +0000
@@ -1,3 +1,9 @@
+2012-06-19  Masatake YAMATO  <yamato@redhat.com>
+
+	* term/x-win.el (x-menu-bar-temorary-visibility): New custom var.
+	(x-menu-bar-open): Show menu bar temporarily if `x-menu-bar-temorary-visibility'.
+	(x-accelerate-menu-with-temporary-visible-menu-bar): New function.
+
 2012-06-14  Andreas Schwab  <schwab@linux-m68k.org>
 
 	* play/doctor.el (doctor-doc): Remove parameter and use

=== 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-06-20 03:43:31 +0000
@@ -1,4 +1,4 @@
-;;; x-win.el --- parse relevant switches and set up for X  -*-coding: iso-2022-7bit;-*-
+;;; x-win.el --- parse relevant switches and set up for X  -*-coding: iso-2022-7bit; lexical-binding: t; -*-
 
 ;; Copyright (C) 1993-1994, 2001-2012 Free Software Foundation, Inc.
 
@@ -1190,6 +1190,15 @@
 		      (const TEXT)))
   :group 'killing)
 
+(defcustom x-menu-bar-temorary-visibility t
+  "Control whether use menu bar or `tmm-menubar' when `x-menu-bar-open' is invoked.
+Non-nil means showing menu bar temporarily even if `menu-bar-mode' is turned off.
+If nil, the behavior is changed whether `menu-bar-mode' is on or off. See `x-menu-bar-open'
+for more detail."
+  :type 'boolean
+  :group 'x
+  :version "24.2")
+
 ;; Get a selection value of type TYPE by calling x-get-selection with
 ;; an appropriate DATA-TYPE argument decided by `x-select-request-type'.
 ;; The return value is already decoded.  If x-get-selection causes an
@@ -1304,12 +1313,35 @@
 
 (declare-function accelerate-menu "xmenu.c" (&optional frame) t)
 
+(defun x-accelerate-menu-with-temporary-visible-menu-bar (frame)
+  "Do `accelerate-menu' with temporarily visible menu bar of FRAME."
+  (let ((old-menu-bar-lines (frame-parameter frame 'menu-bar-lines))
+	(old-frame (or frame (selected-frame))))
+    (if (menu-bar-positive-p old-menu-bar-lines)
+	(accelerate-menu frame)
+      (letrec ((hide (lambda ()
+		       (remove-hook 'deactivate-menubar-hook hide)
+		       ;; TODO: How can I handle the case the menu bar visibility is 
+		       ;;       changed as the effect of menu item choice.
+		       (when (frame-live-p old-frame)
+			 (set-frame-parameter old-frame 
+					      'menu-bar-lines old-menu-bar-lines)))))
+	(set-frame-parameter old-frame 'menu-bar-lines 1)
+	(prog1
+	    (accelerate-menu frame)
+	  (add-hook 'deactivate-menubar-hook hide))))))
+
 (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 `menu-bar-mode' is on or `x-menu-bar-temorary-visibility' is non-nil, otherwise call `tmm-menubar'."
   (interactive "i")
-  (if (and menu-bar-mode
-	   (fboundp 'accelerate-menu))
-      (accelerate-menu frame)
+  (if (fboundp 'accelerate-menu)
+      (cond
+       (x-menu-bar-temorary-visibility
+	(x-accelerate-menu-with-temporary-visible-menu-bar frame))
+       (menu-bar-mode
+	(accelerate-menu frame))
+       (t
+	(tmm-menubar)))
     (tmm-menubar)))
 
 \f

=== modified file 'src/ChangeLog'
--- src/ChangeLog	2012-06-14 04:02:35 +0000
+++ src/ChangeLog	2012-06-20 03:29:35 +0000
@@ -1,3 +1,11 @@
+2012-06-19  Masatake YAMATO  <yamato@redhat.com>
+
+	* xmenu.c (popup_deactivate_callback): Run Qdeactivate_menubar_hook.
+
+	* keyboard.c (Qdeactivate_menubar_hook): Define a new hook.
+
+	* keyboard.h (Qdeactivate_menubar_hook): Declare the new hook.
+
 2012-06-14  Paul Eggert  <eggert@cs.ucla.edu>
 
 	* .gdbinit (xgetint): Fix recently-introduced paren typo.

=== modified file 'src/keyboard.c'
--- src/keyboard.c	2012-06-02 19:21:34 +0000
+++ src/keyboard.c	2012-06-19 17:10:11 +0000
@@ -257,6 +257,7 @@
 static Lisp_Object Qdeactivate_mark;
 
 Lisp_Object Qrecompute_lucid_menubar, Qactivate_menubar_hook;
+Lisp_Object Qdeactivate_menubar_hook;
 
 static Lisp_Object Qecho_area_clear_hook;
 
@@ -11535,6 +11536,7 @@
 
   DEFSYM (Qrecompute_lucid_menubar, "recompute-lucid-menubar");
   DEFSYM (Qactivate_menubar_hook, "activate-menubar-hook");
+  DEFSYM (Qdeactivate_menubar_hook, "deactivate-menubar-hook");
 
   DEFSYM (Qpolling_period, "polling-period");
 

=== modified file 'src/keyboard.h'
--- src/keyboard.h	2012-02-10 18:58:48 +0000
+++ src/keyboard.h	2012-06-19 17:08:30 +0000
@@ -212,6 +212,7 @@
 extern Lisp_Object internal_last_event_frame;
 \f
 extern Lisp_Object Qrecompute_lucid_menubar, Qactivate_menubar_hook;
+extern Lisp_Object Qdeactivate_menubar_hook;
 
 /* This holds a Lisp vector that holds the properties of a single
    menu item while decoding it in parse_menu_item.

=== modified file 'src/xmenu.c'
--- src/xmenu.c	2012-02-10 18:58:48 +0000
+++ src/xmenu.c	2012-06-19 17:07:58 +0000
@@ -686,12 +686,14 @@
 static void
 popup_deactivate_callback (GtkWidget *widget, gpointer client_data)
 {
+  safe_run_hooks (Qdeactivate_menubar_hook);
   popup_activated_flag = 0;
 }
 #else
 static void
 popup_deactivate_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
 {
+  safe_run_hooks (Qdeactivate_menubar_hook);
   popup_activated_flag = 0;
 }
 #endif




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [patch v3] showing menu bar temporarily when f10 is pressed
  2012-06-20  6:17   ` [patch v2] " Masatake YAMATO
@ 2012-07-18 11:29     ` Masatake YAMATO
  2012-07-19  6:54       ` Stefan Monnier
  0 siblings, 1 reply; 18+ messages in thread
From: Masatake YAMATO @ 2012-07-18 11:29 UTC (permalink / raw)
  To: monnier; +Cc: emacs-devel

Hi,

If no objection, please, install this patch to the official source tree.
I've attached the latest version.

(I'm using this patch on gnome-shell, which provides generic(?) full-screen 
 mode. The full-screen mode with this patch is quite nice.)

Masatake YAMATO

>>> +	  (unless visible
>>> +	    (menu-bar-mode 1))
>> 
>> Here we have a problem: if you have several frames, some of which have
>> a menu-bar and some don't, this will add a menu-bar to all of them, and
>> then (menu-bar-mode -1) will remove it from all the frames.
> 
> Thank you for reviewing.
> I've revised my patch to handle the case you pointed out. 
> In the new patch, I deal with only frame local parameter.
> I don't touch the minor mode.
> I have still one un solved(TODO) item. 
> 
>> Why do you need the menu-bar?  Why not pop up the menu usually bound to
>> C-mouse-3?
> 
> To be honest, I didn't know that.
> I've just tried C-mouse-3; and found some advantages of C-mouse-3
> comparing with f10 for KEYBOARD USER. 
> 
> 1. With C-mouse-3, the menu is pop up where mouse pointer is.
>    With f10, the menu is appeared at the top of frame.
>    With f10, the position is predictable.
> 
>    Following the cases user may lost the mouse pointer:
> 
>    * using large display,
>    * editing text with keyboard long time, and/or
>    * turning on mouse-avoidance-mode.
>    
>    In addition it seems that emacs hides the mouse pointer 
>    while the user editing text continuously. 
> 
>    So with C-moues-3, the user have to search the menu
>    popup'ed. Time taking searching is very short but
>    some user may feel frustration when the menu appeared
>    on somewhere far away from (point). 
> 
>    In other hand, with f10, the user can predict the 
>    place where menu appears. No mental overload.
> 
> 2. With C-mouse-3, the contents of menu is chosen based
>    on the window where the mouse pointer is.
> 
>    Consider a frame is splited into two windows.
>    Each window holds different buffer. And different
>    major modes are activated on buffers:
> 
>    Window A -> Buffer B -> Major mode C.
>    Window D -> Buffer D -> Major mode E.
> 
>    Consider the following situation:
>       You are editing text on buffer B, and
>       Mouse pointer is at D.
> 
>    When C-mouse-3 is operated in this situation, a popup menu(P0)
>    which includes a menu entry for major mode E will be appeared. But
>    user may exepct a popup menu(P1) which includes a menu entry for
>    major mode C is appeared.
> 
>    To show P1 in this situation, the user must move the
>    mouse pointer to somewhere Window A.
>    It doesn't take long time to move the mouse pointer to 
>    Window A. some user may feel frustration. 
> 
> Moving the mouse cursor to (point) automatically before
> C-mouse-3 may convers two disadvantage of C-mouse-3 with
> keyboard operation. This is interesting idea, However, I 
> feel extending [f10] is natural.
> 
> Masatake YAMATO

=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2012-06-24 15:06:24 +0000
+++ lisp/ChangeLog	2012-07-04 17:42:24 +0000
@@ -1,3 +1,15 @@
+2012-06-19  Masatake YAMATO  <yamato@redhat.com>
+
+	* term/x-win.el (x-menu-bar-temorary-visibility): New custom var.
+	(x-menu-bar-open): Show menu bar temporarily if `x-menu-bar-temorary-visibility'.
+	(x-accelerate-menu-with-temporary-visible-menu-bar): New function.
+
 2012-06-24  Chong Yidong  <cyd@gnu.org>
 
 	* xml.el (xml-parse-tag): Correctly handle comment embedded in

=== modified file 'src/ChangeLog'
--- src/ChangeLog	2012-06-25 10:28:47 +0000
+++ src/ChangeLog	2012-06-25 12:38:35 +0000
@@ -1,3 +1,11 @@
+2012-06-19  Masatake YAMATO  <yamato@redhat.com>
+
+	* xmenu.c (popup_deactivate_callback): Run Qdeactivate_menubar_hook.
+
+	* keyboard.c (Qdeactivate_menubar_hook): Define a new hook.
+
+	* keyboard.h (Qdeactivate_menubar_hook): Declare the new hook.
+
 2012-06-25  Andreas Schwab  <schwab@linux-m68k.org>
 
 	* keyboard.c (menu_bar_items, menu_bar_item, read_key_sequence):

=== 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-06-20 07:23:03 +0000
@@ -1,4 +1,4 @@
-;;; x-win.el --- parse relevant switches and set up for X  -*-coding: iso-2022-7bit;-*-
+;;; x-win.el --- parse relevant switches and set up for X  -*-coding: iso-2022-7bit; lexical-binding: t; -*-
 
 ;; Copyright (C) 1993-1994, 2001-2012 Free Software Foundation, Inc.
 
@@ -1190,6 +1190,15 @@
 		      (const TEXT)))
   :group 'killing)
 
+(defcustom x-menu-bar-temorary-visibility t
+  "Control whether use menu bar or `tmm-menubar' when `x-menu-bar-open' is invoked.
+Non-nil means showing menu bar temporarily even if `menu-bar-mode' is turned off.
+If nil, the behavior is changed whether `menu-bar-mode' is on or off. See `x-menu-bar-open'
+for more detail."
+  :type 'boolean
+  :group 'x
+  :version "24.2")
+
 ;; Get a selection value of type TYPE by calling x-get-selection with
 ;; an appropriate DATA-TYPE argument decided by `x-select-request-type'.
 ;; The return value is already decoded.  If x-get-selection causes an
@@ -1304,12 +1313,38 @@
 
 (declare-function accelerate-menu "xmenu.c" (&optional frame) t)
 
+(defun x-accelerate-menu-with-temporary-visible-menu-bar (frame)
+  "Do `accelerate-menu' with temporarily visible menu bar of FRAME."
+  (let ((old-menu-bar-lines (frame-parameter frame 'menu-bar-lines))
+	(old-frame (or frame (selected-frame)))
+	(old-menu-bar-mode menu-bar-mode))
+    (if (menu-bar-positive-p old-menu-bar-lines)
+	(accelerate-menu frame)
+      (letrec ((hide (lambda ()
+		       (remove-hook 'deactivate-menubar-hook hide)
+		       (when (or (frame-live-p old-frame)
+				 ;; Handle the case that if menu-bar-mode is
+				 ;; turned on/off with choosing a menu item for controling the mode.
+				 (or (eq old-menu-bar-mode menu-bar-mode)
+				     (not menu-bar-mode)))
+			 (set-frame-parameter old-frame 
+					      'menu-bar-lines old-menu-bar-lines)))))
+	(set-frame-parameter old-frame 'menu-bar-lines 1)
+	(prog1
+	    (accelerate-menu frame)
+	  (add-hook 'deactivate-menubar-hook hide))))))
+
 (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 `menu-bar-mode' is on or `x-menu-bar-temorary-visibility' is non-nil, otherwise call `tmm-menubar'."
   (interactive "i")
-  (if (and menu-bar-mode
-	   (fboundp 'accelerate-menu))
-      (accelerate-menu frame)
+  (if (fboundp 'accelerate-menu)
+      (cond
+       (x-menu-bar-temorary-visibility
+	(x-accelerate-menu-with-temporary-visible-menu-bar frame))
+       (menu-bar-mode
+	(accelerate-menu frame))
+       (t
+	(tmm-menubar)))
     (tmm-menubar)))
 
 \f

=== modified file 'src/keyboard.c'
--- src/keyboard.c	2012-06-25 10:28:47 +0000
+++ src/keyboard.c	2012-06-25 12:37:36 +0000
@@ -257,6 +257,7 @@
 static Lisp_Object Qdeactivate_mark;
 
 Lisp_Object Qrecompute_lucid_menubar, Qactivate_menubar_hook;
+Lisp_Object Qdeactivate_menubar_hook;
 
 static Lisp_Object Qecho_area_clear_hook;
 
@@ -11527,6 +11528,7 @@
 
   DEFSYM (Qrecompute_lucid_menubar, "recompute-lucid-menubar");
   DEFSYM (Qactivate_menubar_hook, "activate-menubar-hook");
+  DEFSYM (Qdeactivate_menubar_hook, "deactivate-menubar-hook");
 
   DEFSYM (Qpolling_period, "polling-period");
 

=== modified file 'src/keyboard.h'
--- src/keyboard.h	2012-02-10 18:58:48 +0000
+++ src/keyboard.h	2012-06-19 17:08:30 +0000
@@ -212,6 +212,7 @@
 extern Lisp_Object internal_last_event_frame;
 \f
 extern Lisp_Object Qrecompute_lucid_menubar, Qactivate_menubar_hook;
+extern Lisp_Object Qdeactivate_menubar_hook;
 
 /* This holds a Lisp vector that holds the properties of a single
    menu item while decoding it in parse_menu_item.

=== modified file 'src/xmenu.c'
--- src/xmenu.c	2012-06-25 04:05:48 +0000
+++ src/xmenu.c	2012-06-25 12:37:36 +0000
@@ -684,12 +684,14 @@
 static void
 popup_deactivate_callback (GtkWidget *widget, gpointer client_data)
 {
+  safe_run_hooks (Qdeactivate_menubar_hook);
   popup_activated_flag = 0;
 }
 #else
 static void
 popup_deactivate_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
 {
+  safe_run_hooks (Qdeactivate_menubar_hook);
   popup_activated_flag = 0;
 }
 #endif




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [patch v3] showing menu bar temporarily when f10 is pressed
  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
  0 siblings, 1 reply; 18+ messages in thread
From: Stefan Monnier @ 2012-07-19  6:54 UTC (permalink / raw)
  To: Masatake YAMATO; +Cc: emacs-devel

>>> Why do you need the menu-bar?  Why not pop up the menu usually bound to
>>> C-mouse-3?
>> To be honest, I didn't know that.
>> I've just tried C-mouse-3; and found some advantages of C-mouse-3
>> comparing with f10 for KEYBOARD USER.

While I agree we should also support the f10 behavior (so your current
patch is acceptable), I think the problem you point out for the
C-mouse-3 behavior could/should be fixed.

>> 1. With C-mouse-3, the menu is pop up where mouse pointer is.

That should be easy to fix so that the menu is popped up at point.

>> 2. With C-mouse-3, the contents of menu is chosen based
>> on the window where the mouse pointer is.

Same here.

Some comments on your code:

> +(defcustom x-menu-bar-temorary-visibility t
> +  "Control whether use menu bar or `tmm-menubar' when `x-menu-bar-open' is invoked.
> +Non-nil means showing menu bar temporarily even if `menu-bar-mode' is turned off.
> +If nil, the behavior is changed whether `menu-bar-mode' is on or off. See `x-menu-bar-open'
> +for more detail."
> +  :type 'boolean
> +  :group 'x
> +  :version "24.2")

Please stay within 80 columns and use two spaces to separate sentences.

> +(defun x-accelerate-menu-with-temporary-visible-menu-bar (frame)

Please only use "x-" for functions that are specific to X11.

> +		       (when (or (frame-live-p old-frame)
> +				 ;; Handle the case that if menu-bar-mode is
> +				 ;; turned on/off with choosing a menu item for controling the mode.
> +				 (or (eq old-menu-bar-mode menu-bar-mode)
> +				     (not menu-bar-mode)))

I don't understand this condition:
- shouldn't the outer `or' be an `and'?
- why check (not menu-bar-mode)?

> +	(prog1
> +	    (accelerate-menu frame)
> +	  (add-hook 'deactivate-menubar-hook hide))))))

Why put the add-hook after rather than before calling accelerate-menu?
If it can't come before, then the prog1 needs to be replaced by an
unwind-protect in case accelerate-menu signals an error.

>  (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 `menu-bar-mode' is on or `x-menu-bar-temorary-visibility' is non-nil, otherwise call `tmm-menubar'."

This docstring's first line is too long.  It has to be less than 80
columns and it has to "stand on its own" (you can't just line-wrap it)
since modes like apropos will only display the first line.

>    (interactive "i")
> -  (if (and menu-bar-mode
> -	   (fboundp 'accelerate-menu))
> -      (accelerate-menu frame)
> +  (if (fboundp 'accelerate-menu)
> +      (cond
> +       (x-menu-bar-temorary-visibility
> +	(x-accelerate-menu-with-temporary-visible-menu-bar frame))
> +       (menu-bar-mode
> +	(accelerate-menu frame))

To be on the safer side, I recommend you only use
x-accelerate-menu-with-temporary-visible-menu-bar when accelerate-menu
won't work (e.g. when menu-bar-mode is nil).

>  popup_deactivate_callback (GtkWidget *widget, gpointer client_data)
>  {
> +  safe_run_hooks (Qdeactivate_menubar_hook);
>    popup_activated_flag = 0;
>  }

Could someone more knowledgeable tell me if this is safe?
I.e. is popup_deactivate_callback called asynchronously (e.g. from
a separate thread or from a signal handler)?
If not, then we'll need to delay running deactivate-menubar-hook to
a safe moment (maybe export popup_activated_flag to Lisp and then use
a pre/post-command-hook that checks this var before running
deactivate-menubar-hook).


        Stefan



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Where the menu should be appeared when C-mouse-3 is triggered (Was: [patch v3] showing menu bar temporarily when f10 is pressed)
  2012-07-19  6:54       ` Stefan Monnier
@ 2012-07-19  8:32         ` Masatake YAMATO
  2012-07-19  9:07           ` Where the menu should be appeared when C-mouse-3 is triggered Stefan Monnier
  0 siblings, 1 reply; 18+ messages in thread
From: Masatake YAMATO @ 2012-07-19  8:32 UTC (permalink / raw)
  To: monnier; +Cc: emacs-devel

Thank you for reviewing.
I'll revise my patch and submit it again.

>>>> Why do you need the menu-bar?  Why not pop up the menu usually bound to
>>>> C-mouse-3?
>>> To be honest, I didn't know that.
>>> I've just tried C-mouse-3; and found some advantages of C-mouse-3
>>> comparing with f10 for KEYBOARD USER.
> 
> While I agree we should also support the f10 behavior (so your current
> patch is acceptable), I think the problem you point out for the
> C-mouse-3 behavior could/should be fixed.
> 
>>> 1. With C-mouse-3, the menu is pop up where mouse pointer is.
> 
> That should be easy to fix so that the menu is popped up at point.
> 
>>> 2. With C-mouse-3, the contents of menu is chosen based
>>> on the window where the mouse pointer is.
> 
> Same here.

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.

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.

I've been thinking about this gap between mouse operation and keyboard
operation in emacs. 

I'd like to introduce `bring-mouse-to-point' for fill the gap.  Its
behavior is too tricky, so I'd like to introduce is after f10 patch is
accepted. The behavior of f10 patch is a bit tricky.

`bring-mouse-to-point' is for for keyboard user, who don't want to 
use mouse but want to use mouse oriented commands from key board.

As the name shown, `bring-mouse-to-point' moves the mouse cursor to
the point.  So you can do what Stefan suggests with following 
key sequence:

    \C-. C-mouse-3

(Here I bind \C-. to `bring-mouse-to-point' privately. I know \C-. is
reserved to user customization.)

If you are using note-PC, this is enough useful because mouse-[123]
are near keyboard. 

After invoking \C-. C-mouse-3, you can type \C-. again. In that case
the mouse cursor moves somewhere far away from point; 
mouse-avoidance-banish is called. It means the behavior or \C-. is 
toggle.

How do you think `bring-mouse-to-point'?
I hope this is included to emacs officially.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Taken from avoid.el
;;
(require 'avoid)
(defun point-position ()
  (let ((edges (window-inside-edges))
	(x-y (posn-x-y (posn-at-point))))
    (cons (selected-frame)
	  (cons (+ (car edges)
		   (/ (car x-y) (frame-char-width)))
		(+ (car (cdr edges))
		   (/ (cdr x-y) (frame-char-height)))))))

(defun bring-mouse-to-point (avoiding)
  (interactive "P")
  (let ((op (mouse-position))
	(np (point-position)))
    (if (or avoiding
	    (equal op np))
	(mouse-avoidance-banish)
      (set-mouse-position (car np) (cadr np) (cddr np)))))
(define-key global-map [(control .)] 'bring-mouse-to-point)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


Masatake YAMATO



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Where the menu should be appeared when C-mouse-3 is triggered
  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           ` Stefan Monnier
  2012-07-20  4:55             ` Masatake YAMATO
  0 siblings, 1 reply; 18+ messages in thread
From: Stefan Monnier @ 2012-07-19  9:07 UTC (permalink / raw)
  To: Masatake YAMATO; +Cc: emacs-devel

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

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

> I'd like to introduce `bring-mouse-to-point' for fill the gap.
> How do you think `bring-mouse-to-point'?

I think that moving the mouse is *evil*.

> I hope this is included to Emacs officially.

I'm not sure it's of wide appeal, but I don't expect users to write code
like the one you quoted, so there should be an easier way to do it.
E.g. a function which translates the window-relative coordinates of
a `posn' into frame- or display-relative coordinates.


        Stefan



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Where the menu should be appeared when C-mouse-3 is triggered
  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
  2012-07-20 11:38               ` Stefan Monnier
  0 siblings, 1 reply; 18+ messages in thread
From: Masatake YAMATO @ 2012-07-20  4:55 UTC (permalink / raw)
  To: monnier; +Cc: emacs-devel

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.




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Where the menu should be appeared when C-mouse-3 is triggered
  2012-07-20  4:55             ` Masatake YAMATO
@ 2012-07-20 11:38               ` Stefan Monnier
  2012-07-20 11:56                 ` Masatake YAMATO
  2012-07-20 12:48                 ` Masatake YAMATO
  0 siblings, 2 replies; 18+ messages in thread
From: Stefan Monnier @ 2012-07-20 11:38 UTC (permalink / raw)
  To: Masatake YAMATO; +Cc: emacs-devel

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

Sounds good.  Installed (except I removed point-pixel-position).

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

Maybe a better direction is to make popup-menu (and x-popup-menu, ...)
accept posn arguments, so you can just use things like (event-end
<event>) or (posn-at-point) to specify where to display it.  The
docstring of popup-menu seems to indicate that an `event' can be used,
but at least in my tests it doesn't seem to work.

Could you look at making a patch to do that (i.e. accept a posn,
or maybe an event)?


        Stefan



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Where the menu should be appeared when C-mouse-3 is triggered
  2012-07-20 11:38               ` Stefan Monnier
@ 2012-07-20 11:56                 ` Masatake YAMATO
  2012-07-28  9:31                   ` Masatake YAMATO
  2012-07-20 12:48                 ` Masatake YAMATO
  1 sibling, 1 reply; 18+ messages in thread
From: Masatake YAMATO @ 2012-07-20 11:56 UTC (permalink / raw)
  To: monnier; +Cc: emacs-devel

Hi,
>> 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.
> 
> Sounds good.  Installed (except I removed point-pixel-position).

Thanks.
 
>> 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'.
> 
> Maybe a better direction is to make popup-menu (and x-popup-menu, ...)
> accept posn arguments, so you can just use things like (event-end
> <event>) or (posn-at-point) to specify where to display it.  The
> docstring of popup-menu seems to indicate that an `event' can be used,
> but at least in my tests it doesn't seem to work.
> 
> Could you look at making a patch to do that (i.e. accept a posn,
> or maybe an event)?

Sure. I'll continue to hack this area.
 
> 
>         Stefan
> 

Masatake YAMATO



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Where the menu should be appeared when C-mouse-3 is triggered
  2012-07-20 11:38               ` Stefan Monnier
  2012-07-20 11:56                 ` Masatake YAMATO
@ 2012-07-20 12:48                 ` Masatake YAMATO
  1 sibling, 0 replies; 18+ messages in thread
From: Masatake YAMATO @ 2012-07-20 12:48 UTC (permalink / raw)
  To: monnier; +Cc: emacs-devel

>> 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.
> 
> Sounds good.  Installed (except I removed point-pixel-position).

It seems that removing point-pixel-position in wrong way.
Following patch is needed.

=== modified file 'lisp/mouse.el'
*** lisp/mouse.el	2012-07-20 11:32:30 +0000
--- lisp/mouse.el	2012-07-20 12:46:34 +0000
***************
*** 116,122 ****
    (setq position
  	(cond
  	 ((eq position 'point)
! 	  (let* ((pp (posn-at-point pos window))
                   (xy (posn-x-y pp)))
  	    (list (list (car xy) (cdr xy)) (posn-window pp))))
  	 ((not position)
--- 116,122 ----
    (setq position
  	(cond
  	 ((eq position 'point)
! 	  (let* ((pp (posn-at-point))
                   (xy (posn-x-y pp)))
  	    (list (list (car xy) (cdr xy)) (posn-window pp))))
  	 ((not position)




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Where the menu should be appeared when C-mouse-3 is triggered
  2012-07-20 11:56                 ` Masatake YAMATO
@ 2012-07-28  9:31                   ` Masatake YAMATO
  2012-08-09 11:13                     ` Masatake YAMATO
  0 siblings, 1 reply; 18+ messages in thread
From: Masatake YAMATO @ 2012-07-28  9:31 UTC (permalink / raw)
  To: monnier; +Cc: emacs-devel

Hi,

About POSITION argument of popup-menu you suggested:

> Maybe a better direction is to make popup-menu (and x-popup-menu, ...)
> accept posn arguments, so you can just use things like (event-end
> <event>) or (posn-at-point) to specify where to display it.  The
> docstring of popup-menu seems to indicate that an `event' can be used,
> but at least in my tests it doesn't seem to work.
> 
> Could you look at making a patch to do that (i.e. accept a posn,
> or maybe an event)?

I've revised the POSITION argument handling.
Now `popup-menu-normalize-position' handles all POSITION variants.
I have not touch `x-popup-menu' yet.

Masatake YAMATO

=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2012-07-27 16:42:19 +0000
+++ lisp/ChangeLog	2012-07-28 09:16:29 +0000
@@ -1,3 +1,13 @@
+2012-07-28  Masatake YAMATO  <yamato@redhat.com>
+
+	* mouse.el (popup-menu-normalize-position): New function.
+	(popup-menu): Use `popup-menu-normalize-position' to normalize
+	the form for POSITION argument.
+
+	* term/x-win.el (x-menu-bar-open): Use
+	the value returend from (posn-at-point) as position
+	passed to `popup-menu'.
+
 2012-07-27  Fabián Ezequiel Gallina  <fgallina@cuca>
 
 	Consistent completion in inferior python with emacs -nw.

=== modified file 'lisp/mouse.el'
--- lisp/mouse.el	2012-07-26 08:32:25 +0000
+++ lisp/mouse.el	2012-07-28 09:18:46 +0000
@@ -101,11 +101,8 @@
   "Popup the given menu and call the selected option.
 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.  If POSITION is the
-symbol `point', the current point position is used.
-
+The menu is shown at the place where POSITION specifies. About
+the form of POSITION, see `popup-menu-normalize-position'.
 PREFIX is the prefix argument (if any) to pass to the command."
   (let* ((map (cond
 	       ((keymapp menu) menu)
@@ -114,18 +111,8 @@
 			 (filter (when (symbolp map)
 				   (plist-get (get map 'menu-prop) :filter))))
 		    (if filter (funcall filter (symbol-function map)) map)))))
-	 event cmd)
-    (setq position
-	  (cond
-	   ((eq position 'point)
-	    (let* ((pp (posn-at-point))
-		   (xy (posn-x-y pp)))
-	      (list (list (car xy) (cdr xy)) (posn-window pp))))
-	   ((not position)
-	    (let ((mp (mouse-pixel-position)))
-	      (list (list (cadr mp) (cddr mp)) (car mp))))
-	   (t
-	    position)))
+	 event cmd
+	 (position (popup-menu-normalize-position 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
@@ -163,6 +150,37 @@
       ;; mouse-major-mode-menu was using `command-execute' instead.
       (call-interactively cmd))))
 
+(defun popup-menu-normalize-position (position)
+  "Converts the POSITION to the form which `popup-menu' expects internally.
+POSITION can be nil, an click event, a posn- value, or a value having
+form ((XOFFSET YOFFSET) WINDOW).
+If nil, the current mouse position is used.
+If an click event, the value returend from `event-end' is used."
+  (pcase position
+    ;; nil -> mouse cursor position
+    ;; this pattern must be before `eventp' because
+    ;; nil is an event.
+    (`nil
+     (let ((mp (mouse-pixel-position)))
+       (list (list (cadr mp) (cddr mp)) (car mp))))
+    ;; value returned from (event-end (read-event)) or (posn-at-point)
+    ((or `(,window ,area-or-pos (,x . ,y)
+		   ,timestamp ,object ,pos (,col . ,row)
+		   ,image (,dx . ,dy) (,width . ,height))
+	 `(,window ,pos (0 . 0) 0))
+     (let ((xy (posn-x-y position)))
+       (list (list (car xy) (cdr xy))
+	     (posn-window position))))
+    ;; pattern expected by popup-menu
+    (`((,xoffset ,yoffset) ,window)
+     position)
+    ;; event
+    ((pred eventp)
+     (popup-menu-normalize-position (event-end position)))
+    ;; rejects
+    (t
+     (error "Unexpected position form"))))
+
 (defun minor-mode-menu-from-indicator (indicator)
   "Show menu for minor mode specified by INDICATOR.
 Interactively, INDICATOR is read using completion.

=== modified file 'lisp/term/x-win.el'
--- lisp/term/x-win.el	2012-07-20 11:32:30 +0000
+++ lisp/term/x-win.el	2012-07-28 05:08:48 +0000
@@ -1316,7 +1316,7 @@
     (popup-menu (mouse-menu-bar-map)
 		(if (listp last-nonmenu-event)
 		    nil
-		  'point)))))
+		  (posn-at-point))))))
 
 \f
 ;;; Window system initialization.




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Where the menu should be appeared when C-mouse-3 is triggered
  2012-07-28  9:31                   ` Masatake YAMATO
@ 2012-08-09 11:13                     ` Masatake YAMATO
  2012-08-10 12:44                       ` Stefan Monnier
  0 siblings, 1 reply; 18+ messages in thread
From: Masatake YAMATO @ 2012-08-09 11:13 UTC (permalink / raw)
  To: monnier; +Cc: emacs-devel

Hi, could you review this patch?

http://lists.gnu.org/archive/html/emacs-devel/2012-07/msg00602.html
-------------------------------------------------------------------------
Hi,

About POSITION argument of popup-menu you suggested:

> Maybe a better direction is to make popup-menu (and x-popup-menu, ...)
> accept posn arguments, so you can just use things like (event-end
> <event>) or (posn-at-point) to specify where to display it.  The
> docstring of popup-menu seems to indicate that an `event' can be used,
> but at least in my tests it doesn't seem to work.
> 
> Could you look at making a patch to do that (i.e. accept a posn,
> or maybe an event)?

I've revised the POSITION argument handling.
Now `popup-menu-normalize-position' handles all POSITION variants.
I have not touch `x-popup-menu' yet.

Masatake YAMATO

=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2012-07-27 16:42:19 +0000
+++ lisp/ChangeLog	2012-07-28 09:16:29 +0000
@@ -1,3 +1,13 @@
+2012-07-28  Masatake YAMATO  <yamato@redhat.com>
+
+	* mouse.el (popup-menu-normalize-position): New function.
+	(popup-menu): Use `popup-menu-normalize-position' to normalize
+	the form for POSITION argument.
+
+	* term/x-win.el (x-menu-bar-open): Use
+	the value returend from (posn-at-point) as position
+	passed to `popup-menu'.
+
 2012-07-27  Fabián Ezequiel Gallina  <fgallina@cuca>
 
 	Consistent completion in inferior python with emacs -nw.

=== modified file 'lisp/mouse.el'
--- lisp/mouse.el	2012-07-26 08:32:25 +0000
+++ lisp/mouse.el	2012-07-28 09:18:46 +0000
@@ -101,11 +101,8 @@
   "Popup the given menu and call the selected option.
 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.  If POSITION is the
-symbol `point', the current point position is used.
-
+The menu is shown at the place where POSITION specifies. About
+the form of POSITION, see `popup-menu-normalize-position'.
 PREFIX is the prefix argument (if any) to pass to the command."
   (let* ((map (cond
 	       ((keymapp menu) menu)
@@ -114,18 +111,8 @@
 			 (filter (when (symbolp map)
 				   (plist-get (get map 'menu-prop) :filter))))
 		    (if filter (funcall filter (symbol-function map)) map)))))
-	 event cmd)
-    (setq position
-	  (cond
-	   ((eq position 'point)
-	    (let* ((pp (posn-at-point))
-		   (xy (posn-x-y pp)))
-	      (list (list (car xy) (cdr xy)) (posn-window pp))))
-	   ((not position)
-	    (let ((mp (mouse-pixel-position)))
-	      (list (list (cadr mp) (cddr mp)) (car mp))))
-	   (t
-	    position)))
+	 event cmd
+	 (position (popup-menu-normalize-position 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
@@ -163,6 +150,37 @@
       ;; mouse-major-mode-menu was using `command-execute' instead.
       (call-interactively cmd))))
 
+(defun popup-menu-normalize-position (position)
+  "Converts the POSITION to the form which `popup-menu' expects internally.
+POSITION can be nil, an click event, a posn- value, or a value having
+form ((XOFFSET YOFFSET) WINDOW).
+If nil, the current mouse position is used.
+If an click event, the value returend from `event-end' is used."
+  (pcase position
+    ;; nil -> mouse cursor position
+    ;; this pattern must be before `eventp' because
+    ;; nil is an event.
+    (`nil
+     (let ((mp (mouse-pixel-position)))
+       (list (list (cadr mp) (cddr mp)) (car mp))))
+    ;; value returned from (event-end (read-event)) or (posn-at-point)
+    ((or `(,window ,area-or-pos (,x . ,y)
+		   ,timestamp ,object ,pos (,col . ,row)
+		   ,image (,dx . ,dy) (,width . ,height))
+	 `(,window ,pos (0 . 0) 0))
+     (let ((xy (posn-x-y position)))
+       (list (list (car xy) (cdr xy))
+	     (posn-window position))))
+    ;; pattern expected by popup-menu
+    (`((,xoffset ,yoffset) ,window)
+     position)
+    ;; event
+    ((pred eventp)
+     (popup-menu-normalize-position (event-end position)))
+    ;; rejects
+    (t
+     (error "Unexpected position form"))))
+
 (defun minor-mode-menu-from-indicator (indicator)
   "Show menu for minor mode specified by INDICATOR.
 Interactively, INDICATOR is read using completion.

=== modified file 'lisp/term/x-win.el'
--- lisp/term/x-win.el	2012-07-20 11:32:30 +0000
+++ lisp/term/x-win.el	2012-07-28 05:08:48 +0000
@@ -1316,7 +1316,7 @@
     (popup-menu (mouse-menu-bar-map)
 		(if (listp last-nonmenu-event)
 		    nil
-		  'point)))))
+		  (posn-at-point))))))
 
 \f
 ;;; Window system initialization.





^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Where the menu should be appeared when C-mouse-3 is triggered
  2012-08-09 11:13                     ` Masatake YAMATO
@ 2012-08-10 12:44                       ` Stefan Monnier
  2012-08-10 13:21                         ` Drew Adams
                                           ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Stefan Monnier @ 2012-08-10 12:44 UTC (permalink / raw)
  To: Masatake YAMATO; +Cc: emacs-devel

> Hi, could you review this patch?

Yes, sorry for the delay.  Installed,


        Stefan


> http://lists.gnu.org/archive/html/emacs-devel/2012-07/msg00602.html
> -------------------------------------------------------------------------
> Hi,

> About POSITION argument of popup-menu you suggested:

>> Maybe a better direction is to make popup-menu (and x-popup-menu, ...)
>> accept posn arguments, so you can just use things like (event-end
>> <event>) or (posn-at-point) to specify where to display it.  The
>> docstring of popup-menu seems to indicate that an `event' can be used,
>> but at least in my tests it doesn't seem to work.
>> 
>> Could you look at making a patch to do that (i.e. accept a posn,
>> or maybe an event)?

> I've revised the POSITION argument handling.
> Now `popup-menu-normalize-position' handles all POSITION variants.
> I have not touch `x-popup-menu' yet.

> Masatake YAMATO

> === modified file 'lisp/ChangeLog'
> --- lisp/ChangeLog	2012-07-27 16:42:19 +0000
> +++ lisp/ChangeLog	2012-07-28 09:16:29 +0000
> @@ -1,3 +1,13 @@
> +2012-07-28  Masatake YAMATO  <yamato@redhat.com>
> +
> +	* mouse.el (popup-menu-normalize-position): New function.
> +	(popup-menu): Use `popup-menu-normalize-position' to normalize
> +	the form for POSITION argument.
> +
> +	* term/x-win.el (x-menu-bar-open): Use
> +	the value returend from (posn-at-point) as position
> +	passed to `popup-menu'.
> +
>  2012-07-27  Fabián Ezequiel Gallina  <fgallina@cuca>
 
>  	Consistent completion in inferior python with emacs -nw.

> === modified file 'lisp/mouse.el'
> --- lisp/mouse.el	2012-07-26 08:32:25 +0000
> +++ lisp/mouse.el	2012-07-28 09:18:46 +0000
> @@ -101,11 +101,8 @@
>    "Popup the given menu and call the selected option.
>  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.  If POSITION is the
> -symbol `point', the current point position is used.
> -
> +The menu is shown at the place where POSITION specifies. About
> +the form of POSITION, see `popup-menu-normalize-position'.
>  PREFIX is the prefix argument (if any) to pass to the command."
>    (let* ((map (cond
>  	       ((keymapp menu) menu)
> @@ -114,18 +111,8 @@
>  			 (filter (when (symbolp map)
>  				   (plist-get (get map 'menu-prop) :filter))))
>  		    (if filter (funcall filter (symbol-function map)) map)))))
> -	 event cmd)
> -    (setq position
> -	  (cond
> -	   ((eq position 'point)
> -	    (let* ((pp (posn-at-point))
> -		   (xy (posn-x-y pp)))
> -	      (list (list (car xy) (cdr xy)) (posn-window pp))))
> -	   ((not position)
> -	    (let ((mp (mouse-pixel-position)))
> -	      (list (list (cadr mp) (cddr mp)) (car mp))))
> -	   (t
> -	    position)))
> +	 event cmd
> +	 (position (popup-menu-normalize-position 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
> @@ -163,6 +150,37 @@
>        ;; mouse-major-mode-menu was using `command-execute' instead.
>        (call-interactively cmd))))
 
> +(defun popup-menu-normalize-position (position)
> +  "Converts the POSITION to the form which `popup-menu' expects internally.
> +POSITION can be nil, an click event, a posn- value, or a value having
> +form ((XOFFSET YOFFSET) WINDOW).
> +If nil, the current mouse position is used.
> +If an click event, the value returend from `event-end' is used."
> +  (pcase position
> +    ;; nil -> mouse cursor position
> +    ;; this pattern must be before `eventp' because
> +    ;; nil is an event.
> +    (`nil
> +     (let ((mp (mouse-pixel-position)))
> +       (list (list (cadr mp) (cddr mp)) (car mp))))
> +    ;; value returned from (event-end (read-event)) or (posn-at-point)
> +    ((or `(,window ,area-or-pos (,x . ,y)
> +		   ,timestamp ,object ,pos (,col . ,row)
> +		   ,image (,dx . ,dy) (,width . ,height))
> +	 `(,window ,pos (0 . 0) 0))
> +     (let ((xy (posn-x-y position)))
> +       (list (list (car xy) (cdr xy))
> +	     (posn-window position))))
> +    ;; pattern expected by popup-menu
> +    (`((,xoffset ,yoffset) ,window)
> +     position)
> +    ;; event
> +    ((pred eventp)
> +     (popup-menu-normalize-position (event-end position)))
> +    ;; rejects
> +    (t
> +     (error "Unexpected position form"))))
> +
>  (defun minor-mode-menu-from-indicator (indicator)
>    "Show menu for minor mode specified by INDICATOR.
>  Interactively, INDICATOR is read using completion.

> === modified file 'lisp/term/x-win.el'
> --- lisp/term/x-win.el	2012-07-20 11:32:30 +0000
> +++ lisp/term/x-win.el	2012-07-28 05:08:48 +0000
> @@ -1316,7 +1316,7 @@
>      (popup-menu (mouse-menu-bar-map)
>  		(if (listp last-nonmenu-event)
>  		    nil
> -		  'point)))))
> +		  (posn-at-point))))))
 
>  \f
>  ;;; Window system initialization.





^ permalink raw reply	[flat|nested] 18+ messages in thread

* RE: Where the menu should be appeared when C-mouse-3 is triggered
  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
  2 siblings, 0 replies; 18+ messages in thread
From: Drew Adams @ 2012-08-10 13:21 UTC (permalink / raw)
  To: 'Stefan Monnier', 'Masatake YAMATO'; +Cc: emacs-devel

> Yes, sorry for the delay.  Installed,

NEWS too?




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Where the menu should be appeared when C-mouse-3 is triggered
  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
  2 siblings, 0 replies; 18+ messages in thread
From: Masatake YAMATO @ 2012-08-10 13:52 UTC (permalink / raw)
  To: monnier; +Cc: emacs-devel

Thanks.

>> Hi, could you review this patch?
> 
> Yes, sorry for the delay.  Installed,
> 
> 
>         Stefan
> 
> 
>> http://lists.gnu.org/archive/html/emacs-devel/2012-07/msg00602.html
>> -------------------------------------------------------------------------
>> Hi,
> 
>> About POSITION argument of popup-menu you suggested:
> 
>>> Maybe a better direction is to make popup-menu (and x-popup-menu, ...)
>>> accept posn arguments, so you can just use things like (event-end
>>> <event>) or (posn-at-point) to specify where to display it.  The
>>> docstring of popup-menu seems to indicate that an `event' can be used,
>>> but at least in my tests it doesn't seem to work.
>>> 
>>> Could you look at making a patch to do that (i.e. accept a posn,
>>> or maybe an event)?
> 
>> I've revised the POSITION argument handling.
>> Now `popup-menu-normalize-position' handles all POSITION variants.
>> I have not touch `x-popup-menu' yet.
> 
>> Masatake YAMATO
> 
>> === modified file 'lisp/ChangeLog'
>> --- lisp/ChangeLog	2012-07-27 16:42:19 +0000
>> +++ lisp/ChangeLog	2012-07-28 09:16:29 +0000
>> @@ -1,3 +1,13 @@
>> +2012-07-28  Masatake YAMATO  <yamato@redhat.com>
>> +
>> +	* mouse.el (popup-menu-normalize-position): New function.
>> +	(popup-menu): Use `popup-menu-normalize-position' to normalize
>> +	the form for POSITION argument.
>> +
>> +	* term/x-win.el (x-menu-bar-open): Use
>> +	the value returend from (posn-at-point) as position
>> +	passed to `popup-menu'.
>> +
>>  2012-07-27  Fabián Ezequiel Gallina  <fgallina@cuca>
>  
>>  	Consistent completion in inferior python with emacs -nw.
> 
>> === modified file 'lisp/mouse.el'
>> --- lisp/mouse.el	2012-07-26 08:32:25 +0000
>> +++ lisp/mouse.el	2012-07-28 09:18:46 +0000
>> @@ -101,11 +101,8 @@
>>    "Popup the given menu and call the selected option.
>>  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.  If POSITION is the
>> -symbol `point', the current point position is used.
>> -
>> +The menu is shown at the place where POSITION specifies. About
>> +the form of POSITION, see `popup-menu-normalize-position'.
>>  PREFIX is the prefix argument (if any) to pass to the command."
>>    (let* ((map (cond
>>  	       ((keymapp menu) menu)
>> @@ -114,18 +111,8 @@
>>  			 (filter (when (symbolp map)
>>  				   (plist-get (get map 'menu-prop) :filter))))
>>  		    (if filter (funcall filter (symbol-function map)) map)))))
>> -	 event cmd)
>> -    (setq position
>> -	  (cond
>> -	   ((eq position 'point)
>> -	    (let* ((pp (posn-at-point))
>> -		   (xy (posn-x-y pp)))
>> -	      (list (list (car xy) (cdr xy)) (posn-window pp))))
>> -	   ((not position)
>> -	    (let ((mp (mouse-pixel-position)))
>> -	      (list (list (cadr mp) (cddr mp)) (car mp))))
>> -	   (t
>> -	    position)))
>> +	 event cmd
>> +	 (position (popup-menu-normalize-position 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
>> @@ -163,6 +150,37 @@
>>        ;; mouse-major-mode-menu was using `command-execute' instead.
>>        (call-interactively cmd))))
>  
>> +(defun popup-menu-normalize-position (position)
>> +  "Converts the POSITION to the form which `popup-menu' expects internally.
>> +POSITION can be nil, an click event, a posn- value, or a value having
>> +form ((XOFFSET YOFFSET) WINDOW).
>> +If nil, the current mouse position is used.
>> +If an click event, the value returend from `event-end' is used."
>> +  (pcase position
>> +    ;; nil -> mouse cursor position
>> +    ;; this pattern must be before `eventp' because
>> +    ;; nil is an event.
>> +    (`nil
>> +     (let ((mp (mouse-pixel-position)))
>> +       (list (list (cadr mp) (cddr mp)) (car mp))))
>> +    ;; value returned from (event-end (read-event)) or (posn-at-point)
>> +    ((or `(,window ,area-or-pos (,x . ,y)
>> +		   ,timestamp ,object ,pos (,col . ,row)
>> +		   ,image (,dx . ,dy) (,width . ,height))
>> +	 `(,window ,pos (0 . 0) 0))
>> +     (let ((xy (posn-x-y position)))
>> +       (list (list (car xy) (cdr xy))
>> +	     (posn-window position))))
>> +    ;; pattern expected by popup-menu
>> +    (`((,xoffset ,yoffset) ,window)
>> +     position)
>> +    ;; event
>> +    ((pred eventp)
>> +     (popup-menu-normalize-position (event-end position)))
>> +    ;; rejects
>> +    (t
>> +     (error "Unexpected position form"))))
>> +
>>  (defun minor-mode-menu-from-indicator (indicator)
>>    "Show menu for minor mode specified by INDICATOR.
>>  Interactively, INDICATOR is read using completion.
> 
>> === modified file 'lisp/term/x-win.el'
>> --- lisp/term/x-win.el	2012-07-20 11:32:30 +0000
>> +++ lisp/term/x-win.el	2012-07-28 05:08:48 +0000
>> @@ -1316,7 +1316,7 @@
>>      (popup-menu (mouse-menu-bar-map)
>>  		(if (listp last-nonmenu-event)
>>  		    nil
>> -		  'point)))))
>> +		  (posn-at-point))))))
>  
>>  \f
>>  ;;; Window system initialization.
> 
> 
> 



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Where the menu should be appeared when C-mouse-3 is triggered
  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
  2 siblings, 0 replies; 18+ messages in thread
From: Stefan Monnier @ 2012-08-10 14:47 UTC (permalink / raw)
  To: Masatake YAMATO; +Cc: emacs-devel

> Yes, sorry for the delay.  Installed,

Completed by the patch below.


        Stefan


=== modified file 'etc/NEWS'
--- etc/NEWS	2012-08-08 16:17:15 +0000
+++ etc/NEWS	2012-08-10 14:30:53 +0000
@@ -556,6 +556,8 @@
 
 ** New functions `autoloadp' and `autoload-do-load'.
 
+** New function `posnp' to test if an object is a `posn'.
+
 ** `function-get' fetches the property of a function, following aliases.
 
 ** `toggle-read-only' accepts a second argument specifying whether to

=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2012-08-10 12:44:06 +0000
+++ lisp/ChangeLog	2012-08-10 14:46:13 +0000
@@ -1,3 +1,12 @@
+2012-08-10  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* term/x-win.el (x-menu-bar-open): Always pass last-nonmenu-event.
+	* subr.el (eventp): `nil' is not an event, and eventp is not hot.
+	(event-start, event-end): Use posn-at-point to return a more
+	informative posn.
+	(posnp): New function.
+	* mouse.el (popup-menu-normalize-position): Use it.
+
 2012-08-10  Masatake YAMATO  <yamato@redhat.com>
 
 	* mouse.el (popup-menu-normalize-position): New function.

=== modified file 'lisp/mouse.el'
--- lisp/mouse.el	2012-08-10 12:44:06 +0000
+++ lisp/mouse.el	2012-08-10 14:35:01 +0000
@@ -1,4 +1,4 @@
-;;; mouse.el --- window system-independent mouse support
+;;; mouse.el --- window system-independent mouse support  -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1993-1995, 1999-2012 Free Software Foundation, Inc.
 
@@ -151,35 +151,24 @@
       (call-interactively cmd))))
 
 (defun popup-menu-normalize-position (position)
-  "Converts the POSITION to the form which `popup-menu' expects internally.
-POSITION can be nil, an click event, a posn- value, or a value having
-form ((XOFFSET YOFFSET) WINDOW).
-If nil, the current mouse position is used.
-If an click event, the value returend from `event-end' is used."
+  "Convert the POSITION to the form which `popup-menu' expects internally.
+POSITION can an event, a posn- value, a value having
+form ((XOFFSET YOFFSET) WINDOW), or nil.
+If nil, the current mouse position is used."
   (pcase position
     ;; nil -> mouse cursor position
-    ;; this pattern must be before `eventp' because
-    ;; nil is an event.
     (`nil
      (let ((mp (mouse-pixel-position)))
        (list (list (cadr mp) (cddr mp)) (car mp))))
-    ;; value returned from (event-end (read-event)) or (posn-at-point)
-    ((or `(,window ,area-or-pos (,x . ,y)
-		   ,timestamp ,object ,pos (,col . ,row)
-		   ,image (,dx . ,dy) (,width . ,height))
-	 `(,window ,pos (0 . 0) 0))
+    ;; Value returned from `event-end' or `posn-at-point'.
+    ((pred posnp)
      (let ((xy (posn-x-y position)))
        (list (list (car xy) (cdr xy))
 	     (posn-window position))))
-    ;; pattern expected by popup-menu
-    (`((,xoffset ,yoffset) ,window)
-     position)
-    ;; event
+    ;; Event.
     ((pred eventp)
      (popup-menu-normalize-position (event-end position)))
-    ;; rejects
-    (t
-     (error "Unexpected position form"))))
+    (t position)))
 
 (defun minor-mode-menu-from-indicator (indicator)
   "Show menu for minor mode specified by INDICATOR.

=== modified file 'lisp/subr.el'
--- lisp/subr.el	2012-07-29 18:11:42 +0000
+++ lisp/subr.el	2012-08-10 14:45:19 +0000
@@ -907,11 +907,12 @@
 			  c)))
 	    key)))
 
-(defsubst eventp (obj)
+(defun eventp (obj)
   "True if the argument is an event object."
+  (when obj
   (or (integerp obj)
       (and (symbolp obj) obj (not (keywordp obj)))
-      (and (consp obj) (symbolp (car obj)))))
+        (and (consp obj) (symbolp (car obj))))))
 
 (defun event-modifiers (event)
   "Return a list of symbols representing the modifier keys in event EVENT.
@@ -975,7 +976,7 @@
   ;; is this really correct? maybe remove mouse-movement?
   (memq (event-basic-type object) '(mouse-1 mouse-2 mouse-3 mouse-movement)))
 
-(defsubst event-start (event)
+(defun event-start (event)
   "Return the starting position of EVENT.
 EVENT should be a click, drag, or key press event.
 If it is a key press event, the return value has the form
@@ -990,9 +991,10 @@
 position of the event.  If EVENT is a drag, this is the starting
 position of the drag."
   (if (consp event) (nth 1 event)
-    (list (selected-window) (point) '(0 . 0) 0)))
+    (or (posn-at-point)
+        (list (selected-window) (point) '(0 . 0) 0))))
 
-(defsubst event-end (event)
+(defun event-end (event)
   "Return the ending location of EVENT.
 EVENT should be a click, drag, or key press event.
 If EVENT is a key press event, the return value has the form
@@ -1009,7 +1011,8 @@
 position of the event.  If EVENT is a drag, this is the starting
 position of the drag."
   (if (consp event) (nth (if (consp (nth 2 event)) 2 1) event)
-    (list (selected-window) (point) '(0 . 0) 0)))
+    (or (posn-at-point)
+        (list (selected-window) (point) '(0 . 0) 0))))
 
 (defsubst event-click-count (event)
   "Return the multi-click count of EVENT, a click or drag event.
@@ -1018,6 +1021,13 @@
 \f
 ;;;; Extracting fields of the positions in an event.
 
+(defun posnp (obj)
+  "Return non-nil if OBJ appears to be a valid `posn' object."
+  (and (windowp (car-safe obj))
+       (atom (car-safe (setq obj (cdr obj))))                ;AREA-OR-POS.
+       (integerp (car-safe (car-safe (setq obj (cdr obj))))) ;XOFFSET.
+       (integerp (car-safe (cdr obj)))))                     ;TIMESTAMP.
+
 (defsubst posn-window (position)
   "Return the window in POSITION.
 POSITION should be a list of the form returned by the `event-start'

=== modified file 'lisp/term/x-win.el'
--- lisp/term/x-win.el	2012-08-10 12:44:06 +0000
+++ lisp/term/x-win.el	2012-08-10 14:33:38 +0000
@@ -1306,17 +1306,14 @@
 
 (defun x-menu-bar-open (&optional frame)
   "Open the menu bar if it is shown.
-`popup-menu' is used if it is off "
+`popup-menu' is used if it is off."
   (interactive "i")
   (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
-		  (posn-at-point))))))
+    (popup-menu (mouse-menu-bar-map) last-nonmenu-event))))
 
 \f
 ;;; Window system initialization.




^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2012-08-10 14:47 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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