(mouse-save-then-kill): When we don't use existing
[bpt/emacs.git] / lisp / frame.el
CommitLineData
dc6d9681 1;;; frame.el --- multi-frame management independent of window systems.
c88ab9ce 2
8f1204db 3;;;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
3a801d0c 4
fc68affa 5;; Maintainer: FSF
fd7fa35a 6;; Keywords: internal
fc68affa 7
64c669bc
JB
8;;; This file is part of GNU Emacs.
9;;;
10;;; GNU Emacs is free software; you can redistribute it and/or modify
11;;; it under the terms of the GNU General Public License as published by
de49a6d3 12;;; the Free Software Foundation; either version 2, or (at your option)
64c669bc
JB
13;;; any later version.
14;;;
15;;; GNU Emacs is distributed in the hope that it will be useful,
16;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;;; GNU General Public License for more details.
19;;;
20;;; You should have received a copy of the GNU General Public License
21;;; along with GNU Emacs; see the file COPYING. If not, write to
22;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
fc68affa
ER
24;;; Code:
25
dc6d9681
JB
26(defvar frame-creation-function nil
27 "Window-system dependent function to call to create a new frame.
28The window system startup file should set this to its frame creation
64c669bc
JB
29function, which should take an alist of parameters as its argument.")
30
7eadab74
JB
31;;; The initial value given here for this must ask for a minibuffer.
32;;; There must always exist a frame with a minibuffer, and after we
33;;; delete the terminal frame, this will be the only frame.
9e2b097b 34(defvar initial-frame-alist '((minibuffer . t))
eaa974e1
JB
35 "Alist of frame parameters for creating the initial X window frame.
36You can set this in your `.emacs' file; for example,
dc6d9681 37 (setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55)))
de17da15
RS
38Parameters specified here supersede the values given in `default-frame-alist'.
39
40If the value calls for a frame without a minibuffer, and you have not created
41a minibuffer frame on your own, one is created according to
7eadab74 42`minibuffer-frame-alist'.
de17da15
RS
43
44You can specify geometry-related options for just the initial frame
45by setting this variable in your `.emacs' file; however, they won't
46take affect until Emacs reads `.emacs', which happens after first creating
47the frame. If you want the frame to have the proper geometry as soon
48as it appears, you need to use this three-step process:
49* Specify X resources to give the geometry you want.
50* Set `default-frame-alist' to override these options so that they
51 don't affect subsequent frames.
52* Set `initial-frame-alist' in a way that matches the X resources,
53 to override what you put in `default-frame-alist'.")
64c669bc 54
7eadab74 55(defvar minibuffer-frame-alist '((width . 80) (height . 2))
eaa974e1
JB
56 "Alist of frame parameters for initially creating a minibuffer frame.
57You can set this in your `.emacs' file; for example,
dc6d9681 58 (setq minibuffer-frame-alist
7eadab74 59 '((top . 1) (left . 1) (width . 80) (height . 2)))
eaa974e1
JB
60Parameters specified here supersede the values given in
61`default-frame-alist'.")
64c669bc 62
dc6d9681 63(defvar pop-up-frame-alist nil
eaa974e1 64 "Alist of frame parameters used when creating pop-up frames.
dc6d9681 65Pop-up frames are used for completions, help, and the like.
64c669bc 66This variable can be set in your init file, like this:
dc6d9681 67 (setq pop-up-frame-alist '((width . 80) (height . 20)))
eb8c3be9 68These supersede the values given in `default-frame-alist'.")
64c669bc 69
dc6d9681 70(setq pop-up-frame-function
64c669bc 71 (function (lambda ()
6eb018ba 72 (make-frame pop-up-frame-alist))))
64c669bc 73
8a9e86e6
RS
74(defvar special-display-frame-alist
75 '((height . 14) (width . 80) (unsplittable . t))
76 "*Alist of frame parameters used when creating special frames.
77Special frames are used for buffers whose names are in
78`special-display-buffer-names' and for buffers whose names match
79one of the regular expressions in `special-display-regexps'.
80This variable can be set in your init file, like this:
81 (setq special-display-frame-alist '((width . 80) (height . 20)))
82These supersede the values given in `default-frame-alist'.")
83
84;; Display BUFFER in its own frame, reusing an existing window if any.
85;; Return the window chosen.
86;; Currently we do not insist on selecting the window within its frame.
95e6cf39
RS
87;; If ARGS is an alist, use it as a list of frame parameter specs.
88;; If ARGS is a list whose car is a symbol.
89;; use (car ARGS) as a function to do the work.
90;; Pass it BUFFER as first arg, and (cdr ARGS) gives the rest of the args.
91(defun special-display-popup-frame (buffer &optional args)
92 (if (and args (symbolp (car args)))
93 (apply (car args) buffer (cdr args))
94 (let ((window (get-buffer-window buffer t)))
95 (if window
96 ;; If we have a window already, make it visible.
97 (let ((frame (window-frame window)))
98 (make-frame-visible frame)
99 (raise-frame frame)
100 window)
101 ;; If no window yet, make one in a new frame.
102 (let ((frame (make-frame (append args special-display-frame-alist))))
103 (set-window-buffer (frame-selected-window frame) buffer)
104 (set-window-dedicated-p (frame-selected-window frame) t)
105 (frame-selected-window frame))))))
8a9e86e6 106
924be53a
RS
107;; Handle delete-frame events from the X server.
108(defun handle-delete-frame (event)
109 (interactive "e")
110 (let ((frame (posn-window (event-start event)))
111 (i 0)
112 (tail (frame-list)))
113 (while tail
114 (and (frame-visible-p (car tail))
115 (not (eq (car tail) frame))
116 (setq i (1+ i)))
117 (setq tail (cdr tail)))
118 (if (> i 0)
119 (delete-frame frame t)
120 (kill-emacs))))
64c669bc 121\f
dc6d9681 122;;;; Arrangement of frames at startup
64c669bc
JB
123
124;;; 1) Load the window system startup file from the lisp library and read the
125;;; high-priority arguments (-q and the like). The window system startup
dc6d9681 126;;; file should create any frames specified in the window system defaults.
64c669bc 127;;;
dc6d9681 128;;; 2) If no frames have been opened, we open an initial text frame.
64c669bc
JB
129;;;
130;;; 3) Once the init file is done, we apply any newly set parameters
dc6d9681 131;;; in initial-frame-alist to the frame.
64c669bc 132
fc4d4afb
RS
133;; These are now called explicitly at the proper times,
134;; since that is easier to understand.
135;; Actually using hooks within Emacs is bad for future maintenance. --rms.
136;; (add-hook 'before-init-hook 'frame-initialize)
137;; (add-hook 'window-setup-hook 'frame-notice-user-settings)
64c669bc 138
dc6d9681
JB
139;;; If we create the initial frame, this is it.
140(defvar frame-initial-frame nil)
64c669bc 141
3f2f8c83
RS
142;; Record the parameters used in frame-initialize to make the initial frame.
143(defvar frame-initial-frame-alist)
144
791e09d8
RS
145(defvar frame-initial-geometry-arguments nil)
146
64c669bc 147;;; startup.el calls this function before loading the user's init
dc6d9681 148;;; file - if there is no frame with a minibuffer open now, create
64c669bc 149;;; one to display messages while loading the init file.
dc6d9681 150(defun frame-initialize ()
62642af9 151
64c669bc
JB
152 ;; Are we actually running under a window system at all?
153 (if (and window-system (not noninteractive))
7eadab74 154 (progn
62642af9
RS
155 ;; Turn on special-display processing only if there's a window system.
156 (setq special-display-function 'special-display-popup-frame)
157
7eadab74
JB
158 ;; If there is no frame with a minibuffer besides the terminal
159 ;; frame, then we need to create the opening frame. Make sure
160 ;; it has a minibuffer, but let initial-frame-alist omit the
161 ;; minibuffer spec.
162 (or (delq terminal-frame (minibuffer-frame-list))
36fc9c9f 163 (progn
3f2f8c83
RS
164 (setq frame-initial-frame-alist
165 (append initial-frame-alist default-frame-alist))
a8bb5882
RS
166 ;; Record these with their default values
167 ;; if they don't have any values explicitly.
168 (or (assq 'vertical-scroll-bars frame-initial-frame-alist)
169 (setq frame-initial-frame-alist
170 (cons '(vertical-scroll-bars . t)
171 frame-initial-frame-alist)))
172 (or (assq 'horizontal-scroll-bars frame-initial-frame-alist)
173 (setq frame-initial-frame-alist
174 (cons '(horizontal-scroll-bars . t)
175 frame-initial-frame-alist)))
36fc9c9f
RS
176 (setq default-minibuffer-frame
177 (setq frame-initial-frame
6eb018ba 178 (make-frame initial-frame-alist)))
11281034
RS
179 ;; Delete any specifications for window geometry parameters
180 ;; so that we won't reapply them in frame-notice-user-settings.
181 ;; It would be wrong to reapply them then,
182 ;; because that would override explicit user resizing.
58bf6042 183 (setq initial-frame-alist
c2079f0a 184 (frame-remove-geometry-params initial-frame-alist))))
dc6d9681
JB
185 ;; At this point, we know that we have a frame open, so we
186 ;; can delete the terminal frame.
187 (delete-frame terminal-frame)
188 (setq terminal-frame nil))
64c669bc
JB
189
190 ;; No, we're not running a window system. Arrange to cause errors.
dc6d9681 191 (setq frame-creation-function
9198945a
MB
192 (function
193 (lambda (parameters)
194 (error
8290babd 195 "Can't create multiple frames without a window system"))))))
64c669bc 196
7eadab74
JB
197;;; startup.el calls this function after loading the user's init
198;;; file. Now default-frame-alist and initial-frame-alist contain
199;;; information to which we must react; do what needs to be done.
dc6d9681 200(defun frame-notice-user-settings ()
7eadab74 201
2ffa6186
RS
202 ;; Make menu-bar-mode and default-frame-alist consistent.
203 (let ((default (assq 'menu-bar-lines default-frame-alist)))
204 (if default
205 (setq menu-bar-mode (not (eq (cdr default) 0)))
206 (setq default-frame-alist
207 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
208 default-frame-alist))))
209
7eadab74
JB
210 ;; Creating and deleting frames may shift the selected frame around,
211 ;; and thus the current buffer. Protect against that. We don't
212 ;; want to use save-excursion here, because that may also try to set
213 ;; the buffer of the selected window, which fails when the selected
214 ;; window is the minibuffer.
215 (let ((old-buffer (current-buffer)))
216
217 ;; If the initial frame is still around, apply initial-frame-alist
218 ;; and default-frame-alist to it.
219 (if (frame-live-p frame-initial-frame)
220
221 ;; The initial frame we create above always has a minibuffer.
222 ;; If the user wants to remove it, or make it a minibuffer-only
223 ;; frame, then we'll have to delete the current frame and make a
224 ;; new one; you can't remove or add a root window to/from an
225 ;; existing frame.
226 ;;
ec558adc
JB
227 ;; NOTE: default-frame-alist was nil when we created the
228 ;; existing frame. We need to explicitly include
229 ;; default-frame-alist in the parameters of the screen we
230 ;; create here, so that its new value, gleaned from the user's
231 ;; .emacs file, will be applied to the existing screen.
7eadab74
JB
232 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
233 (assq 'minibuffer default-frame-alist)
234 '(minibuffer . t)))
235 t))
236 ;; Create the new frame.
b65e2f74
RS
237 (let (parms new)
238 ;; If the frame isn't visible yet, wait till it is.
239 ;; If the user has to position the window,
240 ;; Emacs doesn't know its real position until
241 ;; the frame is seen to be visible.
242 (while (not (cdr (assq 'visibility
243 (frame-parameters frame-initial-frame))))
244 (sleep-for 1))
245 (setq parms (append initial-frame-alist
6eb018ba
RS
246 default-frame-alist
247 (frame-parameters frame-initial-frame)
248 nil))
c1e67401
RS
249 ;; Get rid of `reverse', because that was handled
250 ;; when we first made the frame.
251 (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
252 (if (assq 'height frame-initial-geometry-arguments)
5b66a32f 253 (setq parms (frame-delete-all 'height parms)))
c1e67401 254 (if (assq 'width frame-initial-geometry-arguments)
5b66a32f 255 (setq parms (frame-delete-all 'width parms)))
c1e67401 256 (if (assq 'left frame-initial-geometry-arguments)
5b66a32f 257 (setq parms (frame-delete-all 'left parms)))
c1e67401 258 (if (assq 'top frame-initial-geometry-arguments)
5b66a32f 259 (setq parms (frame-delete-all 'top parms)))
c1e67401
RS
260 (setq new
261 (make-frame
262 ;; Use the geometry args that created the existing
263 ;; frame, rather than the parms we get for it.
264 (append frame-initial-geometry-arguments parms)))
7eadab74
JB
265 ;; The initial frame, which we are about to delete, may be
266 ;; the only frame with a minibuffer. If it is, create a
267 ;; new one.
268 (or (delq frame-initial-frame (minibuffer-frame-list))
6eb018ba 269 (make-frame (append minibuffer-frame-alist
7eadab74
JB
270 '((minibuffer . only)))))
271
272 ;; If the initial frame is serving as a surrogate
273 ;; minibuffer frame for any frames, we need to wean them
274 ;; onto a new frame. The default-minibuffer-frame
275 ;; variable must be handled similarly.
276 (let ((users-of-initial
277 (filtered-frame-list
278 (function (lambda (frame)
279 (and (not (eq frame frame-initial-frame))
280 (eq (window-frame
281 (minibuffer-window frame))
282 frame-initial-frame)))))))
283 (if (or users-of-initial
284 (eq default-minibuffer-frame frame-initial-frame))
285
286 ;; Choose an appropriate frame. Prefer frames which
287 ;; are only minibuffers.
288 (let* ((new-surrogate
289 (car
290 (or (filtered-frame-list
291 (function
292 (lambda (frame)
293 (eq (cdr (assq 'minibuffer
294 (frame-parameters frame)))
295 'only))))
296 (minibuffer-frame-list))))
297 (new-minibuffer (minibuffer-window new-surrogate)))
298
299 (if (eq default-minibuffer-frame frame-initial-frame)
300 (setq default-minibuffer-frame new-surrogate))
301
302 ;; Wean the frames using frame-initial-frame as
303 ;; their minibuffer frame.
304 (mapcar
305 (function
306 (lambda (frame)
307 (modify-frame-parameters
308 frame (list (cons 'minibuffer new-minibuffer)))))
309 users-of-initial))))
ec558adc
JB
310
311 ;; Redirect events enqueued at this frame to the new frame.
312 ;; Is this a good idea?
7eadab74 313 (redirect-frame-focus frame-initial-frame new)
ec558adc 314
7eadab74 315 ;; Finally, get rid of the old frame.
0cffbbb9 316 (delete-frame frame-initial-frame t))
7eadab74
JB
317
318 ;; Otherwise, we don't need all that rigamarole; just apply
319 ;; the new parameters.
3f2f8c83
RS
320 (let (newparms allparms tail)
321 (setq allparms (append initial-frame-alist
322 default-frame-alist))
5b66a32f
RS
323 (if (assq 'height frame-initial-geometry-arguments)
324 (setq allparms (frame-delete-all 'height allparms)))
325 (if (assq 'width frame-initial-geometry-arguments)
326 (setq allparms (frame-delete-all 'width allparms)))
327 (if (assq 'left frame-initial-geometry-arguments)
328 (setq allparms (frame-delete-all 'left allparms)))
329 (if (assq 'top frame-initial-geometry-arguments)
330 (setq allparms (frame-delete-all 'top allparms)))
3f2f8c83
RS
331 (setq tail allparms)
332 ;; Find just the parms that have changed since we first
333 ;; made this frame. Those are the ones actually set by
334 ;; the init file. For those parms whose values we already knew
335 ;; (such as those spec'd by command line options)
336 ;; it is undesirable to specify the parm again
337 ;; once the user has seen the frame and been able to alter it
338 ;; manually.
339 (while tail
340 (let (newval oldval)
341 (setq oldval (cdr (assq (car (car tail))
342 frame-initial-frame-alist)))
343 (setq newval (cdr (assq (car (car tail)) allparms)))
344 (or (eq oldval newval)
345 (setq newparms
346 (cons (cons (car (car tail)) newval) newparms))))
347 (setq tail (cdr tail)))
86e58378 348 (setq newparms (nreverse newparms))
3f2f8c83 349 (modify-frame-parameters frame-initial-frame
86e58378
RS
350 newparms)
351 (if (assq 'font newparms)
352 (frame-update-faces frame-initial-frame)))))
64c669bc 353
7eadab74
JB
354 ;; Restore the original buffer.
355 (set-buffer old-buffer)
356
357 ;; Make sure the initial frame can be GC'd if it is ever deleted.
d202f1f2
JB
358 ;; Make sure frame-notice-user-settings does nothing if called twice.
359 (setq frame-initial-frame nil)))
64c669bc 360
5b66a32f
RS
361;; Delete from ALIST all elements whose car is KEY.
362;; Return the modified alist.
363(defun frame-delete-all (key alist)
9759578f 364 (setq alist (copy-sequence alist))
5b66a32f
RS
365 (let ((tail alist))
366 (while tail
367 (if (eq (car (car tail)) key)
368 (setq alist (delq (car tail) alist)))
369 (setq tail (cdr tail)))
370 alist))
64c669bc 371\f
7eadab74 372;;;; Creation of additional frames, and other frame miscellanea
dc6d9681 373
7eadab74 374;;; Return some frame other than the current frame, creating one if
eb8c3be9 375;;; necessary. Note that the minibuffer frame, if separate, is not
7eadab74 376;;; considered (see next-frame).
7253d8e0 377(defun get-other-frame ()
dc6d9681 378 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
6eb018ba 379 (make-frame)
dc6d9681 380 (next-frame (selected-frame)))))
64c669bc
JB
381 s))
382
dc6d9681
JB
383(defun next-multiframe-window ()
384 "Select the next window, regardless of which frame it is on."
64c669bc
JB
385 (interactive)
386 (select-window (next-window (selected-window)
387 (> (minibuffer-depth) 0)
388 t)))
389
dc6d9681
JB
390(defun previous-multiframe-window ()
391 "Select the previous window, regardless of which frame it is on."
64c669bc
JB
392 (interactive)
393 (select-window (previous-window (selected-window)
394 (> (minibuffer-depth) 0)
395 t)))
396
6d73e337
RS
397(defun make-frame-on-display (display &optional parameters)
398 "Make a frame on display DISPLAY.
399The optional second argument PARAMETERS specifies additional frame parameters."
400 (interactive "sMake frame on display: ")
401 (make-frame (cons (cons 'display display) parameters)))
402
92e443b1 403;; Alias, kept temporarily.
31e1d920 404(defalias 'new-frame 'make-frame)
92e443b1 405(defun make-frame (&optional parameters)
dc6d9681 406 "Create a new frame, displaying the current buffer.
bc93c097 407
43a2e52c 408Optional argument PARAMETERS is an alist of parameters for the new
dc6d9681 409frame. Specifically, PARAMETERS is a list of pairs, each having one
43a2e52c
JB
410of the following forms:
411
eaa974e1 412\(name . STRING) - The frame should be named STRING.
43a2e52c 413
eaa974e1 414\(height . NUMBER) - The frame should be NUMBER text lines high. If
43a2e52c
JB
415 this parameter is present, the width parameter must also be
416 given.
417
eaa974e1 418\(width . NUMBER) - The frame should be NUMBER characters in width.
43a2e52c
JB
419 If this parameter is present, the height parameter must also
420 be given.
421
eaa974e1 422\(minibuffer . t) - the frame should have a minibuffer
0ca90494 423\(minibuffer . nil) - the frame should have no minibuffer
eaa974e1 424\(minibuffer . only) - the frame should contain only a minibuffer
8dbd5c78 425\(minibuffer . WINDOW) - the frame should use WINDOW as its minibuffer window."
64c669bc 426 (interactive)
4133ab49
RS
427 (let ((nframe))
428 (run-hooks 'before-make-frame-hook)
429 (setq nframe (funcall frame-creation-function parameters))
430 (run-hooks 'after-make-frame-hook)
431 nframe))
64c669bc 432
7eadab74
JB
433(defun filtered-frame-list (predicate)
434 "Return a list of all live frames which satisfy PREDICATE."
435 (let ((frames (frame-list))
436 good-frames)
437 (while (consp frames)
438 (if (funcall predicate (car frames))
439 (setq good-frames (cons (car frames) good-frames)))
440 (setq frames (cdr frames)))
441 good-frames))
442
443(defun minibuffer-frame-list ()
444 "Return a list of all frames with their own minibuffers."
445 (filtered-frame-list
446 (function (lambda (frame)
447 (eq frame (window-frame (minibuffer-window frame)))))))
448
58bf6042
JB
449(defun frame-remove-geometry-params (param-list)
450 "Return the parameter list PARAM-LIST, but with geometry specs removed.
451This deletes all bindings in PARAM-LIST for `top', `left', `width',
791e09d8 452`height', `user-size' and `user-position' parameters.
58bf6042
JB
453Emacs uses this to avoid overriding explicit moves and resizings from
454the user during startup."
455 (setq param-list (cons nil param-list))
456 (let ((tail param-list))
457 (while (consp (cdr tail))
458 (if (and (consp (car (cdr tail)))
791e09d8
RS
459 (memq (car (car (cdr tail)))
460 '(height width top left user-position user-size)))
461 (progn
462 (setq frame-initial-geometry-arguments
463 (cons (car (cdr tail)) frame-initial-geometry-arguments))
464 (setcdr tail (cdr (cdr tail))))
58bf6042 465 (setq tail (cdr tail)))))
e11c3dc2
KH
466 (setq frame-initial-geometry-arguments
467 (nreverse frame-initial-geometry-arguments))
58bf6042
JB
468 (cdr param-list))
469
470
ceab6935 471(defun other-frame (arg)
a569dbc3 472 "Select the ARG'th different visible frame, and raise it.
ceab6935
RM
473All frames are arranged in a cyclic order.
474This command selects the frame ARG steps away in that order.
475A negative ARG moves in the opposite order."
476 (interactive "p")
477 (let ((frame (selected-frame)))
478 (while (> arg 0)
a569dbc3
RM
479 (setq frame (next-frame frame))
480 (while (not (eq (frame-visible-p frame) t))
481 (setq frame (next-frame frame)))
482 (setq arg (1- arg)))
ceab6935 483 (while (< arg 0)
a569dbc3
RM
484 (setq frame (previous-frame frame))
485 (while (not (eq (frame-visible-p frame) t))
486 (setq frame (previous-frame frame)))
915cfd1f 487 (setq arg (1+ arg)))
ceab6935 488 (raise-frame frame)
699213bc 489 (select-frame frame)
2b88f7a0 490 (set-mouse-position (selected-frame) (1- (frame-width)) 0)
699213bc 491 (unfocus-frame)))
64c669bc 492\f
dc6d9681
JB
493;;;; Frame configurations
494
495(defun current-frame-configuration ()
496 "Return a list describing the positions and states of all frames.
376a7584
JB
497Its car is `frame-configuration'.
498Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
499where
500 FRAME is a frame object,
501 ALIST is an association list specifying some of FRAME's parameters, and
502 WINDOW-CONFIG is a window configuration object for FRAME."
503 (cons 'frame-configuration
504 (mapcar (function
505 (lambda (frame)
506 (list frame
507 (frame-parameters frame)
508 (current-window-configuration frame))))
509 (frame-list))))
dc6d9681 510
68cd265f 511(defun set-frame-configuration (configuration &optional nodelete)
dc6d9681
JB
512 "Restore the frames to the state described by CONFIGURATION.
513Each frame listed in CONFIGURATION has its position, size, window
68cd265f 514configuration, and other parameters set as specified in CONFIGURATION.
a78db71c
RS
515Ordinarily, this function deletes all existing frames not
516listed in CONFIGURATION. But if optional second argument NODELETE
5da841d2 517is given and non-nil, the unwanted frames are iconified instead."
376a7584
JB
518 (or (frame-configuration-p configuration)
519 (signal 'wrong-type-argument
520 (list 'frame-configuration-p configuration)))
521 (let ((config-alist (cdr configuration))
522 frames-to-delete)
06b1a5ef 523 (mapcar (function
dc6d9681 524 (lambda (frame)
376a7584 525 (let ((parameters (assq frame config-alist)))
06b1a5ef
JB
526 (if parameters
527 (progn
98e9d14b
JB
528 (modify-frame-parameters
529 frame
530 ;; Since we can't set a frame's minibuffer status,
531 ;; we might as well omit the parameter altogether.
532 (let* ((parms (nth 1 parameters))
533 (mini (assq 'minibuffer parms)))
534 (if mini (setq parms (delq mini parms)))
535 parms))
06b1a5ef 536 (set-window-configuration (nth 2 parameters)))
dc6d9681
JB
537 (setq frames-to-delete (cons frame frames-to-delete))))))
538 (frame-list))
a78db71c 539 (if nodelete
5da841d2
RS
540 ;; Note: making frames invisible here was tried
541 ;; but led to some strange behavior--each time the frame
542 ;; was made visible again, the window manager asked afresh
543 ;; for where to put it.
544 (mapcar 'iconify-frame frames-to-delete)
a78db71c 545 (mapcar 'delete-frame frames-to-delete))))
64c669bc 546
376a7584
JB
547(defun frame-configuration-p (object)
548 "Return non-nil if OBJECT seems to be a frame configuration.
549Any list whose car is `frame-configuration' is assumed to be a frame
550configuration."
551 (and (consp object)
552 (eq (car object) 'frame-configuration)))
553
64c669bc 554\f
dc6d9681
JB
555;;;; Convenience functions for accessing and interactively changing
556;;;; frame parameters.
64c669bc 557
151bdc83 558(defun frame-height (&optional frame)
dc6d9681
JB
559 "Return number of lines available for display on FRAME.
560If FRAME is omitted, describe the currently selected frame."
151bdc83 561 (cdr (assq 'height (frame-parameters frame))))
dc6d9681
JB
562
563(defun frame-width (&optional frame)
564 "Return number of columns available for display on FRAME.
565If FRAME is omitted, describe the currently selected frame."
151bdc83 566 (cdr (assq 'width (frame-parameters frame))))
dc6d9681 567
64c669bc 568(defun set-default-font (font-name)
7eadab74
JB
569 "Set the font of the selected frame to FONT.
570When called interactively, prompt for the name of the font to use."
64c669bc 571 (interactive "sFont name: ")
dc6d9681 572 (modify-frame-parameters (selected-frame)
4033f46b
RS
573 (list (cons 'font font-name)))
574 ;; Update faces that want a bold or italic version of the default font.
575 (frame-update-faces (selected-frame)))
64c669bc 576
8290babd 577(defun set-background-color (color-name)
7eadab74
JB
578 "Set the background color of the selected frame to COLOR.
579When called interactively, prompt for the name of the color to use."
64c669bc 580 (interactive "sColor: ")
dc6d9681 581 (modify-frame-parameters (selected-frame)
1787c22a
RS
582 (list (cons 'background-color color-name)))
583 (frame-update-face-colors (selected-frame)))
64c669bc 584
8290babd 585(defun set-foreground-color (color-name)
7eadab74
JB
586 "Set the foreground color of the selected frame to COLOR.
587When called interactively, prompt for the name of the color to use."
64c669bc 588 (interactive "sColor: ")
dc6d9681 589 (modify-frame-parameters (selected-frame)
1787c22a
RS
590 (list (cons 'foreground-color color-name)))
591 (frame-update-face-colors (selected-frame)))
64c669bc
JB
592
593(defun set-cursor-color (color-name)
7eadab74
JB
594 "Set the text cursor color of the selected frame to COLOR.
595When called interactively, prompt for the name of the color to use."
64c669bc 596 (interactive "sColor: ")
dc6d9681 597 (modify-frame-parameters (selected-frame)
7eadab74 598 (list (cons 'cursor-color color-name))))
64c669bc 599
eaa974e1 600(defun set-mouse-color (color-name)
7eadab74
JB
601 "Set the color of the mouse pointer of the selected frame to COLOR.
602When called interactively, prompt for the name of the color to use."
64c669bc 603 (interactive "sColor: ")
dc6d9681 604 (modify-frame-parameters (selected-frame)
7eadab74
JB
605 (list (cons 'mouse-color color-name))))
606
eaa974e1
JB
607(defun set-border-color (color-name)
608 "Set the color of the border of the selected frame to COLOR.
609When called interactively, prompt for the name of the color to use."
610 (interactive "sColor: ")
611 (modify-frame-parameters (selected-frame)
612 (list (cons 'border-color color-name))))
613
614(defun auto-raise-mode (arg)
7eadab74 615 "Toggle whether or not the selected frame should auto-raise.
79e6ae33
RS
616With arg, turn auto-raise mode on if and only if arg is positive.
617Note that this controls Emacs's own auto-raise feature.
618Some window managers allow you to enable auto-raise for certain windows.
619You can use that for Emacs windows if you wish, but if you do,
620that is beyond the control of Emacs and this command has no effect on it."
7eadab74
JB
621 (interactive "P")
622 (if (null arg)
623 (setq arg
624 (if (cdr (assq 'auto-raise (frame-parameters (selected-frame))))
625 -1 1)))
dc6d9681 626 (modify-frame-parameters (selected-frame)
7eadab74
JB
627 (list (cons 'auto-raise (> arg 0)))))
628
eaa974e1 629(defun auto-lower-mode (arg)
7eadab74 630 "Toggle whether or not the selected frame should auto-lower.
79e6ae33
RS
631With arg, turn auto-lower mode on if and only if arg is positive.
632Note that this controls Emacs's own auto-lower feature.
633Some window managers allow you to enable auto-lower for certain windows.
634You can use that for Emacs windows if you wish, but if you do,
635that is beyond the control of Emacs and this command has no effect on it."
7eadab74
JB
636 (interactive "P")
637 (if (null arg)
638 (setq arg
639 (if (cdr (assq 'auto-lower (frame-parameters (selected-frame))))
640 -1 1)))
dc6d9681 641 (modify-frame-parameters (selected-frame)
7eadab74
JB
642 (list (cons 'auto-lower (> arg 0)))))
643
7e85c6b5 644(defun toggle-scroll-bar (arg)
0ca90494
JB
645 "Toggle whether or not the selected frame has vertical scroll bars.
646With arg, turn vertical scroll bars on if and only if arg is positive."
7eadab74
JB
647 (interactive "P")
648 (if (null arg)
649 (setq arg
0ca90494 650 (if (cdr (assq 'vertical-scroll-bars
7eadab74
JB
651 (frame-parameters (selected-frame))))
652 -1 1)))
dc6d9681 653 (modify-frame-parameters (selected-frame)
0ca90494 654 (list (cons 'vertical-scroll-bars (> arg 0)))))
7eadab74 655
8290babd 656(defun toggle-horizontal-scroll-bar (arg)
0ca90494
JB
657 "Toggle whether or not the selected frame has horizontal scroll bars.
658With arg, turn horizontal scroll bars on if and only if arg is positive.
659Horizontal scroll bars aren't implemented yet."
7eadab74 660 (interactive "P")
8290babd 661 (error "Horizontal scroll bars aren't implemented yet"))
64c669bc 662
64c669bc 663\f
dc6d9681 664;;;; Aliases for backward compatibility with Emacs 18.
31e1d920
ER
665(defalias 'screen-height 'frame-height)
666(defalias 'screen-width 'frame-width)
9e2b097b
JB
667
668(defun set-screen-width (cols &optional pretend)
669 "Obsolete function to change the size of the screen to COLS columns.\n\
670Optional second arg non-nil means that redisplay should use COLS columns\n\
671but that the idea of the actual width of the frame should not be changed.\n\
672This function is provided only for compatibility with Emacs 18; new code\n\
fe668515 673should use `set-frame-width instead'."
9e2b097b
JB
674 (set-frame-width (selected-frame) cols pretend))
675
676(defun set-screen-height (lines &optional pretend)
677 "Obsolete function to change the height of the screen to LINES lines.\n\
678Optional second arg non-nil means that redisplay should use LINES lines\n\
679but that the idea of the actual height of the screen should not be changed.\n\
680This function is provided only for compatibility with Emacs 18; new code\n\
fe668515 681should use `set-frame-width' instead."
9e2b097b
JB
682 (set-frame-height (selected-frame) lines pretend))
683
684(make-obsolete 'screen-height 'frame-height)
685(make-obsolete 'screen-width 'frame-width)
686(make-obsolete 'set-screen-width 'set-frame-width)
687(make-obsolete 'set-screen-height 'set-frame-height)
dc6d9681
JB
688
689\f
64c669bc 690;;;; Key bindings
daa37602 691(defvar ctl-x-5-map (make-sparse-keymap)
dc6d9681 692 "Keymap for frame commands.")
31e1d920 693(defalias 'ctl-x-5-prefix ctl-x-5-map)
daa37602 694(define-key ctl-x-map "5" 'ctl-x-5-prefix)
64c669bc 695
6eb018ba 696(define-key ctl-x-5-map "2" 'make-frame)
dc6d9681 697(define-key ctl-x-5-map "0" 'delete-frame)
ceab6935 698(define-key ctl-x-5-map "o" 'other-frame)
49116ac0 699
dc6d9681 700(provide 'frame)
c88ab9ce 701
dc6d9681 702;;; frame.el ends here