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