(Fx_create_frame): Pass new arg to make_frame_without_minibuffer.
[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
85557d7e 46take effect until Emacs reads `.emacs', which happens after first creating
de17da15
RS
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
85557d7e 74(defvar special-display-frame-alist
8a9e86e6
RS
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 87;; If ARGS is an alist, use it as a list of frame parameter specs.
85557d7e 88;; If ARGS is a list whose car is a symbol,
95e6cf39
RS
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.
85557d7e 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
85557d7e 133;; These are now called explicitly at the proper times,
fc4d4afb
RS
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 ()
85557d7e 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))))
85557d7e 185 ;; At this point, we know that we have a frame open, so we
dc6d9681
JB
186 ;; can delete the terminal frame.
187 (delete-frame terminal-frame)
188 (setq terminal-frame nil))
85557d7e 189
0759c4d0
KH
190 ;; No, we're not running a window system. Use make-terminal-frame if
191 ;; we support that feature, otherwise arrange to cause errors.
dc6d9681 192 (setq frame-creation-function
0759c4d0
KH
193 (if (fboundp 'make-terminal-frame)
194 'make-terminal-frame
195 (function
196 (lambda (parameters)
197 (error
198 "Can't create multiple frames without a window system")))))))
85557d7e 199
7eadab74
JB
200;;; startup.el calls this function after loading the user's init
201;;; file. Now default-frame-alist and initial-frame-alist contain
202;;; information to which we must react; do what needs to be done.
dc6d9681 203(defun frame-notice-user-settings ()
7eadab74 204
2ffa6186 205 ;; Make menu-bar-mode and default-frame-alist consistent.
b65be6a8
KH
206 (if (boundp 'menu-bar-mode)
207 (let ((default (assq 'menu-bar-lines default-frame-alist)))
208 (if default
209 (setq menu-bar-mode (not (eq (cdr default) 0)))
210 (setq default-frame-alist
211 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
212 default-frame-alist)))))
2ffa6186 213
7eadab74
JB
214 ;; Creating and deleting frames may shift the selected frame around,
215 ;; and thus the current buffer. Protect against that. We don't
216 ;; want to use save-excursion here, because that may also try to set
217 ;; the buffer of the selected window, which fails when the selected
218 ;; window is the minibuffer.
219 (let ((old-buffer (current-buffer)))
220
221 ;; If the initial frame is still around, apply initial-frame-alist
222 ;; and default-frame-alist to it.
223 (if (frame-live-p frame-initial-frame)
224
225 ;; The initial frame we create above always has a minibuffer.
226 ;; If the user wants to remove it, or make it a minibuffer-only
227 ;; frame, then we'll have to delete the current frame and make a
228 ;; new one; you can't remove or add a root window to/from an
229 ;; existing frame.
230 ;;
ec558adc
JB
231 ;; NOTE: default-frame-alist was nil when we created the
232 ;; existing frame. We need to explicitly include
233 ;; default-frame-alist in the parameters of the screen we
234 ;; create here, so that its new value, gleaned from the user's
235 ;; .emacs file, will be applied to the existing screen.
7eadab74
JB
236 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
237 (assq 'minibuffer default-frame-alist)
238 '(minibuffer . t)))
239 t))
240 ;; Create the new frame.
b65e2f74
RS
241 (let (parms new)
242 ;; If the frame isn't visible yet, wait till it is.
243 ;; If the user has to position the window,
244 ;; Emacs doesn't know its real position until
245 ;; the frame is seen to be visible.
246 (while (not (cdr (assq 'visibility
247 (frame-parameters frame-initial-frame))))
248 (sleep-for 1))
249 (setq parms (append initial-frame-alist
6eb018ba
RS
250 default-frame-alist
251 (frame-parameters frame-initial-frame)
252 nil))
c1e67401
RS
253 ;; Get rid of `reverse', because that was handled
254 ;; when we first made the frame.
255 (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
256 (if (assq 'height frame-initial-geometry-arguments)
5b66a32f 257 (setq parms (frame-delete-all 'height parms)))
c1e67401 258 (if (assq 'width frame-initial-geometry-arguments)
5b66a32f 259 (setq parms (frame-delete-all 'width parms)))
c1e67401 260 (if (assq 'left frame-initial-geometry-arguments)
5b66a32f 261 (setq parms (frame-delete-all 'left parms)))
c1e67401 262 (if (assq 'top frame-initial-geometry-arguments)
5b66a32f 263 (setq parms (frame-delete-all 'top parms)))
c1e67401
RS
264 (setq new
265 (make-frame
266 ;; Use the geometry args that created the existing
267 ;; frame, rather than the parms we get for it.
3ce3ff11
KH
268 (append frame-initial-geometry-arguments
269 '((user-size . t) (user-position . t))
270 parms)))
7eadab74
JB
271 ;; The initial frame, which we are about to delete, may be
272 ;; the only frame with a minibuffer. If it is, create a
273 ;; new one.
274 (or (delq frame-initial-frame (minibuffer-frame-list))
6eb018ba 275 (make-frame (append minibuffer-frame-alist
7eadab74
JB
276 '((minibuffer . only)))))
277
278 ;; If the initial frame is serving as a surrogate
279 ;; minibuffer frame for any frames, we need to wean them
280 ;; onto a new frame. The default-minibuffer-frame
281 ;; variable must be handled similarly.
282 (let ((users-of-initial
283 (filtered-frame-list
284 (function (lambda (frame)
285 (and (not (eq frame frame-initial-frame))
286 (eq (window-frame
287 (minibuffer-window frame))
288 frame-initial-frame)))))))
289 (if (or users-of-initial
290 (eq default-minibuffer-frame frame-initial-frame))
291
292 ;; Choose an appropriate frame. Prefer frames which
293 ;; are only minibuffers.
294 (let* ((new-surrogate
295 (car
296 (or (filtered-frame-list
297 (function
298 (lambda (frame)
299 (eq (cdr (assq 'minibuffer
300 (frame-parameters frame)))
301 'only))))
302 (minibuffer-frame-list))))
303 (new-minibuffer (minibuffer-window new-surrogate)))
304
305 (if (eq default-minibuffer-frame frame-initial-frame)
306 (setq default-minibuffer-frame new-surrogate))
307
308 ;; Wean the frames using frame-initial-frame as
309 ;; their minibuffer frame.
310 (mapcar
311 (function
312 (lambda (frame)
313 (modify-frame-parameters
314 frame (list (cons 'minibuffer new-minibuffer)))))
315 users-of-initial))))
ec558adc
JB
316
317 ;; Redirect events enqueued at this frame to the new frame.
318 ;; Is this a good idea?
7eadab74 319 (redirect-frame-focus frame-initial-frame new)
ec558adc 320
7eadab74 321 ;; Finally, get rid of the old frame.
0cffbbb9 322 (delete-frame frame-initial-frame t))
7eadab74
JB
323
324 ;; Otherwise, we don't need all that rigamarole; just apply
325 ;; the new parameters.
3f2f8c83
RS
326 (let (newparms allparms tail)
327 (setq allparms (append initial-frame-alist
328 default-frame-alist))
5b66a32f
RS
329 (if (assq 'height frame-initial-geometry-arguments)
330 (setq allparms (frame-delete-all 'height allparms)))
331 (if (assq 'width frame-initial-geometry-arguments)
332 (setq allparms (frame-delete-all 'width allparms)))
333 (if (assq 'left frame-initial-geometry-arguments)
334 (setq allparms (frame-delete-all 'left allparms)))
335 (if (assq 'top frame-initial-geometry-arguments)
336 (setq allparms (frame-delete-all 'top allparms)))
3f2f8c83
RS
337 (setq tail allparms)
338 ;; Find just the parms that have changed since we first
339 ;; made this frame. Those are the ones actually set by
340 ;; the init file. For those parms whose values we already knew
341 ;; (such as those spec'd by command line options)
342 ;; it is undesirable to specify the parm again
343 ;; once the user has seen the frame and been able to alter it
344 ;; manually.
345 (while tail
346 (let (newval oldval)
66de157d
RS
347 (setq oldval (assq (car (car tail))
348 frame-initial-frame-alist))
3f2f8c83 349 (setq newval (cdr (assq (car (car tail)) allparms)))
66de157d 350 (or (and oldval (eq (cdr oldval) newval))
3f2f8c83
RS
351 (setq newparms
352 (cons (cons (car (car tail)) newval) newparms))))
353 (setq tail (cdr tail)))
86e58378 354 (setq newparms (nreverse newparms))
3f2f8c83 355 (modify-frame-parameters frame-initial-frame
86e58378
RS
356 newparms)
357 (if (assq 'font newparms)
358 (frame-update-faces frame-initial-frame)))))
64c669bc 359
7eadab74
JB
360 ;; Restore the original buffer.
361 (set-buffer old-buffer)
362
363 ;; Make sure the initial frame can be GC'd if it is ever deleted.
d202f1f2
JB
364 ;; Make sure frame-notice-user-settings does nothing if called twice.
365 (setq frame-initial-frame nil)))
64c669bc 366
5b66a32f
RS
367;; Delete from ALIST all elements whose car is KEY.
368;; Return the modified alist.
369(defun frame-delete-all (key alist)
9759578f 370 (setq alist (copy-sequence alist))
5b66a32f
RS
371 (let ((tail alist))
372 (while tail
373 (if (eq (car (car tail)) key)
374 (setq alist (delq (car tail) alist)))
375 (setq tail (cdr tail)))
376 alist))
64c669bc 377\f
7eadab74 378;;;; Creation of additional frames, and other frame miscellanea
dc6d9681 379
7eadab74 380;;; Return some frame other than the current frame, creating one if
eb8c3be9 381;;; necessary. Note that the minibuffer frame, if separate, is not
7eadab74 382;;; considered (see next-frame).
7253d8e0 383(defun get-other-frame ()
dc6d9681 384 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
6eb018ba 385 (make-frame)
dc6d9681 386 (next-frame (selected-frame)))))
64c669bc
JB
387 s))
388
dc6d9681
JB
389(defun next-multiframe-window ()
390 "Select the next window, regardless of which frame it is on."
64c669bc
JB
391 (interactive)
392 (select-window (next-window (selected-window)
393 (> (minibuffer-depth) 0)
394 t)))
395
dc6d9681
JB
396(defun previous-multiframe-window ()
397 "Select the previous window, regardless of which frame it is on."
64c669bc
JB
398 (interactive)
399 (select-window (previous-window (selected-window)
400 (> (minibuffer-depth) 0)
401 t)))
402
6d73e337
RS
403(defun make-frame-on-display (display &optional parameters)
404 "Make a frame on display DISPLAY.
405The optional second argument PARAMETERS specifies additional frame parameters."
406 (interactive "sMake frame on display: ")
407 (make-frame (cons (cons 'display display) parameters)))
408
92e443b1 409;; Alias, kept temporarily.
31e1d920 410(defalias 'new-frame 'make-frame)
92e443b1 411(defun make-frame (&optional parameters)
dc6d9681 412 "Create a new frame, displaying the current buffer.
bc93c097 413
43a2e52c 414Optional argument PARAMETERS is an alist of parameters for the new
a105105a
RS
415frame. Specifically, PARAMETERS is a list of pairs, each having
416the form (NAME . VALUE).
417
418Here are some of the parameters allowed (not a complete list):
43a2e52c 419
eaa974e1 420\(name . STRING) - The frame should be named STRING.
43a2e52c 421
eaa974e1 422\(height . NUMBER) - The frame should be NUMBER text lines high. If
43a2e52c
JB
423 this parameter is present, the width parameter must also be
424 given.
425
eaa974e1 426\(width . NUMBER) - The frame should be NUMBER characters in width.
43a2e52c
JB
427 If this parameter is present, the height parameter must also
428 be given.
429
eaa974e1 430\(minibuffer . t) - the frame should have a minibuffer
0ca90494 431\(minibuffer . nil) - the frame should have no minibuffer
eaa974e1 432\(minibuffer . only) - the frame should contain only a minibuffer
8dbd5c78 433\(minibuffer . WINDOW) - the frame should use WINDOW as its minibuffer window."
64c669bc 434 (interactive)
4133ab49
RS
435 (let ((nframe))
436 (run-hooks 'before-make-frame-hook)
437 (setq nframe (funcall frame-creation-function parameters))
438 (run-hooks 'after-make-frame-hook)
439 nframe))
64c669bc 440
7eadab74
JB
441(defun filtered-frame-list (predicate)
442 "Return a list of all live frames which satisfy PREDICATE."
443 (let ((frames (frame-list))
444 good-frames)
445 (while (consp frames)
446 (if (funcall predicate (car frames))
447 (setq good-frames (cons (car frames) good-frames)))
448 (setq frames (cdr frames)))
449 good-frames))
450
451(defun minibuffer-frame-list ()
452 "Return a list of all frames with their own minibuffers."
453 (filtered-frame-list
454 (function (lambda (frame)
455 (eq frame (window-frame (minibuffer-window frame)))))))
456
58bf6042
JB
457(defun frame-remove-geometry-params (param-list)
458 "Return the parameter list PARAM-LIST, but with geometry specs removed.
459This deletes all bindings in PARAM-LIST for `top', `left', `width',
791e09d8 460`height', `user-size' and `user-position' parameters.
58bf6042
JB
461Emacs uses this to avoid overriding explicit moves and resizings from
462the user during startup."
463 (setq param-list (cons nil param-list))
464 (let ((tail param-list))
465 (while (consp (cdr tail))
466 (if (and (consp (car (cdr tail)))
791e09d8
RS
467 (memq (car (car (cdr tail)))
468 '(height width top left user-position user-size)))
469 (progn
470 (setq frame-initial-geometry-arguments
471 (cons (car (cdr tail)) frame-initial-geometry-arguments))
472 (setcdr tail (cdr (cdr tail))))
58bf6042 473 (setq tail (cdr tail)))))
e11c3dc2
KH
474 (setq frame-initial-geometry-arguments
475 (nreverse frame-initial-geometry-arguments))
58bf6042
JB
476 (cdr param-list))
477
478
ceab6935 479(defun other-frame (arg)
a569dbc3 480 "Select the ARG'th different visible frame, and raise it.
ceab6935
RM
481All frames are arranged in a cyclic order.
482This command selects the frame ARG steps away in that order.
483A negative ARG moves in the opposite order."
484 (interactive "p")
485 (let ((frame (selected-frame)))
486 (while (> arg 0)
a569dbc3
RM
487 (setq frame (next-frame frame))
488 (while (not (eq (frame-visible-p frame) t))
489 (setq frame (next-frame frame)))
490 (setq arg (1- arg)))
ceab6935 491 (while (< arg 0)
a569dbc3
RM
492 (setq frame (previous-frame frame))
493 (while (not (eq (frame-visible-p frame) t))
494 (setq frame (previous-frame frame)))
915cfd1f 495 (setq arg (1+ arg)))
ceab6935 496 (raise-frame frame)
699213bc 497 (select-frame frame)
2b88f7a0 498 (set-mouse-position (selected-frame) (1- (frame-width)) 0)
b65be6a8
KH
499 (if (fboundp 'unfocus-frame)
500 (unfocus-frame))))
64c669bc 501\f
dc6d9681
JB
502;;;; Frame configurations
503
504(defun current-frame-configuration ()
505 "Return a list describing the positions and states of all frames.
376a7584
JB
506Its car is `frame-configuration'.
507Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
508where
509 FRAME is a frame object,
510 ALIST is an association list specifying some of FRAME's parameters, and
511 WINDOW-CONFIG is a window configuration object for FRAME."
512 (cons 'frame-configuration
513 (mapcar (function
514 (lambda (frame)
515 (list frame
516 (frame-parameters frame)
517 (current-window-configuration frame))))
518 (frame-list))))
dc6d9681 519
68cd265f 520(defun set-frame-configuration (configuration &optional nodelete)
dc6d9681
JB
521 "Restore the frames to the state described by CONFIGURATION.
522Each frame listed in CONFIGURATION has its position, size, window
68cd265f 523configuration, and other parameters set as specified in CONFIGURATION.
a78db71c
RS
524Ordinarily, this function deletes all existing frames not
525listed in CONFIGURATION. But if optional second argument NODELETE
5da841d2 526is given and non-nil, the unwanted frames are iconified instead."
376a7584
JB
527 (or (frame-configuration-p configuration)
528 (signal 'wrong-type-argument
529 (list 'frame-configuration-p configuration)))
530 (let ((config-alist (cdr configuration))
531 frames-to-delete)
06b1a5ef 532 (mapcar (function
dc6d9681 533 (lambda (frame)
376a7584 534 (let ((parameters (assq frame config-alist)))
06b1a5ef
JB
535 (if parameters
536 (progn
98e9d14b
JB
537 (modify-frame-parameters
538 frame
85557d7e 539 ;; Since we can't set a frame's minibuffer status,
98e9d14b
JB
540 ;; we might as well omit the parameter altogether.
541 (let* ((parms (nth 1 parameters))
542 (mini (assq 'minibuffer parms)))
543 (if mini (setq parms (delq mini parms)))
544 parms))
06b1a5ef 545 (set-window-configuration (nth 2 parameters)))
dc6d9681
JB
546 (setq frames-to-delete (cons frame frames-to-delete))))))
547 (frame-list))
a78db71c 548 (if nodelete
5da841d2
RS
549 ;; Note: making frames invisible here was tried
550 ;; but led to some strange behavior--each time the frame
551 ;; was made visible again, the window manager asked afresh
552 ;; for where to put it.
553 (mapcar 'iconify-frame frames-to-delete)
a78db71c 554 (mapcar 'delete-frame frames-to-delete))))
64c669bc 555
376a7584
JB
556(defun frame-configuration-p (object)
557 "Return non-nil if OBJECT seems to be a frame configuration.
558Any list whose car is `frame-configuration' is assumed to be a frame
559configuration."
560 (and (consp object)
561 (eq (car object) 'frame-configuration)))
562
64c669bc 563\f
dc6d9681
JB
564;;;; Convenience functions for accessing and interactively changing
565;;;; frame parameters.
64c669bc 566
151bdc83 567(defun frame-height (&optional frame)
dc6d9681
JB
568 "Return number of lines available for display on FRAME.
569If FRAME is omitted, describe the currently selected frame."
151bdc83 570 (cdr (assq 'height (frame-parameters frame))))
dc6d9681
JB
571
572(defun frame-width (&optional frame)
573 "Return number of columns available for display on FRAME.
574If FRAME is omitted, describe the currently selected frame."
151bdc83 575 (cdr (assq 'width (frame-parameters frame))))
dc6d9681 576
64c669bc 577(defun set-default-font (font-name)
7eadab74
JB
578 "Set the font of the selected frame to FONT.
579When called interactively, prompt for the name of the font to use."
64c669bc 580 (interactive "sFont name: ")
dc6d9681 581 (modify-frame-parameters (selected-frame)
4033f46b
RS
582 (list (cons 'font font-name)))
583 ;; Update faces that want a bold or italic version of the default font.
584 (frame-update-faces (selected-frame)))
64c669bc 585
8290babd 586(defun set-background-color (color-name)
7eadab74
JB
587 "Set the background color of the selected frame to COLOR.
588When called interactively, prompt for the name of the color to use."
64c669bc 589 (interactive "sColor: ")
dc6d9681 590 (modify-frame-parameters (selected-frame)
1787c22a
RS
591 (list (cons 'background-color color-name)))
592 (frame-update-face-colors (selected-frame)))
64c669bc 593
8290babd 594(defun set-foreground-color (color-name)
7eadab74
JB
595 "Set the foreground color of the selected frame to COLOR.
596When called interactively, prompt for the name of the color to use."
64c669bc 597 (interactive "sColor: ")
dc6d9681 598 (modify-frame-parameters (selected-frame)
1787c22a
RS
599 (list (cons 'foreground-color color-name)))
600 (frame-update-face-colors (selected-frame)))
64c669bc
JB
601
602(defun set-cursor-color (color-name)
7eadab74
JB
603 "Set the text cursor color of the selected frame to COLOR.
604When called interactively, prompt for the name of the color to use."
64c669bc 605 (interactive "sColor: ")
dc6d9681 606 (modify-frame-parameters (selected-frame)
7eadab74 607 (list (cons 'cursor-color color-name))))
64c669bc 608
eaa974e1 609(defun set-mouse-color (color-name)
7eadab74
JB
610 "Set the color of the mouse pointer of the selected frame to COLOR.
611When called interactively, prompt for the name of the color to use."
64c669bc 612 (interactive "sColor: ")
dc6d9681 613 (modify-frame-parameters (selected-frame)
7eadab74
JB
614 (list (cons 'mouse-color color-name))))
615
eaa974e1
JB
616(defun set-border-color (color-name)
617 "Set the color of the border of the selected frame to COLOR.
618When called interactively, prompt for the name of the color to use."
619 (interactive "sColor: ")
620 (modify-frame-parameters (selected-frame)
621 (list (cons 'border-color color-name))))
622
623(defun auto-raise-mode (arg)
7eadab74 624 "Toggle whether or not the selected frame should auto-raise.
79e6ae33
RS
625With arg, turn auto-raise mode on if and only if arg is positive.
626Note that this controls Emacs's own auto-raise feature.
627Some window managers allow you to enable auto-raise for certain windows.
628You can use that for Emacs windows if you wish, but if you do,
629that is beyond the control of Emacs and this command has no effect on it."
7eadab74
JB
630 (interactive "P")
631 (if (null arg)
632 (setq arg
633 (if (cdr (assq 'auto-raise (frame-parameters (selected-frame))))
634 -1 1)))
dc6d9681 635 (modify-frame-parameters (selected-frame)
7eadab74
JB
636 (list (cons 'auto-raise (> arg 0)))))
637
eaa974e1 638(defun auto-lower-mode (arg)
7eadab74 639 "Toggle whether or not the selected frame should auto-lower.
79e6ae33
RS
640With arg, turn auto-lower mode on if and only if arg is positive.
641Note that this controls Emacs's own auto-lower feature.
642Some window managers allow you to enable auto-lower for certain windows.
643You can use that for Emacs windows if you wish, but if you do,
644that is beyond the control of Emacs and this command has no effect on it."
7eadab74
JB
645 (interactive "P")
646 (if (null arg)
647 (setq arg
648 (if (cdr (assq 'auto-lower (frame-parameters (selected-frame))))
649 -1 1)))
dc6d9681 650 (modify-frame-parameters (selected-frame)
7eadab74
JB
651 (list (cons 'auto-lower (> arg 0)))))
652
7e85c6b5 653(defun toggle-scroll-bar (arg)
0ca90494
JB
654 "Toggle whether or not the selected frame has vertical scroll bars.
655With arg, turn vertical scroll bars on if and only if arg is positive."
7eadab74
JB
656 (interactive "P")
657 (if (null arg)
658 (setq arg
0ca90494 659 (if (cdr (assq 'vertical-scroll-bars
7eadab74
JB
660 (frame-parameters (selected-frame))))
661 -1 1)))
dc6d9681 662 (modify-frame-parameters (selected-frame)
0ca90494 663 (list (cons 'vertical-scroll-bars (> arg 0)))))
7eadab74 664
8290babd 665(defun toggle-horizontal-scroll-bar (arg)
0ca90494
JB
666 "Toggle whether or not the selected frame has horizontal scroll bars.
667With arg, turn horizontal scroll bars on if and only if arg is positive.
668Horizontal scroll bars aren't implemented yet."
7eadab74 669 (interactive "P")
8290babd 670 (error "Horizontal scroll bars aren't implemented yet"))
64c669bc 671
64c669bc 672\f
dc6d9681 673;;;; Aliases for backward compatibility with Emacs 18.
31e1d920
ER
674(defalias 'screen-height 'frame-height)
675(defalias 'screen-width 'frame-width)
9e2b097b
JB
676
677(defun set-screen-width (cols &optional pretend)
678 "Obsolete function to change the size of the screen to COLS columns.\n\
679Optional second arg non-nil means that redisplay should use COLS columns\n\
680but that the idea of the actual width of the frame should not be changed.\n\
681This function is provided only for compatibility with Emacs 18; new code\n\
fe668515 682should use `set-frame-width instead'."
9e2b097b
JB
683 (set-frame-width (selected-frame) cols pretend))
684
685(defun set-screen-height (lines &optional pretend)
686 "Obsolete function to change the height of the screen to LINES lines.\n\
687Optional second arg non-nil means that redisplay should use LINES lines\n\
688but that the idea of the actual height of the screen should not be changed.\n\
689This function is provided only for compatibility with Emacs 18; new code\n\
fe668515 690should use `set-frame-width' instead."
9e2b097b
JB
691 (set-frame-height (selected-frame) lines pretend))
692
693(make-obsolete 'screen-height 'frame-height)
694(make-obsolete 'screen-width 'frame-width)
695(make-obsolete 'set-screen-width 'set-frame-width)
696(make-obsolete 'set-screen-height 'set-frame-height)
dc6d9681
JB
697
698\f
64c669bc 699;;;; Key bindings
daa37602 700(defvar ctl-x-5-map (make-sparse-keymap)
dc6d9681 701 "Keymap for frame commands.")
31e1d920 702(defalias 'ctl-x-5-prefix ctl-x-5-map)
daa37602 703(define-key ctl-x-map "5" 'ctl-x-5-prefix)
64c669bc 704
6eb018ba 705(define-key ctl-x-5-map "2" 'make-frame)
dc6d9681 706(define-key ctl-x-5-map "0" 'delete-frame)
ceab6935 707(define-key ctl-x-5-map "o" 'other-frame)
49116ac0 708
dc6d9681 709(provide 'frame)
c88ab9ce 710
dc6d9681 711;;; frame.el ends here