emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r109550: * lisp/mouse.el (popup-menu-


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r109550: * lisp/mouse.el (popup-menu-normalize-position): New function.
Date: Fri, 10 Aug 2012 08:44:06 -0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 109550
author: Masatake YAMATO <address@hidden>
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Fri 2012-08-10 08:44:06 -0400
message:
  * lisp/mouse.el (popup-menu-normalize-position): New function.
  (popup-menu): Use `popup-menu-normalize-position' to normalize
  the form for POSITION argument.
  * lisp/term/x-win.el (x-menu-bar-open):
  Use the value returend from (posn-at-point) as position
  passed to `popup-menu'.
modified:
  lisp/ChangeLog
  lisp/mouse.el
  lisp/term/x-win.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-08-09 14:46:03 +0000
+++ b/lisp/ChangeLog    2012-08-10 12:44:06 +0000
@@ -1,3 +1,13 @@
+2012-08-10  Masatake YAMATO  <address@hidden>
+
+       * 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-08-09  Jay Belanger  <address@hidden>
 
        * calc/calccomp.el (math-compose-expr): Add extra argument
@@ -35,8 +45,8 @@
        * progmodes/python.el: Enhancements to forward-sexp.
        (python-nav-forward-sexp): Rename from
        python-nav-forward-sexp-function.
-       (python-nav--forward-sexp, python-nav--backward-sexp): New
-       functions.
+       (python-nav--forward-sexp, python-nav--backward-sexp):
+       New functions.
 
 2012-08-09  Jay Belanger  <address@hidden>
 
@@ -489,9 +499,8 @@
 
        * register.el (copy-to-register, copy-rectangle-to-register):
        Deactivate the mark, and use indicate-copied-region (Bug#10056).
-       (append-to-register, prepend-to-register): Call
-
-2012-07-29  Juri Linkov  <address@hidden>
+       (append-to-register, prepend-to-register):
+       Call 2012-07-29  Juri Linkov  <address@hidden>
 
        * simple.el (async-shell-command-buffer): New defcustom.
        (shell-command): Use it.  (Bug#4719)

=== modified file 'lisp/mouse.el'
--- a/lisp/mouse.el     2012-08-07 03:31:53 +0000
+++ b/lisp/mouse.el     2012-08-10 12:44:06 +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'
--- a/lisp/term/x-win.el        2012-07-20 11:32:30 +0000
+++ b/lisp/term/x-win.el        2012-08-10 12:44:06 +0000
@@ -1316,7 +1316,7 @@
     (popup-menu (mouse-menu-bar-map)
                (if (listp last-nonmenu-event)
                    nil
-                 'point)))))
+                 (posn-at-point))))))
 
 
 ;;; Window system initialization.


reply via email to

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