- (if (featurep 'menubar)
- (progn
- (unless (member menu easy-menu-all-popups)
- (push menu easy-menu-all-popups))
- (setq mode-popup-menu (if (> (length easy-menu-all-popups) 1)
- (cons (easy-menu-title)
- (reverse easy-menu-all-popups))
- (car easy-menu-all-popups)))
-
- (cond ((null current-menubar)
- ;; Don't add it to a non-existing menubar.
- nil)
- ((assoc (car menu) current-menubar)
- ;; Already present.
- nil)
- ((equal current-menubar '(nil))
- ;; Set at left if only contains right marker.
- (set-buffer-menubar (list menu nil)))
- (t
- ;; Add at right.
- (set-buffer-menubar (copy-sequence current-menubar))
- (add-menu nil (car menu) (cdr menu)))))))
+ ;; If you uncomment the following, do an xemacs -vanilla, type M-x
+ ;; folding-mode RET, you'll see that this code, which theoretically has
+ ;; *scratch* as its buffer context, can't see *scratch*'s value for
+ ;; mode-popup-menu--the default overrides it.
+ ;;
+ ;; This is not specific to *scratch*--try it on ~/.xemacs/init.el--but it
+ ;; does appear to be specific to the first time mode-popup-menu is
+ ;; accessed as a buffer-local variable in non-interactive code (that is,
+ ;; M-: mode-popup-menu RET gives the correct value).
+ ;;
+ ;; My fixing this right now isn't going to happen. Aidan Kehoe, 2006-01-03
+; (message (concat "inside easy-menu-add, menu is %s, "
+; "mode-popup-menu is %s, current buffer is %s, "
+; "default-value mode-popup-menu is %s, "
+; "easy-menu-all-popups is %s")
+; menu mode-popup-menu (current-buffer)
+; (default-value 'mode-popup-menu) easy-menu-all-popups)
+ (when (featurep 'menubar)
+ ;; Save the existing mode-popup-menu, if it's been changed.
+ (when (and (zerop (length easy-menu-all-popups))
+ (not (equal (default-value 'mode-popup-menu) mode-popup-menu)))
+ (push mode-popup-menu easy-menu-all-popups))
+ ;; Add the menu to our list of all the popups for the buffer.
+ (pushnew menu easy-menu-all-popups :test 'equal)
+ ;; If there are multiple popup menus available, make the popup menu
+ ;; normally shown with button-3 a menu of them. If there is just one,
+ ;; make that button show it, and no super-menu.
+ (setq mode-popup-menu (if (= 1 (length easy-menu-all-popups))
+ (car easy-menu-all-popups)
+ (cons (easy-menu-title)
+ (reverse easy-menu-all-popups))))
+ (cond ((null current-menubar)
+ ;; Don't add it to a non-existing menubar.
+ nil)
+ ((assoc (car menu) current-menubar)
+ ;; Already present.
+ nil)
+ ((equal current-menubar '(nil))
+ ;; Set at left if only contains right marker.
+ (set-buffer-menubar (list menu nil)))
+ (t
+ ;; Add at right.
+ (set-buffer-menubar (copy-sequence current-menubar))
+ (add-menu nil (car menu) (cdr menu))))))