(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
function, which should take an alist of parameters as its argument.")
(defcustom 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)))
Parameters specified here supersede the values given in `default-frame-alist'.
If the value calls for a frame without a minibuffer, and you have not created
a minibuffer frame on your own, one is created according to
`minibuffer-frame-alist'.
You can specify geometry-related options for just the initial frame
by setting this variable in your `.emacs' file; however, they won't
take effect until Emacs reads `.emacs', which happens after first creating
the frame. If you want the frame to have the proper geometry as soon
as it appears, you need to use this three-step process:
* Specify X resources to give the geometry you want.
* Set `default-frame-alist' to override these options so that they
don't affect subsequent frames.
* Set `initial-frame-alist' in a way that matches the X resources,
to override what you put in `default-frame-alist'."
:type '(repeat (cons :format "%v"
(symbol :tag "Parameter")
(sexp :tag "Value")))
:group 'frames)
(defcustom minibuffer-frame-alist '((width . 80) (height . 2))
"*Alist of frame parameters for initially creating a minibuffer frame.
You can set this in your `.emacs' file; for example,
(setq minibuffer-frame-alist
'((top . 1) (left . 1) (width . 80) (height . 2)))
Parameters specified here supersede the values given in
`default-frame-alist', for a minibuffer frame."
:type '(repeat (cons :format "%v"
(symbol :tag "Parameter")
(sexp :tag "Value")))
:group 'frames)
(defcustom pop-up-frame-alist nil
"*Alist of frame parameters used when creating pop-up frames.
Pop-up frames are used for completions, help, and the like.
This variable can be set in your init file, like this:
(setq pop-up-frame-alist '((width . 80) (height . 20)))
These supersede the values given in `default-frame-alist',
for pop-up frames."
:type '(repeat (cons :format "%v"
(symbol :tag "Parameter")
(sexp :tag "Value")))
:group 'frames)
(setq pop-up-frame-function
(function (lambda ()
(make-frame pop-up-frame-alist))))
(defcustom special-display-frame-alist
'((height . 14) (width . 80) (unsplittable . t))
"*Alist of frame parameters used when creating special frames.
Special frames are used for buffers whose names are in
`special-display-buffer-names' and for buffers whose names match
one of the regular expressions in `special-display-regexps'.
This variable can be set in your init file, like this:
(setq special-display-frame-alist '((width . 80) (height . 20)))
These supersede the values given in `default-frame-alist'."
:type '(repeat (cons :format "%v"
(symbol :tag "Parameter")
(sexp :tag "Value")))
:group 'frames)
(defun special-display-popup-frame (buffer &optional args)
(if (and args (symbolp (car args)))
(apply (car args) buffer (cdr args))
(let ((window (get-buffer-window buffer t)))
(if window
(let ((frame (window-frame window)))
(make-frame-visible frame)
(raise-frame frame)
window)
(let ((frame (make-frame (append args special-display-frame-alist))))
(set-window-buffer (frame-selected-window frame) buffer)
(set-window-dedicated-p (frame-selected-window frame) t)
(frame-selected-window frame))))))
(defun handle-delete-frame (event)
(interactive "e")
(let ((frame (posn-window (event-start event)))
(i 0)
(tail (frame-list)))
(while tail
(and (frame-visible-p (car tail))
(not (eq (car tail) frame))
(setq i (1+ i)))
(setq tail (cdr tail)))
(if (> i 0)
(delete-frame frame t)
(save-buffers-kill-emacs))))
(defvar frame-initial-frame nil)
(defvar frame-initial-frame-alist)
(defvar frame-initial-geometry-arguments nil)
(defun frame-initialize ()
(if (and window-system (not noninteractive) (not (eq window-system 'pc)))
(progn
(setq special-display-function 'special-display-popup-frame)
(or (delq terminal-frame (minibuffer-frame-list))
(progn
(setq frame-initial-frame-alist
(append initial-frame-alist default-frame-alist))
(or (assq 'horizontal-scroll-bars frame-initial-frame-alist)
(setq frame-initial-frame-alist
(cons '(horizontal-scroll-bars . t)
frame-initial-frame-alist)))
(setq default-minibuffer-frame
(setq frame-initial-frame
(make-frame frame-initial-frame-alist)))
(setq initial-frame-alist
(frame-remove-geometry-params initial-frame-alist))))
(delete-frame terminal-frame)
(setq terminal-frame nil))
(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"))))))))
(defun frame-notice-user-settings ()
(if (boundp 'menu-bar-mode)
(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)))))
(let ((old-buffer (current-buffer)))
(if (frame-live-p frame-initial-frame)
(if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
(assq 'minibuffer default-frame-alist)
'(minibuffer . t)))
t))
(let (parms new)
(while (not (cdr (assq 'visibility
(frame-parameters frame-initial-frame))))
(sleep-for 1))
(setq parms (frame-parameters frame-initial-frame))
(or (assq 'name frame-initial-frame-alist)
(setq parms (delq (assq 'name parms) parms)))
(setq parms (append initial-frame-alist
default-frame-alist
parms
nil))
(setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
(if (assq 'height frame-initial-geometry-arguments)
(setq parms (frame-delete-all 'height parms)))
(if (assq 'width frame-initial-geometry-arguments)
(setq parms (frame-delete-all 'width parms)))
(if (assq 'left frame-initial-geometry-arguments)
(setq parms (frame-delete-all 'left parms)))
(if (assq 'top frame-initial-geometry-arguments)
(setq parms (frame-delete-all 'top parms)))
(setq new
(make-frame
(append frame-initial-geometry-arguments
'((user-size . t) (user-position . t))
parms)))
(or (delq frame-initial-frame (minibuffer-frame-list))
(make-initial-minibuffer-frame nil))
(let ((users-of-initial
(filtered-frame-list
(function (lambda (frame)
(and (not (eq frame frame-initial-frame))
(eq (window-frame
(minibuffer-window frame))
frame-initial-frame)))))))
(if (or users-of-initial
(eq default-minibuffer-frame frame-initial-frame))
(let* ((new-surrogate
(car
(or (filtered-frame-list
(function
(lambda (frame)
(eq (cdr (assq 'minibuffer
(frame-parameters frame)))
'only))))
(minibuffer-frame-list))))
(new-minibuffer (minibuffer-window new-surrogate)))
(if (eq default-minibuffer-frame frame-initial-frame)
(setq default-minibuffer-frame new-surrogate))
(mapcar
(function
(lambda (frame)
(modify-frame-parameters
frame (list (cons 'minibuffer new-minibuffer)))))
users-of-initial))))
(redirect-frame-focus frame-initial-frame new)
(delete-frame frame-initial-frame t))
(let (newparms allparms tail)
(setq allparms (append initial-frame-alist
default-frame-alist))
(if (assq 'height frame-initial-geometry-arguments)
(setq allparms (frame-delete-all 'height allparms)))
(if (assq 'width frame-initial-geometry-arguments)
(setq allparms (frame-delete-all 'width allparms)))
(if (assq 'left frame-initial-geometry-arguments)
(setq allparms (frame-delete-all 'left allparms)))
(if (assq 'top frame-initial-geometry-arguments)
(setq allparms (frame-delete-all 'top allparms)))
(setq tail allparms)
(while tail
(let (newval oldval)
(setq oldval (assq (car (car tail))
frame-initial-frame-alist))
(setq newval (cdr (assq (car (car tail)) allparms)))
(or (and oldval (eq (cdr oldval) newval))
(setq newparms
(cons (cons (car (car tail)) newval) newparms))))
(setq tail (cdr tail)))
(setq newparms (nreverse newparms))
(modify-frame-parameters frame-initial-frame
newparms)
(if (assq 'font newparms)
(frame-update-faces frame-initial-frame)))))
(set-buffer old-buffer)
(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))))
(defun frame-delete-all (key alist)
(setq alist (copy-sequence alist))
(let ((tail alist))
(while tail
(if (eq (car (car tail)) key)
(setq alist (delq (car tail) alist)))
(setq tail (cdr tail)))
alist))
(defun get-other-frame ()
(let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
(make-frame)
(next-frame (selected-frame)))))
s))
(defun next-multiframe-window ()
"Select the next window, regardless of which frame it is on."
(interactive)
(select-window (next-window (selected-window)
(> (minibuffer-depth) 0)
t)))
(defun previous-multiframe-window ()
"Select the previous window, regardless of which frame it is on."
(interactive)
(select-window (previous-window (selected-window)
(> (minibuffer-depth) 0)
t)))
(defun make-frame-on-display (display &optional parameters)
"Make a frame on display DISPLAY.
The optional second argument PARAMETERS specifies additional frame parameters."
(interactive "sMake frame on display: ")
(or (string-match "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display)
(error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
(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.")
(defalias 'new-frame 'make-frame)
(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:
(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.
You cannot specify either `width' or `height', you must use neither or both.
(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)
(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."
(let ((frames (frame-list))
good-frames)
(while (consp frames)
(if (funcall predicate (car frames))
(setq good-frames (cons (car frames) good-frames)))
(setq frames (cdr frames)))
good-frames))
(defun minibuffer-frame-list ()
"Return a list of all frames with their own minibuffers."
(filtered-frame-list
(function (lambda (frame)
(eq frame (window-frame (minibuffer-window frame)))))))
(defun frame-remove-geometry-params (param-list)
"Return the parameter list PARAM-LIST, but with geometry specs removed.
This deletes all bindings in PARAM-LIST for `top', `left', `width',
`height', `user-size' and `user-position' parameters.
Emacs uses this to avoid overriding explicit moves and resizings from
the user during startup."
(setq param-list (cons nil param-list))
(let ((tail param-list))
(while (consp (cdr tail))
(if (and (consp (car (cdr tail)))
(memq (car (car (cdr tail)))
'(height width top left user-position user-size)))
(progn
(setq frame-initial-geometry-arguments
(cons (car (cdr tail)) frame-initial-geometry-arguments))
(setcdr tail (cdr (cdr tail))))
(setq tail (cdr tail)))))
(setq frame-initial-geometry-arguments
(nreverse frame-initial-geometry-arguments))
(cdr param-list))
(defcustom focus-follows-mouse t
"*Non-nil if window system changes focus when you move the mouse."
:type 'boolean
:group 'frames
:version "20.3")
(defun other-frame (arg)
"Select the ARG'th different visible frame, and raise it.
All frames are arranged in a cyclic order.
This command selects the frame ARG steps away in that order.
A negative ARG moves in the opposite order."
(interactive "p")
(let ((frame (selected-frame)))
(while (> arg 0)
(setq frame (next-frame frame))
(while (not (eq (frame-visible-p frame) t))
(setq frame (next-frame frame)))
(setq arg (1- arg)))
(while (< arg 0)
(setq frame (previous-frame frame))
(while (not (eq (frame-visible-p frame) t))
(setq frame (previous-frame frame)))
(setq arg (1+ arg)))
(raise-frame frame)
(select-frame frame)
(if (eq window-system 'w32)
(w32-focus-frame frame)
(when focus-follows-mouse
(set-mouse-position (selected-frame) (1- (frame-width)) 0)))))
(defun make-frame-names-alist ()
(let* ((current-frame (selected-frame))
(falist
(cons
(cons (frame-parameter current-frame 'name) current-frame) nil))
(frame (next-frame nil t)))
(while (not (eq frame current-frame))
(progn
(setq falist (cons (cons (frame-parameter frame 'name) frame) falist))
(setq frame (next-frame frame t))))
falist))
(defvar frame-name-history nil)
(defun select-frame-by-name (name)
"Select the frame whose name is NAME and raise it.
If there is no frame by that name, signal an error."
(interactive
(let* ((frame-names-alist (make-frame-names-alist))
(default (car (car frame-names-alist)))
(input (completing-read
(format "Select Frame (default %s): " default)
frame-names-alist nil t nil 'frame-name-history)))
(if (= (length input) 0)
(list default)
(list input))))
(let* ((frame-names-alist (make-frame-names-alist))
(frame (cdr (assoc name frame-names-alist))))
(or frame
(error "There is no frame named `%s'" name))
(make-frame-visible frame)
(raise-frame frame)
(select-frame frame)
(if (eq window-system 'w32)
(w32-focus-frame frame)
(when focus-follows-mouse
(set-mouse-position (selected-frame) (1- (frame-width)) 0)))))
(defun current-frame-configuration ()
"Return a list describing the positions and states of all frames.
Its car is `frame-configuration'.
Each element of the cdr 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."
(cons 'frame-configuration
(mapcar (function
(lambda (frame)
(list frame
(frame-parameters frame)
(current-window-configuration frame))))
(frame-list))))
(defun set-frame-configuration (configuration &optional nodelete)
"Restore the frames to the state described by CONFIGURATION.
Each frame listed in CONFIGURATION has its position, size, window
configuration, and other parameters set as specified in CONFIGURATION.
Ordinarily, this function deletes all existing frames not
listed in CONFIGURATION. But if optional second argument NODELETE
is given and non-nil, the unwanted frames are iconified instead."
(or (frame-configuration-p configuration)
(signal 'wrong-type-argument
(list 'frame-configuration-p configuration)))
(let ((config-alist (cdr configuration))
frames-to-delete)
(mapcar (function
(lambda (frame)
(let ((parameters (assq frame config-alist)))
(if parameters
(progn
(modify-frame-parameters
frame
(let* ((parms (nth 1 parameters))
(mini (assq 'minibuffer parms)))
(if mini (setq parms (delq mini parms)))
parms))
(set-window-configuration (nth 2 parameters)))
(setq frames-to-delete (cons frame frames-to-delete))))))
(frame-list))
(if nodelete
(mapcar 'iconify-frame frames-to-delete)
(mapcar 'delete-frame frames-to-delete))))
(defun frame-parameter (frame parameter)
"Return FRAME's value for parameter PARAMETER.
If FRAME is nil, 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."
(cdr (assq 'height (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 'width (frame-parameters frame))))
(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.
To get the frame's current default font, use `frame-parameters'."
(interactive "sFont name: ")
(modify-frame-parameters (selected-frame)
(list (cons 'font font-name)))
(frame-update-faces (selected-frame)))
(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.
To get the frame's current background color, use `frame-parameters'."
(interactive "sColor: ")
(modify-frame-parameters (selected-frame)
(list (cons 'background-color color-name)))
(frame-update-face-colors (selected-frame)))
(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.
To get the frame's current foreground color, use `frame-parameters'."
(interactive "sColor: ")
(modify-frame-parameters (selected-frame)
(list (cons 'foreground-color color-name)))
(frame-update-face-colors (selected-frame)))
(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.
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.
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.
To get the frame's current border color, use `frame-parameters'."
(interactive "sColor: ")
(modify-frame-parameters (selected-frame)
(list (cons 'border-color color-name))))
(defun auto-raise-mode (arg)
"Toggle whether or not the selected frame should auto-raise.
With arg, turn auto-raise mode on if and only if arg is positive.
Note that this controls Emacs's own auto-raise feature.
Some window managers allow you to enable auto-raise for certain windows.
You can use that for Emacs windows if you wish, but if you do,
that is beyond the control of Emacs and this command has no effect on it."
(interactive "P")
(if (null arg)
(setq arg
(if (cdr (assq 'auto-raise (frame-parameters (selected-frame))))
-1 1)))
(modify-frame-parameters (selected-frame)
(list (cons 'auto-raise (> arg 0)))))
(defun auto-lower-mode (arg)
"Toggle whether or not the selected frame should auto-lower.
With arg, turn auto-lower mode on if and only if arg is positive.
Note that this controls Emacs's own auto-lower feature.
Some window managers allow you to enable auto-lower for certain windows.
You can use that for Emacs windows if you wish, but if you do,
that is beyond the control of Emacs and this command has no effect on it."
(interactive "P")
(if (null arg)
(setq arg
(if (cdr (assq 'auto-lower (frame-parameters (selected-frame))))
-1 1)))
(modify-frame-parameters (selected-frame)
(list (cons 'auto-lower (> arg 0)))))
(defun set-frame-name (name)
"Set the name of the selected frame to NAME.
When called interactively, prompt for the name of the frame.
The frame name is displayed on the modeline if the terminal displays only
one frame, otherwise the name is displayed on the frame's caption bar."
(interactive "sFrame name: ")
(modify-frame-parameters (selected-frame)
(list (cons 'name name))))
(defalias 'screen-height 'frame-height)
(defalias 'screen-width 'frame-width)
(defun set-screen-width (cols &optional pretend)
"Obsolete function to change the size of the screen to COLS columns.\n\
Optional second arg non-nil means that redisplay should use COLS columns\n\
but that the idea of the actual width of the frame should not be changed.\n\
This function is provided only for compatibility with Emacs 18; new code\n\
should use `set-frame-width instead'."
(set-frame-width (selected-frame) cols pretend))
(defun set-screen-height (lines &optional pretend)
"Obsolete function to change the height of the screen to LINES lines.\n\
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-height' instead."
(set-frame-height (selected-frame) lines pretend))
(make-obsolete 'screen-height 'frame-height)
(make-obsolete 'screen-width 'frame-width)
(make-obsolete 'set-screen-width 'set-frame-width)
(make-obsolete 'set-screen-height 'set-frame-height)
(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)
(provide 'frame)