diff options
| author | Masatake YAMATO | 2012-08-10 08:44:06 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2012-08-10 08:44:06 -0400 |
| commit | c69f56a207451f7f874877d02a44d4e4e6353b03 (patch) | |
| tree | a5a2a44790c1fe84fa8d575600415a8574a93ad7 /lisp/mouse.el | |
| parent | 9ff736dc87d2e9f1d529adb00d0c3e3080142e71 (diff) | |
| download | emacs-c69f56a207451f7f874877d02a44d4e4e6353b03.tar.gz emacs-c69f56a207451f7f874877d02a44d4e4e6353b03.zip | |
* 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'.
Diffstat (limited to 'lisp/mouse.el')
| -rw-r--r-- | lisp/mouse.el | 52 |
1 files changed, 35 insertions, 17 deletions
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." | |||
| 101 | "Popup the given menu and call the selected option. | 101 | "Popup the given menu and call the selected option. |
| 102 | MENU can be a keymap, an easymenu-style menu or a list of keymaps as for | 102 | MENU can be a keymap, an easymenu-style menu or a list of keymaps as for |
| 103 | `x-popup-menu'. | 103 | `x-popup-menu'. |
| 104 | 104 | The menu is shown at the place where POSITION specifies. About | |
| 105 | POSITION can be a click event or ((XOFFSET YOFFSET) WINDOW) and | 105 | the form of POSITION, see `popup-menu-normalize-position'. |
| 106 | defaults to the current mouse position. If POSITION is the | ||
| 107 | symbol `point', the current point position is used. | ||
| 108 | |||
| 109 | PREFIX is the prefix argument (if any) to pass to the command." | 106 | PREFIX is the prefix argument (if any) to pass to the command." |
| 110 | (let* ((map (cond | 107 | (let* ((map (cond |
| 111 | ((keymapp menu) menu) | 108 | ((keymapp menu) menu) |
| @@ -114,18 +111,8 @@ PREFIX is the prefix argument (if any) to pass to the command." | |||
| 114 | (filter (when (symbolp map) | 111 | (filter (when (symbolp map) |
| 115 | (plist-get (get map 'menu-prop) :filter)))) | 112 | (plist-get (get map 'menu-prop) :filter)))) |
| 116 | (if filter (funcall filter (symbol-function map)) map))))) | 113 | (if filter (funcall filter (symbol-function map)) map))))) |
| 117 | event cmd) | 114 | event cmd |
| 118 | (setq position | 115 | (position (popup-menu-normalize-position position))) |
| 119 | (cond | ||
| 120 | ((eq position 'point) | ||
| 121 | (let* ((pp (posn-at-point)) | ||
| 122 | (xy (posn-x-y pp))) | ||
| 123 | (list (list (car xy) (cdr xy)) (posn-window pp)))) | ||
| 124 | ((not position) | ||
| 125 | (let ((mp (mouse-pixel-position))) | ||
| 126 | (list (list (cadr mp) (cddr mp)) (car mp)))) | ||
| 127 | (t | ||
| 128 | position))) | ||
| 129 | ;; The looping behavior was taken from lmenu's popup-menu-popup | 116 | ;; The looping behavior was taken from lmenu's popup-menu-popup |
| 130 | (while (and map (setq event | 117 | (while (and map (setq event |
| 131 | ;; map could be a prefix key, in which case | 118 | ;; 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." | |||
| 163 | ;; mouse-major-mode-menu was using `command-execute' instead. | 150 | ;; mouse-major-mode-menu was using `command-execute' instead. |
| 164 | (call-interactively cmd)))) | 151 | (call-interactively cmd)))) |
| 165 | 152 | ||
| 153 | (defun popup-menu-normalize-position (position) | ||
| 154 | "Converts the POSITION to the form which `popup-menu' expects internally. | ||
| 155 | POSITION can be nil, an click event, a posn- value, or a value having | ||
| 156 | form ((XOFFSET YOFFSET) WINDOW). | ||
| 157 | If nil, the current mouse position is used. | ||
| 158 | If an click event, the value returend from `event-end' is used." | ||
| 159 | (pcase position | ||
| 160 | ;; nil -> mouse cursor position | ||
| 161 | ;; this pattern must be before `eventp' because | ||
| 162 | ;; nil is an event. | ||
| 163 | (`nil | ||
| 164 | (let ((mp (mouse-pixel-position))) | ||
| 165 | (list (list (cadr mp) (cddr mp)) (car mp)))) | ||
| 166 | ;; value returned from (event-end (read-event)) or (posn-at-point) | ||
| 167 | ((or `(,window ,area-or-pos (,x . ,y) | ||
| 168 | ,timestamp ,object ,pos (,col . ,row) | ||
| 169 | ,image (,dx . ,dy) (,width . ,height)) | ||
| 170 | `(,window ,pos (0 . 0) 0)) | ||
| 171 | (let ((xy (posn-x-y position))) | ||
| 172 | (list (list (car xy) (cdr xy)) | ||
| 173 | (posn-window position)))) | ||
| 174 | ;; pattern expected by popup-menu | ||
| 175 | (`((,xoffset ,yoffset) ,window) | ||
| 176 | position) | ||
| 177 | ;; event | ||
| 178 | ((pred eventp) | ||
| 179 | (popup-menu-normalize-position (event-end position))) | ||
| 180 | ;; rejects | ||
| 181 | (t | ||
| 182 | (error "Unexpected position form")))) | ||
| 183 | |||
| 166 | (defun minor-mode-menu-from-indicator (indicator) | 184 | (defun minor-mode-menu-from-indicator (indicator) |
| 167 | "Show menu for minor mode specified by INDICATOR. | 185 | "Show menu for minor mode specified by INDICATOR. |
| 168 | Interactively, INDICATOR is read using completion. | 186 | Interactively, INDICATOR is read using completion. |