]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/mouse.el (popup-menu-normalize-position): New function.
authorMasatake YAMATO <yamato@redhat.com>
Fri, 10 Aug 2012 12:44:06 +0000 (08:44 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Fri, 10 Aug 2012 12:44:06 +0000 (08:44 -0400)
(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'.

lisp/ChangeLog
lisp/mouse.el
lisp/term/x-win.el

index fef050e6d024faf85c3d3b17a5f36174aac600d9..dc0efcf7563954a4495f285acf17ade6420f2c1e 100644 (file)
@@ -1,3 +1,13 @@
+2012-08-10  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-08-09  Jay Belanger  <jay.p.belanger@gmail.com>
 
        * 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  <jay.p.belanger@gmail.com>
 
 
        * 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  <juri@jurta.org>
+       (append-to-register, prepend-to-register):
+       Call 2012-07-29  Juri Linkov  <juri@jurta.org>
 
        * simple.el (async-shell-command-buffer): New defcustom.
        (shell-command): Use it.  (Bug#4719)
index 71336c08ee3b3a961e6294c9160809c7d28ba1d1..1506c3f5a8451b50dc9fff400579ce5abdf8cc18 100644 (file)
@@ -101,11 +101,8 @@ point at the click position."
   "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 @@ PREFIX is the prefix argument (if any) to pass to the command."
                         (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 @@ PREFIX is the prefix argument (if any) to pass to the command."
       ;; 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.
index fb7389b856ca8c17bfbab94259fcf0e0042127eb..3f58614eb6482a423612b2103e618b3cbc2c42e7 100644 (file)
@@ -1316,7 +1316,7 @@ Request data types in the order specified by `x-select-request-type'."
     (popup-menu (mouse-menu-bar-map)
                (if (listp last-nonmenu-event)
                    nil
-                 'point)))))
+                 (posn-at-point))))))
 
 \f
 ;;; Window system initialization.