]> code.delx.au - gnu-emacs/blobdiff - lisp/frame.el
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah...
[gnu-emacs] / lisp / frame.el
index c8085762d2a627eae3ad729cab16a4321357ee6e..f5d3f4b0c37511bd8a1519371832dddb24c1555f 100644 (file)
@@ -1,7 +1,7 @@
 ;;; frame.el --- multi-frame management independent of window systems
 
 ;; Copyright (C) 1993, 1994, 1996, 1997, 2000, 2001, 2002, 2003,
-;;   2004, 2005 Free Software Foundation, Inc.
+;;   2004, 2005, 2006 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: internal
@@ -41,14 +41,14 @@ as its argument.")
 
 (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.
@@ -238,6 +238,9 @@ Pass it BUFFER as first arg, and (cdr ARGS) gives the rest of the args."
              ;; because that would override explicit user resizing.
              (setq initial-frame-alist
                    (frame-remove-geometry-params initial-frame-alist))))
+       ;; Copy the environment of the Emacs process into the new frame.
+       (set-frame-parameter frame-initial-frame 'environment
+                            (frame-parameter terminal-frame 'environment))
        ;; At this point, we know that we have a frame open, so we
        ;; can delete the terminal frame.
        (delete-frame terminal-frame)
@@ -268,13 +271,21 @@ there (in decreasing order of priority)."
   ;; 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 +556,25 @@ there (in decreasing order of priority)."
 (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 (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 (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 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)))
@@ -598,15 +615,18 @@ The optional second argument PARAMETERS specifies additional frame parameters."
     (x-initialize-window-system))
   (make-frame `((window-system . x) (display . ,display) . ,parameters)))
 
-(defun make-frame-on-tty (device type &optional parameters)
-  "Make a frame on terminal DEVICE which is of type TYPE (e.g., \"xterm\").
-The optional third argument PARAMETERS specifies additional frame parameters."
+(defun make-frame-on-tty (tty type &optional parameters)
+  "Make a frame on terminal device TTY.
+TTY should be the file name of the tty device to use.  TYPE
+should be the terminal type string of TTY, for example \"xterm\"
+or \"vt100\".  The optional third argument PARAMETERS specifies
+additional frame parameters."
   (interactive "fOpen frame on tty device: \nsTerminal type of %s: ")
-  (unless device
+  (unless tty
     (error "Invalid terminal device"))
   (unless type
     (error "Invalid terminal type"))
-  (make-frame `((window-system . nil) (tty . ,device) (tty-type . ,type) . ,parameters)))
+  (make-frame `((window-system . nil) (tty . ,tty) (tty-type . ,type) . ,parameters)))
 
 (defun make-frame-command ()
   "Make a new frame, and select it if the terminal displays only one frame."
@@ -648,7 +668,7 @@ You cannot specify either `width' or `height', you must use neither or both.
  (window-system . nil) The frame should be displayed on a terminal device.
  (window-system . x)   The frame should be displayed in an X window.
 
- (device . ID)          The frame should use the display device identified by ID.
+ (terminal . ID)          The frame should use the terminal identified by ID.
 
 Before the frame is created (via `frame-creation-function-alist'), functions on the
 hook `before-make-frame-hook' are run.  After the frame is created, functions
@@ -661,22 +681,33 @@ instance if the frame appears under the mouse pointer and your
 setup is for focus to follow the pointer."
   (interactive)
   (let* ((w (cond
-            ((assq 'device parameters)
-             (let ((type (display-live-p (cdr (assq 'device parameters)))))
+            ((assq 'terminal parameters)
+             (let ((type (terminal-live-p (cdr (assq 'terminal parameters)))))
                (cond
                 ((eq type t) nil)
-                ((eq type nil) (error "Display %s does not exist" (cdr (assq 'device parameters))))
+                ((eq type nil) (error "Terminal %s does not exist" (cdr (assq 'terminal parameters))))
                 (t type))))
             ((assq 'window-system parameters)
              (cdr (assq 'window-system parameters)))
             (t window-system)))
         (frame-creation-function (cdr (assq w frame-creation-function-alist)))
+        (oldframe (selected-frame))
         frame)
     (unless frame-creation-function
       (error "Don't know how to create a frame on window system %s" w))
     (run-hooks 'before-make-frame-hook)
     (setq frame (funcall frame-creation-function (append parameters (cdr (assq w window-system-default-frame-alist)))))
     (normal-erase-is-backspace-setup-frame frame)
+    ;; Inherit the 'environment and 'client parameters, if needed.
+    (when (eq (frame-terminal frame) (frame-terminal oldframe))
+      (let ((env (frame-parameter oldframe 'environment))
+           (client (frame-parameter oldframe 'client)))
+       (if (not (framep env))
+           (setq env oldframe))
+       (if (and env (not (assq 'environment parameters)))
+           (set-frame-parameter frame 'environment env))
+       (if (and client (not (assq 'client parameters)))
+           (set-frame-parameter frame 'client client))))
     (run-hook-with-args 'after-make-frame-functions frame)
     frame))
 
@@ -696,28 +727,29 @@ setup is for focus to follow the pointer."
    (function (lambda (frame)
               (eq frame (window-frame (minibuffer-window frame)))))))
 
-(defun frames-on-display-list (&optional display)
-  "Return a list of all frames on DISPLAY.
+(defun frames-on-display-list (&optional terminal)
+  "Return a list of all frames on TERMINAL.
 
-DISPLAY should be a display identifier (an integer), but it may
-also be a name of a display, a string of the form HOST:SERVER.SCREEN.
+TERMINAL should be a terminal identifier (an integer), a frame,
+or a name of an X display (a string of the form
+HOST:SERVER.SCREEN).
 
-If DISPLAY is omitted or nil, it defaults to the selected frame's display."
-  (let* ((display (or display (frame-display)))
+If TERMINAL is omitted or nil, it defaults to the selected
+frame's terminal device."
+  (let* ((terminal (terminal-id terminal))
         (func #'(lambda (frame)
-                  (or (eq (frame-display frame) display)
-                      (equal (frame-parameter frame 'display) display)))))
+                  (eq (frame-terminal frame) terminal))))
     (filtered-frame-list func)))
 
-(defun framep-on-display (&optional display)
-  "Return the type of frames on DISPLAY.
-DISPLAY may be a display id, a display name or a frame.  If it is
-a frame, its type is returned.
-If DISPLAY is omitted or nil, it defaults to the selected frame's display.
-All frames on a given display are of the same type."
-  (or (display-live-p display)
-      (framep display)
-      (framep (car (frames-on-display-list display)))))
+(defun framep-on-display (&optional terminal)
+  "Return the type of frames on TERMINAL.
+TERMINAL may be a terminal id, a display name or a frame.  If it
+is a frame, its type is returned.  If TERMINAL is omitted or nil,
+it defaults to the selected frame's terminal device.  All frames
+on a given display are of the same type."
+  (or (terminal-live-p terminal)
+      (framep terminal)
+      (framep (car (frames-on-display-list terminal)))))
 
 (defun frame-remove-geometry-params (param-list)
   "Return the parameter list PARAM-LIST, but with geometry specs removed.
@@ -754,7 +786,7 @@ automatically."
     (select-frame frame)
     (raise-frame frame)
     ;; Ensure, if possible, that frame gets input focus.
-    (cond ((eq (window-system frame) 'x)
+    (cond ((memq (window-system frame) '(x max))
           (x-focus-frame frame))
          ((eq (window-system frame) 'w32)
           (w32-focus-frame frame)))
@@ -795,20 +827,19 @@ Otherwise, that variable should be nil."
 
 (defun suspend-frame ()
   "Do whatever is right to suspend the current frame.
-Calls `suspend-emacs' if invoked from the controlling terminal,
-`suspend-tty' from a secondary terminal, and
+Calls `suspend-emacs' if invoked from the controlling tty device,
+`suspend-tty' from a secondary tty device, and
 `iconify-or-deiconify-frame' from an X frame."
   (interactive)
   (let ((type (framep (selected-frame))))
     (cond
      ((eq type 'x) (iconify-or-deiconify-frame))
      ((eq type t)
-      (if (display-controlling-tty-p)
+      (if (controlling-tty-p)
          (suspend-emacs)
        (suspend-tty)))
      (t (suspend-emacs)))))
 
-
 (defun make-frame-names-alist ()
   (let* ((current-frame (selected-frame))
         (falist
@@ -952,13 +983,16 @@ pixels) is kept by adjusting the numbers of the lines and columns."
   (run-hooks 'after-setting-font-hook 'after-setting-font-hooks))
 
 (defun set-frame-parameter (frame parameter value)
+  "Set frame parameter PARAMETER to VALUE on FRAME.
+If FRAME is nil, it defaults to the selected frame.
+See `modify-frame-parameters.'"
   (modify-frame-parameters frame (list (cons parameter value))))
 
 (defun set-background-color (color-name)
   "Set the background color of the selected frame to COLOR-NAME.
 When called interactively, prompt for the name of the color to use.
 To get the frame's current background color, use `frame-parameters'."
-  (interactive (list (facemenu-read-color)))
+  (interactive (list (facemenu-read-color "Background color: ")))
   (modify-frame-parameters (selected-frame)
                           (list (cons 'background-color color-name)))
   (or window-system
@@ -968,7 +1002,7 @@ To get the frame's current background color, use `frame-parameters'."
   "Set the foreground color of the selected frame to COLOR-NAME.
 When called interactively, prompt for the name of the color to use.
 To get the frame's current foreground color, use `frame-parameters'."
-  (interactive (list (facemenu-read-color)))
+  (interactive (list (facemenu-read-color "Foreground color: ")))
   (modify-frame-parameters (selected-frame)
                           (list (cons 'foreground-color color-name)))
   (or window-system
@@ -978,7 +1012,7 @@ To get the frame's current foreground color, use `frame-parameters'."
   "Set the text cursor color of the selected frame to COLOR-NAME.
 When called interactively, prompt for the name of the color to use.
 To get the frame's current cursor color, use `frame-parameters'."
-  (interactive (list (facemenu-read-color)))
+  (interactive (list (facemenu-read-color "Cursor color: ")))
   (modify-frame-parameters (selected-frame)
                           (list (cons 'cursor-color color-name))))
 
@@ -986,7 +1020,7 @@ To get the frame's current cursor color, use `frame-parameters'."
   "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
 When called interactively, prompt for the name of the color to use.
 To get the frame's current mouse color, use `frame-parameters'."
-  (interactive (list (facemenu-read-color)))
+  (interactive (list (facemenu-read-color "Mouse color: ")))
   (modify-frame-parameters (selected-frame)
                           (list (cons 'mouse-color
                                       (or color-name
@@ -997,7 +1031,7 @@ To get the frame's current mouse color, use `frame-parameters'."
   "Set the color of the border of the selected frame to COLOR-NAME.
 When called interactively, prompt for the name of the color to use.
 To get the frame's current border color, use `frame-parameters'."
-  (interactive (list (facemenu-read-color)))
+  (interactive (list (facemenu-read-color "Border color: ")))
   (modify-frame-parameters (selected-frame)
                           (list (cons 'border-color color-name))))
 
@@ -1054,9 +1088,9 @@ bars (top, bottom, or nil)."
     (cons vert hor)))
 \f
 ;;;; Frame/display capabilities.
-(defun selected-display ()
-  "Return the display that is now selected."
-  (frame-display (selected-frame)))
+(defun selected-terminal ()
+  "Return the terminal that is now selected."
+  (frame-terminal (selected-frame)))
 
 (defun display-mouse-p (&optional display)
   "Return non-nil if DISPLAY has a mouse available.
@@ -1132,9 +1166,9 @@ frame's display)."
   "Return the number of screens associated with DISPLAY."
   (let ((frame-type (framep-on-display display)))
     (cond
-     ((memq frame-type '(x w32))
+     ((memq frame-type '(x w32 mac))
       (x-display-screens display))
-     (t        ;; FIXME: is this correct for the Mac?
+     (t
       1))))
 
 (defun display-pixel-height (&optional display)
@@ -1279,7 +1313,6 @@ left untouched.  FRAME nil or omitted means use the selected frame."
 (defcustom show-trailing-whitespace nil
   "*Non-nil means highlight trailing whitespace.
 This is done in the face `trailing-whitespace'."
-  :tag "Highlight trailing whitespace."
   :type 'boolean
   :group 'whitespace-faces)
 
@@ -1311,13 +1344,11 @@ point visible."
 
 (defcustom blink-cursor-delay 0.5
   "*Seconds of idle time after which cursor starts to blink."
-  :tag "Delay in seconds."
   :type 'number
   :group 'cursor)
 
 (defcustom blink-cursor-interval 0.5
   "*Length of cursor blink interval in seconds."
-  :tag "Blink interval in seconds."
   :type 'number
   :group 'cursor)
 
@@ -1342,7 +1373,7 @@ cursor display.  On a text-only terminal, this is not implemented."
   :init-value (not (or noninteractive
                       no-blinking-cursor
                       (eq system-type 'ms-dos)
-                      (not (memq initial-window-system '(x w32)))))
+                      (not (memq initial-window-system '(x w32 mac)))))
   :initialize 'custom-initialize-safe-default
   :group 'cursor
   :global t
@@ -1393,14 +1424,14 @@ itself as a pre-command hook."
 ;; Hourglass pointer
 
 (defcustom display-hourglass t
-  "*Non-nil means show an hourglass pointer when running under a window system."
-  :tag "Hourglass pointer"
+  "*Non-nil means show an hourglass pointer, when Emacs is busy.
+This feature only works when on a window system that can change
+cursor shapes."
   :type 'boolean
   :group 'cursor)
 
 (defcustom hourglass-delay 1
-  "*Seconds to wait before displaying an hourglass pointer."
-  :tag "Hourglass delay"
+  "*Seconds to wait before displaying an hourglass pointer when Emacs is busy."
   :type 'number
   :group 'cursor)
 
@@ -1409,7 +1440,7 @@ itself as a pre-command hook."
   "*Non-nil means show a hollow box cursor in non-selected windows.
 If nil, don't show a cursor except in the selected window.
 Use Custom to set this variable to get the display updated."
-  :tag "Cursor in non-selected windows"
+  :tag "Cursor In Non-selected Windows"
   :type 'boolean
   :group 'cursor
   :set #'(lambda (symbol value)
@@ -1424,82 +1455,6 @@ Use Custom to set this variable to get the display updated."
 (define-key ctl-x-5-map "0" 'delete-frame)
 (define-key ctl-x-5-map "o" 'other-frame)
 
-(substitute-key-definition 'suspend-emacs 'suspend-frame global-map)
-
-
-(defun terminal-id (terminal)
-  "Return the numerical id of terminal TERMINAL.
-
-TERMINAL can be a terminal id, a frame, or nil (meaning the
-selected frame's terminal)."
-  (cond
-   ((integerp terminal)
-    terminal)
-   ((or (null terminal) (framep terminal))
-    (frame-display terminal))
-   (t
-    (error "Invalid argument %s in `terminal-id'" terminal))))
-
-(defvar terminal-parameter-alist nil
-  "An alist of terminal parameter alists.")
-
-(defun terminal-parameters (&optional terminal)
-  "Return the paramater-alist of terminal TERMINAL.
-It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
-
-TERMINAL can be a terminal id, a frame, or nil (meaning the
-selected frame's terminal)."
-  (cdr (assq (terminal-id terminal) terminal-parameter-alist)))
-
-(defun terminal-parameter-p (terminal parameter)
-  "Return non-nil if PARAMETER is a terminal parameter on TERMINAL.
-
-The actual value returned in that case is a cell (PARAMETER . VALUE),
-where VALUE is the current value of PARAMETER.
-
-TERMINAL can be a terminal id, a frame, or nil (meaning the
-selected frame's terminal)."
-  (assq parameter (cdr (assq (terminal-id terminal) terminal-parameter-alist))))
-
-(defun terminal-parameter (terminal parameter)
-  "Return TERMINAL's value for parameter PARAMETER.
-
-TERMINAL can be a terminal id, a frame, or nil (meaning the
-selected frame's terminal)."
-  (cdr (terminal-parameter-p terminal parameter)))
-
-(defun set-terminal-parameter (terminal parameter value)
-  "Set TERMINAL's value for parameter PARAMETER to VALUE.
-Returns the previous value of PARAMETER.
-
-TERMINAL can be a terminal id, a frame, or nil (meaning the
-selected frame's terminal)."
-  (setq terminal (terminal-id terminal))
-  (let* ((alist (assq terminal terminal-parameter-alist))
-        (pair (assq parameter (cdr alist)))
-        (result (cdr pair)))
-    (cond
-     (pair (setcdr pair value))
-     (alist (setcdr alist (cons (cons parameter value) (cdr alist))))
-     (t (setq terminal-parameter-alist
-             (cons (cons terminal
-                         (cons (cons parameter value)
-                               nil))
-                   terminal-parameter-alist))))
-    result))
-
-(defun terminal-handle-delete-frame (frame)
-  "Clean up terminal parameters of FRAME, if it's the last frame on its terminal."
-  ;; XXX We assume that the display is closed immediately after the
-  ;; last frame is deleted on it.  It would be better to create a hook
-  ;; called `delete-display-functions', and use it instead.
-  (when (and (frame-live-p frame)
-            (= 1 (length (frames-on-display-list (frame-display frame)))))
-    (setq terminal-parameter-alist
-         (assq-delete-all (frame-display frame) terminal-parameter-alist))))
-
-(add-hook 'delete-frame-functions 'terminal-handle-delete-frame)
-
 (provide 'frame)
 
 ;; arch-tag: 82979c70-b8f2-4306-b2ad-ddbd6b328b56