emacs-devel
[Top][All Lists]
Advanced

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

Re: Where the menu should be appeared when C-mouse-3 is triggered


From: Stefan Monnier
Subject: Re: Where the menu should be appeared when C-mouse-3 is triggered
Date: Fri, 10 Aug 2012 10:47:38 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)

> 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  <address@hidden>
+
+       * 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  <address@hidden>
 
        * 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.




reply via email to

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