]> code.delx.au - gnu-emacs/blobdiff - lisp/frame.el
(timezone-parse-date): Match forms 1 and 2 first.
[gnu-emacs] / lisp / frame.el
index 87a898d51e56ea899602cc334dbd7de2cc408d76..b08fdc2c4b5b43b85435a5dcc8b1ddfa9421a626 100644 (file)
@@ -1,25 +1,26 @@
 ;;; frame.el --- multi-frame management independent of window systems.
 
-;;;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: internal
 
-;;; This file is part of GNU Emacs.
-;;;
-;;; GNU Emacs is free software; you can redistribute it and/or modify
-;;; it under the terms of the GNU General Public License as published by
-;;; the Free Software Foundation; either version 2, or (at your option)
-;;; any later version.
-;;;
-;;; GNU Emacs is distributed in the hope that it will be useful,
-;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-;;; GNU General Public License for more details.
-;;;
-;;; You should have received a copy of the GNU General Public License
-;;; along with GNU Emacs; see the file COPYING.  If not, write to
-;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
 
 ;;; Code:
 
 The window system startup file should set this to its frame creation
 function, which should take an alist of parameters as its argument.")
 
-;;; The initial value given here for this must ask for a minibuffer.
-;;; There must always exist a frame with a minibuffer, and after we
-;;; delete the terminal frame, this will be the only frame.
-(defvar initial-frame-alist '((minibuffer . t))
+;;; The initial value given here for used to ask for a minibuffer.
+;;; But that's not necessary, because the default is to have one.
+;;; By not specifying it here, we let an X resource specify it.
+(defvar initial-frame-alist nil
   "Alist of frame parameters for creating the initial X window frame.
 You can set this in your `.emacs' file; for example,
  (setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55)))
@@ -117,7 +118,8 @@ These supersede the values given in `default-frame-alist'.")
       (setq tail (cdr tail)))
     (if (> i 0)
        (delete-frame frame t)
-      (kill-emacs))))
+      ;; Gildea@x.org says it is ok to ask questions before terminating.
+      (save-buffers-kill-emacs))))
 \f
 ;;;; Arrangement of frames at startup
 
@@ -150,7 +152,7 @@ These supersede the values given in `default-frame-alist'.")
 (defun frame-initialize ()
 
   ;; Are we actually running under a window system at all?
-  (if (and window-system (not noninteractive))
+  (if (and window-system (not noninteractive) (not (eq window-system 'pc)))
       (progn
        ;; Turn on special-display processing only if there's a window system.
        (setq special-display-function 'special-display-popup-frame)
@@ -189,13 +191,14 @@ These supersede the values given in `default-frame-alist'.")
 
     ;; No, we're not running a window system.  Use make-terminal-frame if
     ;; we support that feature, otherwise arrange to cause errors.
-    (setq frame-creation-function
-         (if (fboundp 'make-terminal-frame)
-             'make-terminal-frame
-           (function
-            (lambda (parameters)
-              (error
-               "Can't create multiple frames without a window system")))))))
+    (or (eq window-system 'pc)
+       (setq frame-creation-function
+             (if (fboundp 'make-terminal-frame)
+                 'make-terminal-frame
+               (function
+                (lambda (parameters)
+                  (error
+                   "Can't create multiple frames without a window system"))))))))
 
 ;;; startup.el calls this function after loading the user's init
 ;;; file.  Now default-frame-alist and initial-frame-alist contain
@@ -246,9 +249,13 @@ These supersede the values given in `default-frame-alist'.")
              (while (not (cdr (assq 'visibility
                                     (frame-parameters frame-initial-frame))))
                (sleep-for 1))
+             (setq parms (frame-parameters frame-initial-frame))
+             ;; Get rid of `name' unless it was specified explicitly before.
+             (or (assq 'name frame-initial-frame-alist)
+                 (setq parms (delq (assq 'name parms) parms)))
              (setq parms (append initial-frame-alist
                                  default-frame-alist
-                                 (frame-parameters frame-initial-frame)
+                                 parms
                                  nil))
              ;; Get rid of `reverse', because that was handled
              ;; when we first made the frame.
@@ -272,8 +279,7 @@ These supersede the values given in `default-frame-alist'.")
              ;; the only frame with a minibuffer.  If it is, create a
              ;; new one.
              (or (delq frame-initial-frame (minibuffer-frame-list))
-                 (make-frame (append minibuffer-frame-alist
-                                    '((minibuffer . only)))))
+                 (make-initial-minibuffer-frame nil))
 
              ;; If the initial frame is serving as a surrogate
              ;; minibuffer frame for any frames, we need to wean them
@@ -364,6 +370,12 @@ These supersede the values given in `default-frame-alist'.")
     ;; Make sure frame-notice-user-settings does nothing if called twice.
     (setq frame-initial-frame nil)))
 
+(defun make-initial-minibuffer-frame (display)
+  (let ((parms (append minibuffer-frame-alist '((minibuffer . only)))))
+    (if display
+       (make-frame-on-display display parms)
+      (make-frame parms))))
+
 ;; Delete from ALIST all elements whose car is KEY.
 ;; Return the modified alist.
 (defun frame-delete-all (key alist)
@@ -406,37 +418,48 @@ The optional second argument PARAMETERS specifies additional frame parameters."
   (interactive "sMake frame on display: ")
   (make-frame (cons (cons 'display display) parameters)))
 
+(defun make-frame-command ()
+  "Make a new frame, and select it if the terminal displays only one frame."
+  (interactive)
+  (if (and window-system (not (eq window-system 'pc)))
+      (make-frame)
+    (select-frame (make-frame))))
+
+(defvar before-make-frame-hook nil
+  "Functions to run before a frame is created.")
+
+(defvar after-make-frame-functions nil
+  "Functions to run after a frame is created.
+The functions are run with one arg, the newly created frame.")
+
 ;; Alias, kept temporarily.
 (defalias 'new-frame 'make-frame)
-(defun make-frame (&optional parameters)
-  "Create a new frame, displaying the current buffer.
 
-Optional argument PARAMETERS is an alist of parameters for the new
-frame.  Specifically, PARAMETERS is a list of pairs, each having
-the form (NAME . VALUE).
+(defun make-frame (&optional parameters)
+  "Return a newly created frame displaying the current buffer.
+Optional argument PARAMETERS is an alist of parameters for the new frame.
+Each element of PARAMETERS should have the form (NAME . VALUE), for example:
 
-Here are some of the parameters allowed (not a complete list):
+ (name . STRING)       The frame should be named STRING.
 
-\(name . STRING)       - The frame should be named STRING.
+ (width . NUMBER)      The frame should be NUMBER characters in width.
+ (height . NUMBER)     The frame should be NUMBER text lines high.
 
-\(height . NUMBER) - The frame should be NUMBER text lines high.  If
-       this parameter is present, the width parameter must also be
-       given.
+You cannot specify either `width' or `height', you must use neither or both.
 
-\(width . NUMBER) - The frame should be NUMBER characters in width.
-       If this parameter is present, the height parameter must also
-       be given.
+ (minibuffer . t)      The frame should have a minibuffer.
+ (minibuffer . nil)    The frame should have no minibuffer.
+ (minibuffer . only)   The frame should contain only a minibuffer.
+ (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
 
-\(minibuffer . t) - the frame should have a minibuffer
-\(minibuffer . nil) - the frame should have no minibuffer
-\(minibuffer . only) - the frame should contain only a minibuffer
-\(minibuffer . WINDOW) - the frame should use WINDOW as its minibuffer window."
+Before the frame is created (via `frame-creation-function'), functions on the
+hook `before-make-frame-hook' are run.  After the frame is created, functions
+on `after-make-frame-functions' are run with one arg, the newly created frame."
   (interactive)
-  (let ((nframe))
-    (run-hooks 'before-make-frame-hook)
-    (setq nframe (funcall frame-creation-function parameters))
-    (run-hooks 'after-make-frame-hook)
-    nframe))
+  (run-hooks 'before-make-frame-hook)
+  (let ((frame (funcall frame-creation-function parameters)))
+    (run-hook-with-args 'after-make-frame-functions frame)
+    frame))
 
 (defun filtered-frame-list (predicate)
   "Return a list of all live frames which satisfy PREDICATE."
@@ -495,9 +518,7 @@ A negative ARG moves in the opposite order."
       (setq arg (1+ arg)))
     (raise-frame frame)
     (select-frame frame)
-    (set-mouse-position (selected-frame) (1- (frame-width)) 0)
-    (if (fboundp 'unfocus-frame)
-       (unfocus-frame))))
+    (set-mouse-position (selected-frame) (1- (frame-width)) 0)))
 \f
 ;;;; Frame configurations
 
@@ -552,18 +573,15 @@ is given and non-nil, the unwanted frames are iconified instead."
        ;; for where to put it.
        (mapcar 'iconify-frame frames-to-delete)
       (mapcar 'delete-frame frames-to-delete))))
-
-(defun frame-configuration-p (object)
-  "Return non-nil if OBJECT seems to be a frame configuration.
-Any list whose car is `frame-configuration' is assumed to be a frame
-configuration."
-  (and (consp object)
-       (eq (car object) 'frame-configuration)))
-
 \f
 ;;;; Convenience functions for accessing and interactively changing
 ;;;; frame parameters.
 
+(defun frame-parameter (frame parameter)
+  "Return FRAME's value for parameter PARAMETER.
+If FRAME is omitted, describe the currently selected frame."
+  (cdr (assq parameter (frame-parameters frame))))
+
 (defun frame-height (&optional frame)
   "Return number of lines available for display on FRAME.
 If FRAME is omitted, describe the currently selected frame."
@@ -574,9 +592,11 @@ If FRAME is omitted, describe the currently selected frame."
 If FRAME is omitted, describe the currently selected frame."
   (cdr (assq 'width (frame-parameters frame))))
 
-(defun set-default-font (font-name)
+(defalias 'set-default-font 'set-frame-font)
+(defun set-frame-font (font-name)
   "Set the font of the selected frame to FONT.
-When called interactively, prompt for the name of the font to use."
+When called interactively, prompt for the name of the font to use.
+To get the frame's current default font, use `frame-parameters'."
   (interactive "sFont name: ")
   (modify-frame-parameters (selected-frame)
                           (list (cons 'font font-name)))
@@ -585,7 +605,8 @@ When called interactively, prompt for the name of the font to use."
 
 (defun set-background-color (color-name)
   "Set the background color of the selected frame to COLOR.
-When called interactively, prompt for the name of the color to use."
+When called interactively, prompt for the name of the color to use.
+To get the frame's current background color, use `frame-parameters'."
   (interactive "sColor: ")
   (modify-frame-parameters (selected-frame)
                           (list (cons 'background-color color-name)))
@@ -593,7 +614,8 @@ When called interactively, prompt for the name of the color to use."
 
 (defun set-foreground-color (color-name)
   "Set the foreground color of the selected frame to COLOR.
-When called interactively, prompt for the name of the color to use."
+When called interactively, prompt for the name of the color to use.
+To get the frame's current foreground color, use `frame-parameters'."
   (interactive "sColor: ")
   (modify-frame-parameters (selected-frame)
                           (list (cons 'foreground-color color-name)))
@@ -601,21 +623,24 @@ When called interactively, prompt for the name of the color to use."
 
 (defun set-cursor-color (color-name)
   "Set the text cursor color of the selected frame to COLOR.
-When called interactively, prompt for the name of the color to use."
+When called interactively, prompt for the name of the color to use.
+To get the frame's current cursor color, use `frame-parameters'."
   (interactive "sColor: ")
   (modify-frame-parameters (selected-frame)
                           (list (cons 'cursor-color color-name))))
 
 (defun set-mouse-color (color-name)
   "Set the color of the mouse pointer of the selected frame to COLOR.
-When called interactively, prompt for the name of the color to use."
+When called interactively, prompt for the name of the color to use.
+To get the frame's current mouse color, use `frame-parameters'."
   (interactive "sColor: ")
   (modify-frame-parameters (selected-frame)
                           (list (cons 'mouse-color color-name))))
 
 (defun set-border-color (color-name)
   "Set the color of the border of the selected frame to COLOR.
-When called interactively, prompt for the name of the color to use."
+When called interactively, prompt for the name of the color to use.
+To get the frame's current border color, use `frame-parameters'."
   (interactive "sColor: ")
   (modify-frame-parameters (selected-frame)
                           (list (cons 'border-color color-name))))
@@ -650,6 +675,9 @@ that is beyond the control of Emacs and this command has no effect on it."
   (modify-frame-parameters (selected-frame)
                           (list (cons 'auto-lower (> arg 0)))))
 
+(defvar scroll-bar-side 'left
+  "*Specify which side scroll bars should be on.  Value is `left' or `right'.")
+
 (defun toggle-scroll-bar (arg)
   "Toggle whether or not the selected frame has vertical scroll bars.
 With arg, turn vertical scroll bars on if and only if arg is positive."
@@ -660,7 +688,9 @@ With arg, turn vertical scroll bars on if and only if arg is positive."
                           (frame-parameters (selected-frame))))
                -1 1)))
   (modify-frame-parameters (selected-frame)
-                          (list (cons 'vertical-scroll-bars (> arg 0)))))
+                          (list (cons 'vertical-scroll-bars
+                                      (if (> arg 0)
+                                          scroll-bar-side)))))
 
 (defun toggle-horizontal-scroll-bar (arg)
   "Toggle whether or not the selected frame has horizontal scroll bars.
@@ -687,7 +717,7 @@ should use `set-frame-width instead'."
 Optional second arg non-nil means that redisplay should use LINES lines\n\
 but that the idea of the actual height of the screen should not be changed.\n\
 This function is provided only for compatibility with Emacs 18; new code\n\
-should use `set-frame-width' instead."
+should use `set-frame-height' instead."
   (set-frame-height (selected-frame) lines pretend))
 
 (make-obsolete 'screen-height 'frame-height)
@@ -697,12 +727,8 @@ should use `set-frame-width' instead."
 
 \f
 ;;;; Key bindings
-(defvar ctl-x-5-map (make-sparse-keymap)
-  "Keymap for frame commands.")
-(defalias 'ctl-x-5-prefix ctl-x-5-map)
-(define-key ctl-x-map "5" 'ctl-x-5-prefix)
 
-(define-key ctl-x-5-map "2" 'make-frame)
+(define-key ctl-x-5-map "2" 'make-frame-command)
 (define-key ctl-x-5-map "0" 'delete-frame)
 (define-key ctl-x-5-map "o" 'other-frame)