;; Test case for force-mode-line-update. ;; ;; Load this file into a new buffer. ;; ;; It should give a menu called "AAA" with a "Switch to BBB" item. ;; Clicking on the item switches the menu to BBB, which is again a ;; similar menu which allows you to switch back to AAA. ;; ;; Using the "Force to BBB" menu item, on the other hand, doesn't switch ;; the menu. Another event somewhere is needed for the menu bar ;; change to take effect. (defvar test-map (make-sparse-keymap)) (defun menu-A () (define-key test-map [menu-bar] (make-sparse-keymap "Menu")) (define-key test-map [menu-bar menu-a] (cons "AAA" (make-sparse-keymap "AAA"))) (define-key test-map [menu-bar menu-a force] '(menu-item "Force to BBB" test-force-mode-line-update)) (define-key test-map [menu-bar menu-a switch] '(menu-item "Switch to BBB" test-toggle-menubar))) (defun menu-B () (define-key test-map [menu-bar] (make-sparse-keymap "Menu")) (define-key test-map [menu-bar menu-b] (cons "BBB" (make-sparse-keymap "BBB"))) (define-key test-map [menu-bar menu-b force] '(menu-item "Force to AAA" test-force-mode-line-update)) (define-key test-map [menu-bar menu-b switch] '(menu-item "Switch to AAA" test-toggle-menubar))) (defun test-toggle-menubar () (interactive) (if (lookup-key test-map [menu-bar menu-a]) (menu-B) (menu-A)) (force-mode-line-update t)) ;; This is the same as toggle except that it changes buffer beforehand. ;; Tests if force-mode-line-update truly updates all buffers. (defun test-force-mode-line-update () (interactive) (with-current-buffer (get-buffer-create "dummy") (test-toggle-menubar))) (menu-A) (use-local-map test-map)