changeset 83496:f271076dab2d

Fix toolbars on X frames when Emacs is started on a tty. (Reported by Richard Lewis.) * lisp/faces.el (x-create-frame-with-faces): Remove bogus check for first frame. Call `tool-bar-setup'. * lisp/frame.el (window-system-default-frame-alist): Enhance doc string. * lisp/frame.el (frame-notice-user-settings): Don't put 'tool-bar-lines in `default-frame-alist' when initial frame is on a tty. * lisp/frame.el (modify-all-frames-parameters): Simplify using `assq-delete-all'. Remove specified parameters from `window-system-default-frame-alist'. * lisp/fringe.el (set-fringe-mode): Simplify and fix using `modify-all-frames-parameters'. * lisp/menu-bar.el (menu-bar-mode): Ditto. * lisp/scroll-bar.el (set-scroll-bar-mode): Ditto. * lisp/tool-bar.el (tool-bar-mode): Ditto. Remove 'tool-bar-map length check before calling `tool-bar-setup'. * lisp/tool-bar.el (tool-bar-setup): New variable. * lisp/tool-bar.el (tool-bar-setup): Use it to guard against multiple calls. Add optional frame parameter, and select that frame before adding items. * src/frame.c (syms_of_frame): Enhance doc string of `default-frame-alist'. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-536
author Karoly Lorentey <lorentey@elte.hu>
date Sun, 26 Mar 2006 13:57:43 +0000
parents 989dc6aa2eb2
children a25bb5ef27bf
files README.multi-tty lisp/faces.el lisp/frame.el lisp/fringe.el lisp/menu-bar.el lisp/scroll-bar.el lisp/tool-bar.el src/frame.c
diffstat 8 files changed, 116 insertions(+), 138 deletions(-) [+]
line wrap: on
line diff
--- a/README.multi-tty	Sun Mar 26 07:21:47 2006 +0000
+++ b/README.multi-tty	Sun Mar 26 13:57:43 2006 +0000
@@ -46,6 +46,7 @@
 Bas Kok <nekkobassu@yahoo.com>
 Jurej Kubelka <Juraj.Kubelka@email.cz>
 David Lichteblau <david@lichteblau.com>
+Richard Lewis <rtf@jabble.com>
 mace <mace@kirjakaapeli.lib.hel.fi>
 Suresh Madhu <madhu@cs.unm.edu>
 Xavier Mallard <zedek@gnu-rox.org>
@@ -403,6 +404,17 @@
 THINGS TO DO
 ------------
 
+** `tool-bar-mode', `scroll-bar-mode', `menu-bar-mode' and
+   'fringe-mode' are modes global to the entire Emacs session, not
+   just a single frame or a single terminal.  This means that their
+   status sometimes differs from what's actually displayed on the
+   screen.  As a consequence, the Options | Show/Hide menu sometimes
+   shows incorrect status, and you have to select an option twice for
+   it to have any visible effect on the current frame.
+
+   Change Emacs so that the status of the items in the Options |
+   Show/Hide menu correspond to the current frame.
+
 ** emacsclient -t on the console does not work after su:
 
 	# su lorentey
--- a/lisp/faces.el	Sun Mar 26 07:21:47 2006 +0000
+++ b/lisp/faces.el	Sun Mar 26 13:57:43 2006 +0000
@@ -1725,7 +1725,6 @@
 Value is the new frame created."
   (setq parameters (x-handle-named-frame-geometry parameters))
   (let ((visibility-spec (assq 'visibility parameters))
-	(frame-list (frame-list))
 	(frame (x-create-frame `((visibility . nil) . ,parameters)))
 	success)
     (unwind-protect
@@ -1739,7 +1738,11 @@
 	   frame '((interprogram-cut-function . x-select-text)))
 	  (modify-frame-parameters
 	   frame '((interprogram-paste-function . x-cut-buffer-or-selection-value)))
-	  (if (or (null frame-list) (null visibility-spec))
+	  ;; Make sure the tool-bar is ready to be enabled.  The
+	  ;; `tool-bar-lines' frame parameter will not take effect
+	  ;; without this call.
+	  (tool-bar-setup frame)
+	  (if (null visibility-spec)
 	      (make-frame-visible frame)
 	    (modify-frame-parameters frame (list visibility-spec)))
 	  (setq success t))
--- a/lisp/frame.el	Sun Mar 26 07:21:47 2006 +0000
+++ b/lisp/frame.el	Sun Mar 26 13:57:43 2006 +0000
@@ -41,14 +41,14 @@
 
 (defvar window-system-default-frame-alist nil
   "Alist of window-system dependent default frame parameters.
-These may be set in your init file, like this:
+You can set this in your `.emacs' file; for example,
 
     ;; Disable menubar and toolbar on the console, but enable them under X.
     (setq window-system-default-frame-alist
           '((x (menu-bar-lines . 1) (tool-bar-lines . 1))
             (nil (menu-bar-lines . 0) (tool-bar-lines . 0))))
 
-Also see `default-frame-alist'.")
+Parameters specified here supersede the values given in `default-frame-alist'.")
 
 ;; The initial value given here used to ask for a minibuffer.
 ;; But that's not necessary, because the default is to have one.
@@ -268,13 +268,21 @@
   ;; parameter in default-frame-alist in a dumped Emacs, which is not
   ;; what we want.
   (when (and (boundp 'tool-bar-mode)
-	     (not noninteractive))
+ 	     (not noninteractive))
     (let ((default (assq 'tool-bar-lines default-frame-alist)))
       (if default
-	  (setq tool-bar-mode (not (eq (cdr default) 0)))
-	(setq default-frame-alist
-	      (cons (cons 'tool-bar-lines (if tool-bar-mode 1 0))
-		    default-frame-alist)))))
+ 	  (setq tool-bar-mode (not (eq (cdr default) 0)))
+	;; If Emacs was started on a tty, changing default-frame-alist
+	;; would disable the toolbar on X frames created later.  We
+	;; want to keep the default of showing a toolbar under X even
+	;; in this case.
+	;;
+	;; If the user explicitly called `tool-bar-mode' in .emacs,
+	;; then default-frame-alist is already changed anyway.
+	(when initial-window-system
+	  (setq default-frame-alist
+		(cons (cons 'tool-bar-lines (if tool-bar-mode 1 0))
+		      default-frame-alist))))))
 
   ;; Creating and deleting frames may shift the selected frame around,
   ;; and thus the current buffer.  Protect against that.  We don't
@@ -545,19 +553,25 @@
 (defun modify-all-frames-parameters (alist)
   "Modify all current and future frames' parameters according to ALIST.
 This changes `default-frame-alist' and possibly `initial-frame-alist'.
+Furthermore, this function removes all parameters in ALIST from
+`window-system-default-frame-alist'.
 See help of `modify-frame-parameters' for more information."
-  (let (element)			;; temp
-    (dolist (frame (frame-list))
-      (modify-frame-parameters frame alist))
+  (dolist (frame (frame-list))
+    (modify-frame-parameters frame alist))
 
-    (dolist (pair alist)		;; conses to add/replace
-      ;; initial-frame-alist needs setting only when
-      ;; frame-notice-user-settings is true
-      (and frame-notice-user-settings
-	   (setq element (assoc (car pair) initial-frame-alist))
-	   (setq initial-frame-alist (delq element initial-frame-alist)))
-      (and (setq element (assoc (car pair) default-frame-alist))
-	   (setq default-frame-alist (delq element default-frame-alist)))))
+  (dolist (pair alist) ;; conses to add/replace
+    ;; initial-frame-alist needs setting only when
+    ;; frame-notice-user-settings is true.
+    (and frame-notice-user-settings
+	 (setq initial-frame-alist
+	       (assq-delete-all (car pair) initial-frame-alist)))
+    (setq default-frame-alist
+	  (assq-delete-all (car pair) default-frame-alist))
+    ;; Remove any similar settings from the window-system specific
+    ;; parameters---they would override default-frame-alist.
+    (dolist (w window-system-default-frame-alist)
+      (setcdr w (assq-delete-all (car pair) (cdr w)))))
+
   (and frame-notice-user-settings
        (setq initial-frame-alist (append initial-frame-alist alist)))
   (setq default-frame-alist (append default-frame-alist alist)))
--- a/lisp/fringe.el	Sun Mar 26 07:21:47 2006 +0000
+++ b/lisp/fringe.el	Sun Mar 26 13:57:43 2006 +0000
@@ -104,40 +104,13 @@
 See `fringe-mode' for possible values and their effect."
   (setq fringe-mode value)
 
-  ;; Apply it to default-frame-alist.
-  (let ((parameter (assq 'left-fringe default-frame-alist)))
-    (if (consp parameter)
-	(setcdr parameter (if (consp fringe-mode)
-			      (car fringe-mode)
-			    fringe-mode))
-      (setq default-frame-alist
-	    (cons (cons 'left-fringe (if (consp fringe-mode)
-					 (car fringe-mode)
-				       fringe-mode))
-		  default-frame-alist))))
-  (let ((parameter (assq 'right-fringe default-frame-alist)))
-    (if (consp parameter)
-	(setcdr parameter (if (consp fringe-mode)
-			      (cdr fringe-mode)
-			    fringe-mode))
-      (setq default-frame-alist
-	    (cons (cons 'right-fringe (if (consp fringe-mode)
-					  (cdr fringe-mode)
-					fringe-mode))
-		  default-frame-alist))))
-
-  ;; Apply it to existing frames.
-  (let ((frames (frame-list)))
-    (while frames
-      (modify-frame-parameters
-       (car frames)
-       (list (cons 'left-fringe (if (consp fringe-mode)
-				    (car fringe-mode)
-				  fringe-mode))
-	     (cons 'right-fringe (if (consp fringe-mode)
-				     (cdr fringe-mode)
-				   fringe-mode))))
-      (setq frames (cdr frames)))))
+  (modify-all-frames-parameters
+   (list (cons 'left-fringe (if (consp fringe-mode)
+				(car fringe-mode)
+			      fringe-mode))
+	 (cons 'right-fringe (if (consp fringe-mode)
+				 (cdr fringe-mode)
+			       fringe-mode)))))
 
 ;; For initialization of fringe-mode, take account of changes
 ;; made explicitly to default-frame-alist.
--- a/lisp/menu-bar.el	Sun Mar 26 07:21:47 2006 +0000
+++ b/lisp/menu-bar.el	Sun Mar 26 13:57:43 2006 +0000
@@ -1765,18 +1765,10 @@
   :init-value nil
   :global t
   :group 'frames
+
   ;; Make menu-bar-mode and default-frame-alist consistent.
-  (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)))))
+  (modify-all-frames-parameters (list (cons 'menu-bar-lines
+					    (if menu-bar-mode 1 0))))
 
   ;; Make the message appear when Emacs is idle.  We can not call message
   ;; directly.  The minor-mode message "Menu-bar mode disabled" comes
--- a/lisp/scroll-bar.el	Sun Mar 26 07:21:47 2006 +0000
+++ b/lisp/scroll-bar.el	Sun Mar 26 13:57:43 2006 +0000
@@ -88,21 +88,8 @@
   (setq scroll-bar-mode value)
 
   (when scroll-bar-mode-explicit
-    ;; Apply it to default-frame-alist.
-    (let ((parameter (assq 'vertical-scroll-bars default-frame-alist)))
-      (if (consp parameter)
-	  (setcdr parameter scroll-bar-mode)
-	(setq default-frame-alist
-	      (cons (cons 'vertical-scroll-bars scroll-bar-mode)
-		    default-frame-alist))))
-
-    ;; Apply it to existing frames.
-    (let ((frames (frame-list)))
-      (while frames
-	(modify-frame-parameters
-	 (car frames)
-	 (list (cons 'vertical-scroll-bars scroll-bar-mode)))
-	(setq frames (cdr frames))))))
+    (modify-all-frames-parameters (list (cons 'vertical-scroll-bars
+					      scroll-bar-mode)))))
 
 (defcustom scroll-bar-mode default-frame-scroll-bars
   "*Specify whether to have vertical scroll bars, and on which side.
--- a/lisp/tool-bar.el	Sun Mar 26 07:21:47 2006 +0000
+++ b/lisp/tool-bar.el	Sun Mar 26 13:57:43 2006 +0000
@@ -55,20 +55,10 @@
   :group 'mouse
   :group 'frames
   (and (display-images-p)
-       (let ((lines (if tool-bar-mode 1 0)))
-	 ;; Alter existing frames...
-	 (mapc (lambda (frame)
-		 (modify-frame-parameters frame
-					  (list (cons 'tool-bar-lines lines))))
-	       (frame-list))
-	 ;; ...and future ones.
-	 (let ((elt (assq 'tool-bar-lines default-frame-alist)))
-	   (if elt
-	       (setcdr elt lines)
-	     (add-to-list 'default-frame-alist (cons 'tool-bar-lines lines)))))
+       (modify-all-frames-parameters (list (cons 'tool-bar-lines
+						 (if tool-bar-mode 1 0))))
        (if (and tool-bar-mode
-		(display-graphic-p)
-		(= 1 (length (default-value 'tool-bar-map)))) ; not yet setup
+		(display-graphic-p))
 	   (tool-bar-setup))))
 
 ;;;###autoload
@@ -228,54 +218,60 @@
 
 ;;; Set up some global items.  Additions/deletions up for grabs.
 
-(defun tool-bar-setup ()
-  ;; People say it's bad to have EXIT on the tool bar, since users
-  ;; might inadvertently click that button.
-  ;;(tool-bar-add-item-from-menu 'save-buffers-kill-emacs "exit")
-  (tool-bar-add-item-from-menu 'find-file "new")
-  (tool-bar-add-item-from-menu 'menu-find-file-existing "open")
-  (tool-bar-add-item-from-menu 'dired "diropen")
-  (tool-bar-add-item-from-menu 'kill-this-buffer "close")
-  (tool-bar-add-item-from-menu 'save-buffer "save" nil
-			       :visible '(or buffer-file-name
-					     (not (eq 'special
-						      (get major-mode
-							   'mode-class)))))
-  (tool-bar-add-item-from-menu 'write-file "saveas" nil
-			       :visible '(or buffer-file-name
-					     (not (eq 'special
-						      (get major-mode
-							   'mode-class)))))
-  (tool-bar-add-item-from-menu 'undo "undo" nil
-			       :visible '(not (eq 'special (get major-mode
-								'mode-class))))
-  (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [cut])
-			       "cut" nil
-			       :visible '(not (eq 'special (get major-mode
-								'mode-class))))
-  (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [copy])
-			       "copy")
-  (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [paste])
-			       "paste" nil
-			       :visible '(not (eq 'special (get major-mode
-								'mode-class))))
-  (tool-bar-add-item-from-menu 'nonincremental-search-forward "search")
-  ;;(tool-bar-add-item-from-menu 'ispell-buffer "spell")
+(defvar tool-bar-setup nil
+  "t if the tool-bar has been set up by `tool-bar-setup'.")
 
-  ;; There's no icon appropriate for News and we need a command rather
-  ;; than a lambda for Read Mail.
-  ;;(tool-bar-add-item-from-menu 'compose-mail "mail/compose")
+(defun tool-bar-setup (&optional frame)
+  (unless tool-bar-setup
+    (with-selected-frame (or frame (selected-frame))
+      ;; People say it's bad to have EXIT on the tool bar, since users
+      ;; might inadvertently click that button.
+      ;;(tool-bar-add-item-from-menu 'save-buffers-kill-emacs "exit")
+      (tool-bar-add-item-from-menu 'find-file "new")
+      (tool-bar-add-item-from-menu 'menu-find-file-existing "open")
+      (tool-bar-add-item-from-menu 'dired "diropen")
+      (tool-bar-add-item-from-menu 'kill-this-buffer "close")
+      (tool-bar-add-item-from-menu 'save-buffer "save" nil
+				   :visible '(or buffer-file-name
+						 (not (eq 'special
+							  (get major-mode
+							       'mode-class)))))
+      (tool-bar-add-item-from-menu 'write-file "saveas" nil
+				   :visible '(or buffer-file-name
+						 (not (eq 'special
+							  (get major-mode
+							       'mode-class)))))
+      (tool-bar-add-item-from-menu 'undo "undo" nil
+				   :visible '(not (eq 'special (get major-mode
+								    'mode-class))))
+      (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [cut])
+				   "cut" nil
+				   :visible '(not (eq 'special (get major-mode
+								    'mode-class))))
+      (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [copy])
+				   "copy")
+      (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [paste])
+				   "paste" nil
+				   :visible '(not (eq 'special (get major-mode
+								    'mode-class))))
+      (tool-bar-add-item-from-menu 'nonincremental-search-forward "search")
+      ;;(tool-bar-add-item-from-menu 'ispell-buffer "spell")
 
-  (tool-bar-add-item-from-menu 'print-buffer "print")
-  (tool-bar-add-item "preferences" 'customize 'customize
-		     :help "Edit preferences (customize)")
+      ;; There's no icon appropriate for News and we need a command rather
+      ;; than a lambda for Read Mail.
+      ;;(tool-bar-add-item-from-menu 'compose-mail "mail/compose")
+
+      (tool-bar-add-item-from-menu 'print-buffer "print")
+      (tool-bar-add-item "preferences" 'customize 'customize
+			 :help "Edit preferences (customize)")
 
-  (tool-bar-add-item "help" (lambda ()
-			      (interactive)
-			      (popup-menu menu-bar-help-menu))
-		     'help
-		     :help "Pop up the Help menu")
-  )
+      (tool-bar-add-item "help" (lambda ()
+				  (interactive)
+				  (popup-menu menu-bar-help-menu))
+			 'help
+			 :help "Pop up the Help menu")
+
+      (setq tool-bar-setup t))))
 
 (provide 'tool-bar)
 
--- a/src/frame.c	Sun Mar 26 07:21:47 2006 +0000
+++ b/src/frame.c	Sun Mar 26 13:57:43 2006 +0000
@@ -4373,6 +4373,7 @@
 These override values given in window system configuration data,
  including X Windows' defaults database.
 For values specific to the first Emacs frame, see `initial-frame-alist'.
+For window-system specific values, see `window-system-default-frame-alist'.
 For values specific to the separate minibuffer frame, see
  `minibuffer-frame-alist'.
 The `menu-bar-lines' element of the list controls whether new frames