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