comparison lisp/mouse.el @ 32312:b95ac47063ce

(popup-menu): Move the command call outside the loop so that popup-menu returns whatever the command returns.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sun, 08 Oct 2000 20:16:56 +0000
parents 5bccbf00889a
children 452e7cc818ac
comparison
equal deleted inserted replaced
32311:035ce2227d76 32312:b95ac47063ce
56 ((and (listp menu) (keymapp (car menu))) menu) 56 ((and (listp menu) (keymapp (car menu))) menu)
57 (t (let* ((map (easy-menu-create-menu (car menu) (cdr menu))) 57 (t (let* ((map (easy-menu-create-menu (car menu) (cdr menu)))
58 (filter (when (symbolp map) 58 (filter (when (symbolp map)
59 (plist-get (get map 'menu-pro) :filter)))) 59 (plist-get (get map 'menu-pro) :filter))))
60 (if filter (funcall filter (symbol-function map)) map))))) 60 (if filter (funcall filter (symbol-function map)) map)))))
61 event) 61 event cmd)
62 (unless position 62 (unless position
63 (let ((mp (mouse-pixel-position))) 63 (let ((mp (mouse-pixel-position)))
64 (setq position (list (list (cadr mp) (cddr mp)) (car mp))))) 64 (setq position (list (list (cadr mp) (cddr mp)) (car mp)))))
65 ;; The looping behavior was taken from lmenu's popup-menu-popup 65 ;; The looping behavior was taken from lmenu's popup-menu-popup
66 (while (and map (setq event 66 (while (and map (setq event
69 ;; definition. 69 ;; definition.
70 (x-popup-menu position (indirect-function map)))) 70 (x-popup-menu position (indirect-function map))))
71 ;; Strangely x-popup-menu returns a list. 71 ;; Strangely x-popup-menu returns a list.
72 ;; mouse-major-mode-menu was using a weird: 72 ;; mouse-major-mode-menu was using a weird:
73 ;; (key-binding (apply 'vector (append '(menu-bar) menu-prefix events))) 73 ;; (key-binding (apply 'vector (append '(menu-bar) menu-prefix events)))
74 (let ((cmd 74 (setq cmd
75 (if (and (not (keymapp map)) (listp map)) 75 (if (and (not (keymapp map)) (listp map))
76 ;; We were given a list of keymaps. Search them all 76 ;; We were given a list of keymaps. Search them all
77 ;; in sequence until a first binding is found. 77 ;; in sequence until a first binding is found.
78 (let ((mouse-click (apply 'vector event)) 78 (let ((mouse-click (apply 'vector event))
79 binding) 79 binding)
80 (while (and map (null binding)) 80 (while (and map (null binding))
81 (setq binding (lookup-key (car map) mouse-click)) 81 (setq binding (lookup-key (car map) mouse-click))
82 (if (numberp binding) ; `too long' 82 (if (numberp binding) ; `too long'
83 (setq binding nil)) 83 (setq binding nil))
84 (setq map (cdr map))) 84 (setq map (cdr map)))
85 binding) 85 binding)
86 ;; We were given a single keymap. 86 ;; We were given a single keymap.
87 (lookup-key map (apply 'vector event))))) 87 (lookup-key map (apply 'vector event))))
88 (setq map nil) 88 ;; Clear out echoing, which perhaps shows a prefix arg.
89 ;; Clear out echoing, which perhaps shows a prefix arg. 89 (message "")
90 (message "") 90 ;; Maybe try again but with the submap.
91 (when cmd 91 (setq map (if (keymapp cmd) cmd)))
92 (if (keymapp cmd) 92 (when (functionp cmd)
93 ;; Try again but with the submap. 93 (setq prefix-arg prefix)
94 (setq map cmd) 94 ;; `setup-specified-language-environment', for instance,
95 (setq prefix-arg prefix) 95 ;; expects this to be set from a menu keymap.
96 ;; `setup-specified-language-environment', for instance, 96 (setq last-command-event (car (last event)))
97 ;; expects this to be set from a menu keymap. 97 ;; mouse-major-mode-menu was using `command-execute' instead.
98 (setq last-command-event (car (last event))) 98 (call-interactively cmd)))))))
99 ;; mouse-major-mode-menu was using `command-execute' instead.
100 (call-interactively cmd)))))))
101 99
102 (defvar mouse-major-mode-menu-prefix) ; dynamically bound 100 (defvar mouse-major-mode-menu-prefix) ; dynamically bound
103 101
104 (defun mouse-major-mode-menu (event prefix) 102 (defun mouse-major-mode-menu (event prefix)
105 "Pop up a mode-specific menu of mouse commands. 103 "Pop up a mode-specific menu of mouse commands.