From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Where the menu should be appeared when C-mouse-3 is triggered Date: Fri, 10 Aug 2012 10:47:38 -0400 Message-ID: References: <20120720.205626.241222894708490981.yamato@redhat.com> <20120728.183150.270114999187506774.yamato@redhat.com> <20120809.201312.1329961304666767845.yamato@redhat.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1344610073 27320 80.91.229.3 (10 Aug 2012 14:47:53 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 10 Aug 2012 14:47:53 +0000 (UTC) Cc: emacs-devel@gnu.org To: Masatake YAMATO Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Aug 10 16:47:54 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SzqVC-0001Ew-OM for ged-emacs-devel@m.gmane.org; Fri, 10 Aug 2012 16:47:50 +0200 Original-Received: from localhost ([::1]:56558 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzqVC-000117-0s for ged-emacs-devel@m.gmane.org; Fri, 10 Aug 2012 10:47:50 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:54491) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzqV7-00010z-UE for emacs-devel@gnu.org; Fri, 10 Aug 2012 10:47:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzqV2-00051A-32 for emacs-devel@gnu.org; Fri, 10 Aug 2012 10:47:45 -0400 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:33781) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzqV1-00050y-VI for emacs-devel@gnu.org; Fri, 10 Aug 2012 10:47:40 -0400 Original-Received: from faina.iro.umontreal.ca (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id q7AElcsd031618; Fri, 10 Aug 2012 10:47:38 -0400 Original-Received: by faina.iro.umontreal.ca (Postfix, from userid 20848) id 4C8CCB4177; Fri, 10 Aug 2012 10:47:38 -0400 (EDT) In-Reply-To: (Stefan Monnier's message of "Fri, 10 Aug 2012 08:44:42 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV4306=0 X-NAI-Spam-Version: 2.2.0.9309 : core <4306> : streams <797198> : uri <1188920> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.22 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:152411 Archived-At: > 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 + + * 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 * 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 @@ ;;;; 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)))) ;;; Window system initialization.