diff lisp/menu-bar.el @ 49997:afcd12db0367

* startup.el (command-line): Call menu-bar-mode with 1 instead of t. * menu-bar.el (menu-bar-mode): Change to define-minor-mode and initialize as for tool-bar-mode.
author Jan Djärv <jan.h.d@swipnet.se>
date Sat, 01 Mar 2003 15:55:04 +0000
parents 78bf19f4f12c
children 7831ca508f35
line wrap: on
line diff
--- a/lisp/menu-bar.el	Fri Feb 28 18:29:33 2003 +0000
+++ b/lisp/menu-bar.el	Sat Mar 01 15:55:04 2003 +0000
@@ -1611,61 +1611,44 @@
     (list 'menu-item "Enter" 'exit-minibuffer
 	  :help "Terminate input and exit minibuffer")))
 
-(defcustom menu-bar-mode t
-  "Toggle display of a menu bar on each frame.
-Setting this variable directly does not take effect;
-use either \\[customize] or the function `menu-bar-mode'."
-  :set (lambda (symbol value)
-	 (menu-bar-mode (or value 0)))
-  :initialize 'custom-initialize-default
-  :type 'boolean
-  :group 'frames)
+;;;###autoload
+;; This comment is taken from toolbar/tool-bar.el near
+;; (put 'tool-bar-mode ...)
+;; We want to pretend the menu bar by standard is on, as this will make
+;; customize consider disabling the menu bar a customization, and save
+;; that.  We could do this for real by setting :init-value below, but
+;; that would overwrite disabling the tool bar from X resources.
+(put 'menu-bar-mode 'standard-value '(t))
 
-(defun menu-bar-mode (&optional flag)
+;;;###autoload
+(define-minor-mode menu-bar-mode
   "Toggle display of a menu bar on each frame.
 This command applies to all frames that exist and frames to be
 created in the future.
 With a numeric argument, if the argument is positive,
 turn on menu bars; otherwise, turn off menu bars."
-  (interactive "P")
-
+  :init-value nil
+  :global t
+  :group 'frames
   ;; Make menu-bar-mode and default-frame-alist consistent.
-  (let ((default (assq 'menu-bar-lines default-frame-alist)))
-    (if default
-	(setq menu-bar-mode (not (eq (cdr default) 0)))
-      (setq default-frame-alist
-	    (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
-		  default-frame-alist))))
-
-  ;; Toggle or set the mode, according to FLAG.
-  (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
-			(> (prefix-numeric-value flag) 0)))
+  (let ((lines (if menu-bar-mode 1 0)))
+    ;; Alter existing frames...
+    (mapc (lambda (frame)
+	    (modify-frame-parameters frame
+				     (list (cons 'menu-bar-lines lines))))
+	  (frame-list))
+    ;; ...and future ones.
+    (let ((elt (assq 'menu-bar-lines default-frame-alist)))
+      (if elt
+	  (setcdr elt lines)
+	(add-to-list 'default-frame-alist (cons 'menu-bar-lines lines)))))
 
-  ;; Apply it to default-frame-alist.
-  (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
-    (if (consp parameter)
-	(setcdr parameter (if menu-bar-mode 1 0))
-      (setq default-frame-alist
-	    (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
-		  default-frame-alist))))
-
-  ;; Apply it to existing frames.
-  (let ((frames (frame-list)))
-    (while frames
-      (let ((height (cdr (assq 'height (frame-parameters (car frames))))))
-	(modify-frame-parameters (car frames)
-				 (list (cons 'menu-bar-lines
-					     (if menu-bar-mode 1 0))))
-	(modify-frame-parameters (car frames)
-				 (list (cons 'height height))))
-      (setq frames (cdr frames))))
-
-  (when (interactive-p)
-    (if menu-bar-mode
-	(message "Menu-bar mode enabled.")
-      (message "Menu-bar mode disabled.  Use M-x menu-bar-mode to make the menu bar appear."))
-    (customize-mark-as-set 'menu-bar-mode))
-
+  ;; Make the message appear when Emacs is idle.  We can not call message
+  ;; directly.  The minor-mode message "Menu-bar mode disabled" comes
+  ;; after this function returns, overwriting any message we do here.
+  (when (and (interactive-p) (not menu-bar-mode))
+    (run-with-idle-timer 0 nil 'message
+			 "Menu-bar mode disabled.  Use M-x menu-bar-mode to make the menu bar appear."))
   menu-bar-mode)
 
 (provide 'menu-bar)