1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-27 07:37:33 +00:00
emacs/lisp/frame.el

333 lines
11 KiB
EmacsLisp
Raw Normal View History

1992-07-15 00:32:19 +00:00
;;; frame.el --- multi-frame management independent of window systems.
1992-05-30 21:11:25 +00:00
1992-07-16 07:28:05 +00:00
;; Maintainer: FSF
;; Last-Modified: 09 Jul 92
1992-03-16 20:39:07 +00:00
;;;; Copyright (C) 1990, 1992 Free Software Foundation, Inc.
1991-08-15 21:29:06 +00:00
;;; 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 1, 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.
1992-07-16 07:28:05 +00:00
;;; Code:
1992-07-15 00:32:19 +00:00
(defvar frame-creation-function nil
"Window-system dependent function to call to create a new frame.
The window system startup file should set this to its frame creation
1991-08-15 21:29:06 +00:00
function, which should take an alist of parameters as its argument.")
;;; The default value for this must ask for a minibuffer. There must
1992-07-15 00:32:19 +00:00
;;; 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 . nil))
"Alist of values used when creating the initial emacs text frame.
1991-08-15 21:29:06 +00:00
These may be set in your init file, like this:
1992-07-15 00:32:19 +00:00
(setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55)))
These supercede the values given in frame-default-alist.")
1991-08-15 21:29:06 +00:00
1992-07-15 00:32:19 +00:00
(defvar minibuffer-frame-alist nil
"Alist of values to apply to a minibuffer frame.
1991-08-15 21:29:06 +00:00
These may be set in your init file, like this:
1992-07-15 00:32:19 +00:00
(setq minibuffer-frame-alist
1991-08-15 21:29:06 +00:00
'((top . 1) (left . 1) (width . 80) (height . 1)))
1992-07-15 00:32:19 +00:00
These supercede the values given in default-frame-alist.")
1991-08-15 21:29:06 +00:00
1992-07-15 00:32:19 +00:00
(defvar pop-up-frame-alist nil
"Alist of values used when creating pop-up frames.
Pop-up frames are used for completions, help, and the like.
1991-08-15 21:29:06 +00:00
This variable can be set in your init file, like this:
1992-07-15 00:32:19 +00:00
(setq pop-up-frame-alist '((width . 80) (height . 20)))
These supercede the values given in default-frame-alist.")
1991-08-15 21:29:06 +00:00
1992-07-15 00:32:19 +00:00
(setq pop-up-frame-function
1991-08-15 21:29:06 +00:00
(function (lambda ()
1992-07-15 00:32:19 +00:00
(new-frame pop-up-frame-alist))))
1991-08-15 21:29:06 +00:00
1992-07-15 00:32:19 +00:00
;;;; Arrangement of frames at startup
1991-08-15 21:29:06 +00:00
;;; 1) Load the window system startup file from the lisp library and read the
;;; high-priority arguments (-q and the like). The window system startup
1992-07-15 00:32:19 +00:00
;;; file should create any frames specified in the window system defaults.
1991-08-15 21:29:06 +00:00
;;;
1992-07-15 00:32:19 +00:00
;;; 2) If no frames have been opened, we open an initial text frame.
1991-08-15 21:29:06 +00:00
;;;
;;; 3) Once the init file is done, we apply any newly set parameters
1992-07-15 00:32:19 +00:00
;;; in initial-frame-alist to the frame.
1991-08-15 21:29:06 +00:00
1992-07-15 00:32:19 +00:00
(add-hook 'before-init-hook 'frame-initialize)
(add-hook 'window-setup-hook 'frame-notice-user-settings)
1991-08-15 21:29:06 +00:00
1992-07-15 00:32:19 +00:00
;;; If we create the initial frame, this is it.
(defvar frame-initial-frame nil)
1991-08-15 21:29:06 +00:00
;;; startup.el calls this function before loading the user's init
1992-07-15 00:32:19 +00:00
;;; file - if there is no frame with a minibuffer open now, create
1991-08-15 21:29:06 +00:00
;;; one to display messages while loading the init file.
1992-07-15 00:32:19 +00:00
(defun frame-initialize ()
1991-08-15 21:29:06 +00:00
;; Are we actually running under a window system at all?
(if (and window-system (not noninteractive))
1992-07-15 00:32:19 +00:00
(let ((frames (frame-list)))
1991-08-15 21:29:06 +00:00
1992-07-15 00:32:19 +00:00
;; Look for a frame that has a minibuffer.
(while (and frames
(or (eq (car frames) terminal-frame)
1991-08-15 21:29:06 +00:00
(not (cdr (assq 'minibuffer
1992-07-15 00:32:19 +00:00
(frame-parameters
(car frames)))))))
(setq frames (cdr frames)))
;; If there was none, then we need to create the opening frame.
(or frames
(setq default-minibuffer-frame
(setq frame-initial-frame
(new-frame initial-frame-alist))))
1991-08-15 21:29:06 +00:00
1992-07-15 00:32:19 +00:00
;; At this point, we know that we have a frame open, so we
;; can delete the terminal frame.
(delete-frame terminal-frame)
(setq terminal-frame nil))
1991-08-15 21:29:06 +00:00
;; No, we're not running a window system. Arrange to cause errors.
1992-07-15 00:32:19 +00:00
(setq frame-creation-function
1991-08-20 20:21:23 +00:00
(function
(lambda (parameters)
(error
1992-07-15 00:32:19 +00:00
"Can't create multiple frames without a window system."))))))
1991-08-15 21:29:06 +00:00
;;; startup.el calls this function after loading the user's init file.
;;; If we created a minibuffer before knowing if we had permission, we
1992-07-15 00:32:19 +00:00
;;; need to see if it should go away or change. Create a text frame
1991-08-15 21:29:06 +00:00
;;; here.
1992-07-15 00:32:19 +00:00
(defun frame-notice-user-settings ()
(if frame-initial-frame
1991-08-15 21:29:06 +00:00
(progn
1992-07-15 00:32:19 +00:00
;; If the user wants a minibuffer-only frame, we'll have to
1991-08-15 21:29:06 +00:00
;; make a new one; you can't remove or add a root window to/from
1992-07-15 00:32:19 +00:00
;; an existing frame.
(if (eq (cdr (or (assq 'minibuffer initial-frame-alist)
1991-08-15 21:29:06 +00:00
'(minibuffer . t)))
'only)
(progn
1992-07-15 00:32:19 +00:00
(setq default-minibuffer-frame
(new-frame
(append initial-frame-alist
(frame-parameters frame-initial-frame))))
(delete-frame frame-initial-frame))
(modify-frame-parameters frame-initial-frame
initial-frame-alist))))
1991-08-15 21:29:06 +00:00
1992-07-15 00:32:19 +00:00
;; Make sure the initial frame can be GC'd if it is ever deleted.
(makunbound 'frame-initial-frame))
1991-08-15 21:29:06 +00:00
1992-07-15 00:32:19 +00:00
;;;; Creation of additional frames
;;; Return some frame other than the current frame,
;;; creating one if neccessary. Note that the minibuffer frame, if
;;; separate, is not considered (see next-frame).
(defun get-frame ()
(let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
(new-frame)
(next-frame (selected-frame)))))
1991-08-15 21:29:06 +00:00
s))
1992-07-15 00:32:19 +00:00
(defun next-multiframe-window ()
"Select the next window, regardless of which frame it is on."
1991-08-15 21:29:06 +00:00
(interactive)
(select-window (next-window (selected-window)
(> (minibuffer-depth) 0)
t)))
1992-07-15 00:32:19 +00:00
(defun previous-multiframe-window ()
"Select the previous window, regardless of which frame it is on."
1991-08-15 21:29:06 +00:00
(interactive)
(select-window (previous-window (selected-window)
(> (minibuffer-depth) 0)
t)))
1992-07-15 00:32:19 +00:00
(defun new-frame (&optional parameters)
"Create a new frame, displaying the current buffer.
1992-02-06 02:09:14 +00:00
1992-02-10 05:20:54 +00:00
Optional argument PARAMETERS is an alist of parameters for the new
1992-07-15 00:32:19 +00:00
frame. Specifically, PARAMETERS is a list of pairs, each having one
1992-02-10 05:20:54 +00:00
of the following forms:
1992-07-15 00:32:19 +00:00
(name . STRING) - The frame should be named STRING.
1992-02-10 05:20:54 +00:00
1992-07-15 00:32:19 +00:00
(height . NUMBER) - The frame should be NUMBER text lines high. If
1992-02-10 05:20:54 +00:00
this parameter is present, the width parameter must also be
given.
1992-07-15 00:32:19 +00:00
(width . NUMBER) - The frame should be NUMBER characters in width.
1992-02-10 05:20:54 +00:00
If this parameter is present, the height parameter must also
be given.
1992-07-15 00:32:19 +00:00
(minibuffer . t) - the frame should have a minibuffer
(minibuffer . none) - 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.
1992-02-10 05:20:54 +00:00
(NAME . VALUE), specifying the parameter and the value it should have.
NAME should be one of the following symbols:
name VALUE
1992-07-15 00:32:19 +00:00
The documentation for the function x-create-frame describes
additional frame parameters that Emacs will recognize when running
1992-02-10 05:20:54 +00:00
under the X Window System."
1991-08-15 21:29:06 +00:00
(interactive)
1992-07-15 00:32:19 +00:00
(funcall frame-creation-function parameters))
1991-08-15 21:29:06 +00:00
;;;; Iconification
;;; A possible enhancement for the below: if you iconify a surrogate
1992-07-15 00:32:19 +00:00
;;; minibuffer frame, iconify all of its minibuffer's users too;
;;; de-iconify them as a group. This will need to wait until frames
1991-08-15 21:29:06 +00:00
;;; have mapping and unmapping hooks.
(defun iconify ()
1992-07-15 00:32:19 +00:00
"Iconify or deiconify the selected frame."
1991-08-15 21:29:06 +00:00
(interactive)
1992-07-15 00:32:19 +00:00
(let ((frame (selected-frame)))
(if (eq (frame-visible-p frame) t)
(iconify-frame frame)
(make-frame-visible frame))))
1992-07-10 02:33:41 +00:00
1992-07-15 00:32:19 +00:00
;;;; Frame configurations
(defun current-frame-configuration ()
"Return a list describing the positions and states of all frames.
Each element is a list of the form (FRAME ALIST WINDOW-CONFIG), where
FRAME is a frame object, ALIST is an association list specifying
some of FRAME's parameters, and WINDOW-CONFIG is a window
configuration object for FRAME."
1992-07-10 02:33:41 +00:00
(mapcar (function
1992-07-15 00:32:19 +00:00
(lambda (frame)
(list frame
(frame-parameters frame)
(current-window-configuration frame))))
(frame-list)))
(defun set-frame-configuration (configuration)
"Restore the frames to the state described by CONFIGURATION.
Each frame listed in CONFIGURATION has its position, size, window
1992-07-10 02:33:41 +00:00
configuration, and other parameters set as specified in CONFIGURATION."
1992-07-15 00:32:19 +00:00
(let (frames-to-delete)
1992-07-10 02:33:41 +00:00
(mapcar (function
1992-07-15 00:32:19 +00:00
(lambda (frame)
(let ((parameters (assq frame configuration)))
1992-07-10 02:33:41 +00:00
(if parameters
(progn
1992-07-15 00:32:19 +00:00
(modify-frame-parameters frame (nth 1 parameters))
1992-07-10 02:33:41 +00:00
(set-window-configuration (nth 2 parameters)))
1992-07-15 00:32:19 +00:00
(setq frames-to-delete (cons frame frames-to-delete))))))
(frame-list))
(mapcar 'delete-frame frames-to-delete)))
1991-08-15 21:29:06 +00:00
1992-07-15 00:32:19 +00:00
;;;; Convenience functions for accessing and interactively changing
;;;; frame parameters.
1991-08-15 21:29:06 +00:00
1992-07-15 00:32:19 +00:00
(defun frame-width (&optional frame)
"Return number of lines available for display on FRAME.
If FRAME is omitted, describe the currently selected frame."
(cdr (assq 'width (frame-parameters frame))))
(defun frame-width (&optional frame)
"Return number of columns available for display on FRAME.
If FRAME is omitted, describe the currently selected frame."
(cdr (assq 'height (frame-parameters frame))))
(defun set-frame-height (h)
1991-08-15 21:29:06 +00:00
(interactive "NHeight: ")
1992-07-15 00:32:19 +00:00
(let* ((frame (selected-frame))
(width (cdr (assoc 'width (frame-parameters (selected-frame))))))
(set-frame-size (selected-frame) width h)))
1991-08-15 21:29:06 +00:00
1992-07-15 00:32:19 +00:00
(defun set-frame-width (w)
1991-08-15 21:29:06 +00:00
(interactive "NWidth: ")
1992-07-15 00:32:19 +00:00
(let* ((frame (selected-frame))
(height (cdr (assoc 'height (frame-parameters (selected-frame))))))
(set-frame-size (selected-frame) w height)))
1991-08-15 21:29:06 +00:00
(defun set-default-font (font-name)
(interactive "sFont name: ")
1992-07-15 00:32:19 +00:00
(modify-frame-parameters (selected-frame)
1991-08-15 21:29:06 +00:00
(list (cons 'font font-name))))
1992-07-15 00:32:19 +00:00
(defun set-frame-background (color-name)
1991-08-15 21:29:06 +00:00
(interactive "sColor: ")
1992-07-15 00:32:19 +00:00
(modify-frame-parameters (selected-frame)
1991-08-15 21:29:06 +00:00
(list (cons 'background-color color-name))))
1992-07-15 00:32:19 +00:00
(defun set-frame-foreground (color-name)
1991-08-15 21:29:06 +00:00
(interactive "sColor: ")
1992-07-15 00:32:19 +00:00
(modify-frame-parameters (selected-frame)
1991-08-15 21:29:06 +00:00
(list (cons 'foreground-color color-name))))
(defun set-cursor-color (color-name)
(interactive "sColor: ")
1992-07-15 00:32:19 +00:00
(modify-frame-parameters (selected-frame)
1991-08-15 21:29:06 +00:00
(list (cons 'cursor-color color-name))))
(defun set-pointer-color (color-name)
(interactive "sColor: ")
1992-07-15 00:32:19 +00:00
(modify-frame-parameters (selected-frame)
1991-08-15 21:29:06 +00:00
(list (cons 'mouse-color color-name))))
(defun set-auto-raise (toggle)
(interactive "xt or nil? ")
1992-07-15 00:32:19 +00:00
(modify-frame-parameters (selected-frame)
1991-08-15 21:29:06 +00:00
(list (cons 'auto-raise toggle))))
(defun set-auto-lower (toggle)
(interactive "xt or nil? ")
1992-07-15 00:32:19 +00:00
(modify-frame-parameters (selected-frame)
1991-08-15 21:29:06 +00:00
(list (cons 'auto-lower toggle))))
(defun set-vertical-bar (toggle)
(interactive "xt or nil? ")
1992-07-15 00:32:19 +00:00
(modify-frame-parameters (selected-frame)
1991-08-15 21:29:06 +00:00
(list (cons 'vertical-scroll-bar toggle))))
(defun set-horizontal-bar (toggle)
(interactive "xt or nil? ")
1992-07-15 00:32:19 +00:00
(modify-frame-parameters (selected-frame)
1991-08-15 21:29:06 +00:00
(list (cons 'horizontal-scroll-bar toggle))))
1992-07-15 00:32:19 +00:00
;;;; Aliases for backward compatibility with Emacs 18.
(fset 'screen-height 'frame-height)
(fset 'screen-width 'frame-width)
(fset 'set-screen-width 'set-frame-width)
(fset 'set-screen-height 'set-frame-height)
1991-08-15 21:29:06 +00:00
;;;; Key bindings
1992-06-24 05:09:26 +00:00
(defvar ctl-x-5-map (make-sparse-keymap)
1992-07-15 00:32:19 +00:00
"Keymap for frame commands.")
1992-06-24 05:09:26 +00:00
(fset 'ctl-x-5-prefix ctl-x-5-map)
(define-key ctl-x-map "5" 'ctl-x-5-prefix)
1991-08-15 21:29:06 +00:00
1992-07-15 00:32:19 +00:00
(define-key ctl-x-5-map "2" 'new-frame)
(define-key ctl-x-5-map "0" 'delete-frame)
1992-03-16 20:39:07 +00:00
1992-07-15 00:32:19 +00:00
(provide 'frame)
1992-05-30 21:11:25 +00:00
1992-07-15 00:32:19 +00:00
;;; frame.el ends here