comparison lisp/mouse.el @ 93664:c7dd307b0ec5

* subr.el (keymap-canonicalize): New function. * mouse.el (mouse-menu-non-singleton): Use it. (mouse-major-mode-menu): Remove hack made unnecessary. * keymap.c (Qkeymap_canonicalize): New var. (Fmap_keymap_internal): New fun. (describe_map): Use keymap-canonicalize.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 04 Apr 2008 17:31:20 +0000
parents b615c4d2a14d
children a22fbbd18c59
comparison
equal deleted inserted replaced
93663:959f4471c16e 93664:c7dd307b0ec5
199 (make-sparse-keymap (concat (format-mode-line mode-name) 199 (make-sparse-keymap (concat (format-mode-line mode-name)
200 " Mode")) 200 " Mode"))
201 menu-bar-edit-menu)) 201 menu-bar-edit-menu))
202 uniq) 202 uniq)
203 (if ancestor 203 (if ancestor
204 ;; Make our menu inherit from the desired keymap which we want 204 (set-keymap-parent newmap ancestor))
205 ;; to display as the menu now.
206 ;; Sometimes keymaps contain duplicate menu code, leading to
207 ;; duplicates in the popped-up menu. Avoid this by simply
208 ;; taking the first of any identically-named menus.
209 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg00469.html
210 (set-keymap-parent newmap
211 (progn
212 (dolist (e ancestor)
213 (unless (and (listp e)
214 (assoc (car e) uniq))
215 (setq uniq (append uniq (list e)))))
216 uniq)))
217 (popup-menu newmap event prefix))) 205 (popup-menu newmap event prefix)))
218 206
219 207
220 (defun mouse-menu-non-singleton (menubar) 208 (defun mouse-menu-non-singleton (menubar)
221 "Given menu keymap, 209 "Given menu keymap,
223 Otherwise return the whole menu." 211 Otherwise return the whole menu."
224 (if menubar 212 (if menubar
225 (let (submap) 213 (let (submap)
226 (map-keymap 214 (map-keymap
227 (lambda (k v) (setq submap (if submap t (cons k v)))) 215 (lambda (k v) (setq submap (if submap t (cons k v))))
228 menubar) 216 (keymap-canonicalize menubar))
229 (if (eq submap t) 217 (if (eq submap t)
230 menubar 218 menubar
231 (lookup-key menubar (vector (car submap))))))) 219 (lookup-key menubar (vector (car submap)))))))
232 220
233 (defun mouse-popup-menubar (event prefix) 221 (defun mouse-popup-menubar (event prefix)
244 ;; insert it into the keymap; each keymap gets its own 232 ;; insert it into the keymap; each keymap gets its own
245 ;; prompt. This is required for non-toolkit versions to 233 ;; prompt. This is required for non-toolkit versions to
246 ;; display non-empty menu pane names. 234 ;; display non-empty menu pane names.
247 (minor-mode-menus 235 (minor-mode-menus
248 (mapcar 236 (mapcar
249 (function 237 (lambda (menu)
250 (lambda (menu) 238 (let* ((minor-mode (car menu))
251 (let* ((minor-mode (car menu)) 239 (menu (cdr menu))
252 (menu (cdr menu)) 240 (title-or-map (cadr menu)))
253 (title-or-map (cadr menu))) 241 (or (stringp title-or-map)
254 (or (stringp title-or-map) 242 (setq menu
255 (setq menu 243 (cons 'keymap
256 (cons 'keymap 244 (cons (concat
257 (cons (concat 245 (capitalize (subst-char-in-string
258 (capitalize (subst-char-in-string 246 ?- ?\s (symbol-name
259 ?- ?\s (symbol-name 247 minor-mode)))
260 minor-mode))) 248 " Menu")
261 " Menu") 249 (cdr menu)))))
262 (cdr menu))))) 250 menu))
263 menu)))
264 (minor-mode-key-binding [menu-bar]))) 251 (minor-mode-key-binding [menu-bar])))
265 (local-title-or-map (and local-menu (cadr local-menu))) 252 (local-title-or-map (and local-menu (cadr local-menu)))
266 (global-title-or-map (cadr global-menu))) 253 (global-title-or-map (cadr global-menu)))
267 (or (null local-menu) 254 (or (null local-menu)
268 (stringp local-title-or-map) 255 (stringp local-title-or-map)