From c69f56a207451f7f874877d02a44d4e4e6353b03 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Fri, 10 Aug 2012 08:44:06 -0400 Subject: [PATCH] * 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'. --- lisp/ChangeLog | 19 ++++++++++++----- lisp/mouse.el | 52 +++++++++++++++++++++++++++++++--------------- lisp/term/x-win.el | 2 +- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index fef050e6d02..dc0efcf7563 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,13 @@ +2012-08-10 Masatake YAMATO + + * 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 * 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 @@ -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 + (append-to-register, prepend-to-register): + Call 2012-07-29 Juri Linkov * simple.el (async-shell-command-buffer): New defcustom. (shell-command): Use it. (Bug#4719) diff --git a/lisp/mouse.el b/lisp/mouse.el index 71336c08ee3..1506c3f5a84 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -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. diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el index fb7389b856c..3f58614eb64 100644 --- a/lisp/term/x-win.el +++ b/lisp/term/x-win.el @@ -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)))))) ;;; Window system initialization. -- 2.39.2