(shell-input-autoexpand): Fix customization group.
[bpt/emacs.git] / lisp / frame.el
1 ;;; frame.el --- multi-frame management independent of window systems.
2
3 ;; Copyright (C) 1993, 1994, 1996, 1997 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
6 ;; Keywords: internal
7
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.
24
25 ;;; Code:
26
27 (defvar frame-creation-function nil
28 "Window-system dependent function to call to create a new frame.
29 The window system startup file should set this to its frame creation
30 function, which should take an alist of parameters as its argument.")
31
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
36 "Alist of frame parameters for creating the initial X window frame.
37 You can set this in your `.emacs' file; for example,
38 (setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55)))
39 Parameters specified here supersede the values given in `default-frame-alist'.
40
41 If the value calls for a frame without a minibuffer, and you have not created
42 a minibuffer frame on your own, one is created according to
43 `minibuffer-frame-alist'.
44
45 You can specify geometry-related options for just the initial frame
46 by setting this variable in your `.emacs' file; however, they won't
47 take effect until Emacs reads `.emacs', which happens after first creating
48 the frame. If you want the frame to have the proper geometry as soon
49 as 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'.")
55
56 (defvar minibuffer-frame-alist '((width . 80) (height . 2))
57 "Alist of frame parameters for initially creating a minibuffer frame.
58 You can set this in your `.emacs' file; for example,
59 (setq minibuffer-frame-alist
60 '((top . 1) (left . 1) (width . 80) (height . 2)))
61 Parameters specified here supersede the values given in
62 `default-frame-alist'.")
63
64 (defvar pop-up-frame-alist nil
65 "Alist of frame parameters used when creating pop-up frames.
66 Pop-up frames are used for completions, help, and the like.
67 This variable can be set in your init file, like this:
68 (setq pop-up-frame-alist '((width . 80) (height . 20)))
69 These supersede the values given in `default-frame-alist'.")
70
71 (setq pop-up-frame-function
72 (function (lambda ()
73 (make-frame pop-up-frame-alist))))
74
75 (defcustom special-display-frame-alist
76 '((height . 14) (width . 80) (unsplittable . t))
77 "*Alist of frame parameters used when creating special frames.
78 Special frames are used for buffers whose names are in
79 `special-display-buffer-names' and for buffers whose names match
80 one of the regular expressions in `special-display-regexps'.
81 This variable can be set in your init file, like this:
82 (setq special-display-frame-alist '((width . 80) (height . 20)))
83 These 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)
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.
92 ;; If ARGS is an alist, use it as a list of frame parameter specs.
93 ;; If ARGS is a list whose car is a symbol,
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))))))
111
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)
125 ;; Gildea@x.org says it is ok to ask questions before terminating.
126 (save-buffers-kill-emacs))))
127 \f
128 ;;;; Arrangement of frames at startup
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
132 ;;; file should create any frames specified in the window system defaults.
133 ;;;
134 ;;; 2) If no frames have been opened, we open an initial text frame.
135 ;;;
136 ;;; 3) Once the init file is done, we apply any newly set parameters
137 ;;; in initial-frame-alist to the frame.
138
139 ;; These are now called explicitly at the proper times,
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)
144
145 ;;; If we create the initial frame, this is it.
146 (defvar frame-initial-frame nil)
147
148 ;; Record the parameters used in frame-initialize to make the initial frame.
149 (defvar frame-initial-frame-alist)
150
151 (defvar frame-initial-geometry-arguments nil)
152
153 ;;; startup.el calls this function before loading the user's init
154 ;;; file - if there is no frame with a minibuffer open now, create
155 ;;; one to display messages while loading the init file.
156 (defun frame-initialize ()
157
158 ;; Are we actually running under a window system at all?
159 (if (and window-system (not noninteractive) (not (eq window-system 'pc)))
160 (progn
161 ;; Turn on special-display processing only if there's a window system.
162 (setq special-display-function 'special-display-popup-frame)
163
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))
169 (progn
170 (setq frame-initial-frame-alist
171 (append initial-frame-alist default-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)))
176 (setq default-minibuffer-frame
177 (setq frame-initial-frame
178 (make-frame frame-initial-frame-alist)))
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.
183 (setq initial-frame-alist
184 (frame-remove-geometry-params initial-frame-alist))))
185 ;; At this point, we know that we have a frame open, so we
186 ;; can delete the terminal frame.
187 (delete-frame terminal-frame)
188 (setq terminal-frame nil))
189
190 ;; No, we're not running a window system. Use make-terminal-frame if
191 ;; we support that feature, otherwise arrange to cause errors.
192 (or (eq window-system 'pc)
193 (setq frame-creation-function
194 (if (fboundp 'make-terminal-frame)
195 'make-terminal-frame
196 (function
197 (lambda (parameters)
198 (error
199 "Can't create multiple frames without a window system"))))))))
200
201 ;;; startup.el calls this function after loading the user's init
202 ;;; file. Now default-frame-alist and initial-frame-alist contain
203 ;;; information to which we must react; do what needs to be done.
204 (defun frame-notice-user-settings ()
205
206 ;; Make menu-bar-mode and default-frame-alist consistent.
207 (if (boundp 'menu-bar-mode)
208 (let ((default (assq 'menu-bar-lines default-frame-alist)))
209 (if default
210 (setq menu-bar-mode (not (eq (cdr default) 0)))
211 (setq default-frame-alist
212 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
213 default-frame-alist)))))
214
215 ;; Creating and deleting frames may shift the selected frame around,
216 ;; and thus the current buffer. Protect against that. We don't
217 ;; want to use save-excursion here, because that may also try to set
218 ;; the buffer of the selected window, which fails when the selected
219 ;; window is the minibuffer.
220 (let ((old-buffer (current-buffer)))
221
222 ;; If the initial frame is still around, apply initial-frame-alist
223 ;; and default-frame-alist to it.
224 (if (frame-live-p frame-initial-frame)
225
226 ;; The initial frame we create above always has a minibuffer.
227 ;; If the user wants to remove it, or make it a minibuffer-only
228 ;; frame, then we'll have to delete the current frame and make a
229 ;; new one; you can't remove or add a root window to/from an
230 ;; existing frame.
231 ;;
232 ;; NOTE: default-frame-alist was nil when we created the
233 ;; existing frame. We need to explicitly include
234 ;; default-frame-alist in the parameters of the screen we
235 ;; create here, so that its new value, gleaned from the user's
236 ;; .emacs file, will be applied to the existing screen.
237 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
238 (assq 'minibuffer default-frame-alist)
239 '(minibuffer . t)))
240 t))
241 ;; Create the new frame.
242 (let (parms new)
243 ;; If the frame isn't visible yet, wait till it is.
244 ;; If the user has to position the window,
245 ;; Emacs doesn't know its real position until
246 ;; the frame is seen to be visible.
247 (while (not (cdr (assq 'visibility
248 (frame-parameters frame-initial-frame))))
249 (sleep-for 1))
250 (setq parms (frame-parameters frame-initial-frame))
251 ;; Get rid of `name' unless it was specified explicitly before.
252 (or (assq 'name frame-initial-frame-alist)
253 (setq parms (delq (assq 'name parms) parms)))
254 (setq parms (append initial-frame-alist
255 default-frame-alist
256 parms
257 nil))
258 ;; Get rid of `reverse', because that was handled
259 ;; when we first made the frame.
260 (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
261 (if (assq 'height frame-initial-geometry-arguments)
262 (setq parms (frame-delete-all 'height parms)))
263 (if (assq 'width frame-initial-geometry-arguments)
264 (setq parms (frame-delete-all 'width parms)))
265 (if (assq 'left frame-initial-geometry-arguments)
266 (setq parms (frame-delete-all 'left parms)))
267 (if (assq 'top frame-initial-geometry-arguments)
268 (setq parms (frame-delete-all 'top parms)))
269 (setq new
270 (make-frame
271 ;; Use the geometry args that created the existing
272 ;; frame, rather than the parms we get for it.
273 (append frame-initial-geometry-arguments
274 '((user-size . t) (user-position . t))
275 parms)))
276 ;; The initial frame, which we are about to delete, may be
277 ;; the only frame with a minibuffer. If it is, create a
278 ;; new one.
279 (or (delq frame-initial-frame (minibuffer-frame-list))
280 (make-initial-minibuffer-frame nil))
281
282 ;; If the initial frame is serving as a surrogate
283 ;; minibuffer frame for any frames, we need to wean them
284 ;; onto a new frame. The default-minibuffer-frame
285 ;; variable must be handled similarly.
286 (let ((users-of-initial
287 (filtered-frame-list
288 (function (lambda (frame)
289 (and (not (eq frame frame-initial-frame))
290 (eq (window-frame
291 (minibuffer-window frame))
292 frame-initial-frame)))))))
293 (if (or users-of-initial
294 (eq default-minibuffer-frame frame-initial-frame))
295
296 ;; Choose an appropriate frame. Prefer frames which
297 ;; are only minibuffers.
298 (let* ((new-surrogate
299 (car
300 (or (filtered-frame-list
301 (function
302 (lambda (frame)
303 (eq (cdr (assq 'minibuffer
304 (frame-parameters frame)))
305 'only))))
306 (minibuffer-frame-list))))
307 (new-minibuffer (minibuffer-window new-surrogate)))
308
309 (if (eq default-minibuffer-frame frame-initial-frame)
310 (setq default-minibuffer-frame new-surrogate))
311
312 ;; Wean the frames using frame-initial-frame as
313 ;; their minibuffer frame.
314 (mapcar
315 (function
316 (lambda (frame)
317 (modify-frame-parameters
318 frame (list (cons 'minibuffer new-minibuffer)))))
319 users-of-initial))))
320
321 ;; Redirect events enqueued at this frame to the new frame.
322 ;; Is this a good idea?
323 (redirect-frame-focus frame-initial-frame new)
324
325 ;; Finally, get rid of the old frame.
326 (delete-frame frame-initial-frame t))
327
328 ;; Otherwise, we don't need all that rigamarole; just apply
329 ;; the new parameters.
330 (let (newparms allparms tail)
331 (setq allparms (append initial-frame-alist
332 default-frame-alist))
333 (if (assq 'height frame-initial-geometry-arguments)
334 (setq allparms (frame-delete-all 'height allparms)))
335 (if (assq 'width frame-initial-geometry-arguments)
336 (setq allparms (frame-delete-all 'width allparms)))
337 (if (assq 'left frame-initial-geometry-arguments)
338 (setq allparms (frame-delete-all 'left allparms)))
339 (if (assq 'top frame-initial-geometry-arguments)
340 (setq allparms (frame-delete-all 'top allparms)))
341 (setq tail allparms)
342 ;; Find just the parms that have changed since we first
343 ;; made this frame. Those are the ones actually set by
344 ;; the init file. For those parms whose values we already knew
345 ;; (such as those spec'd by command line options)
346 ;; it is undesirable to specify the parm again
347 ;; once the user has seen the frame and been able to alter it
348 ;; manually.
349 (while tail
350 (let (newval oldval)
351 (setq oldval (assq (car (car tail))
352 frame-initial-frame-alist))
353 (setq newval (cdr (assq (car (car tail)) allparms)))
354 (or (and oldval (eq (cdr oldval) newval))
355 (setq newparms
356 (cons (cons (car (car tail)) newval) newparms))))
357 (setq tail (cdr tail)))
358 (setq newparms (nreverse newparms))
359 (modify-frame-parameters frame-initial-frame
360 newparms)
361 (if (assq 'font newparms)
362 (frame-update-faces frame-initial-frame)))))
363
364 ;; Restore the original buffer.
365 (set-buffer old-buffer)
366
367 ;; Make sure the initial frame can be GC'd if it is ever deleted.
368 ;; Make sure frame-notice-user-settings does nothing if called twice.
369 (setq frame-initial-frame nil)))
370
371 (defun make-initial-minibuffer-frame (display)
372 (let ((parms (append minibuffer-frame-alist '((minibuffer . only)))))
373 (if display
374 (make-frame-on-display display parms)
375 (make-frame parms))))
376
377 ;; Delete from ALIST all elements whose car is KEY.
378 ;; Return the modified alist.
379 (defun frame-delete-all (key alist)
380 (setq alist (copy-sequence alist))
381 (let ((tail alist))
382 (while tail
383 (if (eq (car (car tail)) key)
384 (setq alist (delq (car tail) alist)))
385 (setq tail (cdr tail)))
386 alist))
387 \f
388 ;;;; Creation of additional frames, and other frame miscellanea
389
390 ;;; Return some frame other than the current frame, creating one if
391 ;;; necessary. Note that the minibuffer frame, if separate, is not
392 ;;; considered (see next-frame).
393 (defun get-other-frame ()
394 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
395 (make-frame)
396 (next-frame (selected-frame)))))
397 s))
398
399 (defun next-multiframe-window ()
400 "Select the next window, regardless of which frame it is on."
401 (interactive)
402 (select-window (next-window (selected-window)
403 (> (minibuffer-depth) 0)
404 t)))
405
406 (defun previous-multiframe-window ()
407 "Select the previous window, regardless of which frame it is on."
408 (interactive)
409 (select-window (previous-window (selected-window)
410 (> (minibuffer-depth) 0)
411 t)))
412
413 (defun make-frame-on-display (display &optional parameters)
414 "Make a frame on display DISPLAY.
415 The optional second argument PARAMETERS specifies additional frame parameters."
416 (interactive "sMake frame on display: ")
417 (or (string-match "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display)
418 (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
419 (make-frame (cons (cons 'display display) parameters)))
420
421 (defun make-frame-command ()
422 "Make a new frame, and select it if the terminal displays only one frame."
423 (interactive)
424 (if (and window-system (not (eq window-system 'pc)))
425 (make-frame)
426 (select-frame (make-frame))))
427
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.
433 The functions are run with one arg, the newly created frame.")
434
435 ;; Alias, kept temporarily.
436 (defalias 'new-frame 'make-frame)
437
438 (defun make-frame (&optional parameters)
439 "Return a newly created frame displaying the current buffer.
440 Optional argument PARAMETERS is an alist of parameters for the new frame.
441 Each element of PARAMETERS should have the form (NAME . VALUE), for example:
442
443 (name . STRING) The frame should be named STRING.
444
445 (width . NUMBER) The frame should be NUMBER characters in width.
446 (height . NUMBER) The frame should be NUMBER text lines high.
447
448 You cannot specify either `width' or `height', you must use neither or both.
449
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.
454
455 Before the frame is created (via `frame-creation-function'), functions on the
456 hook `before-make-frame-hook' are run. After the frame is created, functions
457 on `after-make-frame-functions' are run with one arg, the newly created frame."
458 (interactive)
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))
463
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
480 (defun frame-remove-geometry-params (param-list)
481 "Return the parameter list PARAM-LIST, but with geometry specs removed.
482 This deletes all bindings in PARAM-LIST for `top', `left', `width',
483 `height', `user-size' and `user-position' parameters.
484 Emacs uses this to avoid overriding explicit moves and resizings from
485 the 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)))
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))))
496 (setq tail (cdr tail)))))
497 (setq frame-initial-geometry-arguments
498 (nreverse frame-initial-geometry-arguments))
499 (cdr param-list))
500
501
502 (defcustom focus-follows-mouse t
503 "*Non-nil if window system changes focus when you move the mouse."
504 :type 'boolean
505 :group 'frames
506 :version "20.3")
507
508 (defun other-frame (arg)
509 "Select the ARG'th different visible frame, and raise it.
510 All frames are arranged in a cyclic order.
511 This command selects the frame ARG steps away in that order.
512 A negative ARG moves in the opposite order."
513 (interactive "p")
514 (let ((frame (selected-frame)))
515 (while (> arg 0)
516 (setq frame (next-frame frame))
517 (while (not (eq (frame-visible-p frame) t))
518 (setq frame (next-frame frame)))
519 (setq arg (1- arg)))
520 (while (< arg 0)
521 (setq frame (previous-frame frame))
522 (while (not (eq (frame-visible-p frame) t))
523 (setq frame (previous-frame frame)))
524 (setq arg (1+ arg)))
525 (raise-frame frame)
526 (select-frame frame)
527 ;; Ensure, if possible, that frame gets input focus.
528 (if (eq window-system 'w32)
529 (w32-focus-frame frame)
530 (when focus-follows-mouse
531 (set-mouse-position (selected-frame) (1- (frame-width)) 0)))))
532
533 (defun make-frame-names-alist ()
534 (let* ((current-frame (selected-frame))
535 (falist
536 (cons
537 (cons (frame-parameter current-frame 'name) current-frame) nil))
538 (frame (next-frame nil t)))
539 (while (not (eq frame current-frame))
540 (progn
541 (setq falist (cons (cons (frame-parameter frame 'name) frame) falist))
542 (setq frame (next-frame frame t))))
543 falist))
544
545 (defvar frame-name-history nil)
546 (defun select-frame-by-name (name)
547 "Select the frame whose name is NAME and raise it.
548 If there is no frame by that name, signal an error."
549 (interactive
550 (let* ((frame-names-alist (make-frame-names-alist))
551 (default (car (car frame-names-alist)))
552 (input (completing-read
553 (format "Select Frame (default %s): " default)
554 frame-names-alist nil t nil 'frame-name-history)))
555 (if (= (length input) 0)
556 (list default)
557 (list input))))
558 (let* ((frame-names-alist (make-frame-names-alist))
559 (frame (cdr (assoc name frame-names-alist))))
560 (or frame
561 (error "There is no frame named `%s'" name))
562 (make-frame-visible frame)
563 (raise-frame frame)
564 (select-frame frame)))
565 \f
566 ;;;; Frame configurations
567
568 (defun current-frame-configuration ()
569 "Return a list describing the positions and states of all frames.
570 Its car is `frame-configuration'.
571 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
572 where
573 FRAME is a frame object,
574 ALIST is an association list specifying some of FRAME's parameters, and
575 WINDOW-CONFIG is a window configuration object for FRAME."
576 (cons 'frame-configuration
577 (mapcar (function
578 (lambda (frame)
579 (list frame
580 (frame-parameters frame)
581 (current-window-configuration frame))))
582 (frame-list))))
583
584 (defun set-frame-configuration (configuration &optional nodelete)
585 "Restore the frames to the state described by CONFIGURATION.
586 Each frame listed in CONFIGURATION has its position, size, window
587 configuration, and other parameters set as specified in CONFIGURATION.
588 Ordinarily, this function deletes all existing frames not
589 listed in CONFIGURATION. But if optional second argument NODELETE
590 is given and non-nil, the unwanted frames are iconified instead."
591 (or (frame-configuration-p configuration)
592 (signal 'wrong-type-argument
593 (list 'frame-configuration-p configuration)))
594 (let ((config-alist (cdr configuration))
595 frames-to-delete)
596 (mapcar (function
597 (lambda (frame)
598 (let ((parameters (assq frame config-alist)))
599 (if parameters
600 (progn
601 (modify-frame-parameters
602 frame
603 ;; Since we can't set a frame's minibuffer status,
604 ;; we might as well omit the parameter altogether.
605 (let* ((parms (nth 1 parameters))
606 (mini (assq 'minibuffer parms)))
607 (if mini (setq parms (delq mini parms)))
608 parms))
609 (set-window-configuration (nth 2 parameters)))
610 (setq frames-to-delete (cons frame frames-to-delete))))))
611 (frame-list))
612 (if nodelete
613 ;; Note: making frames invisible here was tried
614 ;; but led to some strange behavior--each time the frame
615 ;; was made visible again, the window manager asked afresh
616 ;; for where to put it.
617 (mapcar 'iconify-frame frames-to-delete)
618 (mapcar 'delete-frame frames-to-delete))))
619 \f
620 ;;;; Convenience functions for accessing and interactively changing
621 ;;;; frame parameters.
622
623 (defun frame-parameter (frame parameter)
624 "Return FRAME's value for parameter PARAMETER.
625 If FRAME is omitted, describe the currently selected frame."
626 (cdr (assq parameter (frame-parameters frame))))
627
628 (defun frame-height (&optional frame)
629 "Return number of lines available for display on FRAME.
630 If FRAME is omitted, describe the currently selected frame."
631 (cdr (assq 'height (frame-parameters frame))))
632
633 (defun frame-width (&optional frame)
634 "Return number of columns available for display on FRAME.
635 If FRAME is omitted, describe the currently selected frame."
636 (cdr (assq 'width (frame-parameters frame))))
637
638 (defalias 'set-default-font 'set-frame-font)
639 (defun set-frame-font (font-name)
640 "Set the font of the selected frame to FONT.
641 When called interactively, prompt for the name of the font to use.
642 To get the frame's current default font, use `frame-parameters'."
643 (interactive "sFont name: ")
644 (modify-frame-parameters (selected-frame)
645 (list (cons 'font font-name)))
646 ;; Update faces that want a bold or italic version of the default font.
647 (frame-update-faces (selected-frame)))
648
649 (defun set-background-color (color-name)
650 "Set the background color of the selected frame to COLOR.
651 When called interactively, prompt for the name of the color to use.
652 To get the frame's current background color, use `frame-parameters'."
653 (interactive "sColor: ")
654 (modify-frame-parameters (selected-frame)
655 (list (cons 'background-color color-name)))
656 (frame-update-face-colors (selected-frame)))
657
658 (defun set-foreground-color (color-name)
659 "Set the foreground color of the selected frame to COLOR.
660 When called interactively, prompt for the name of the color to use.
661 To get the frame's current foreground color, use `frame-parameters'."
662 (interactive "sColor: ")
663 (modify-frame-parameters (selected-frame)
664 (list (cons 'foreground-color color-name)))
665 (frame-update-face-colors (selected-frame)))
666
667 (defun set-cursor-color (color-name)
668 "Set the text cursor color of the selected frame to COLOR.
669 When called interactively, prompt for the name of the color to use.
670 To get the frame's current cursor color, use `frame-parameters'."
671 (interactive "sColor: ")
672 (modify-frame-parameters (selected-frame)
673 (list (cons 'cursor-color color-name))))
674
675 (defun set-mouse-color (color-name)
676 "Set the color of the mouse pointer of the selected frame to COLOR.
677 When called interactively, prompt for the name of the color to use.
678 To get the frame's current mouse color, use `frame-parameters'."
679 (interactive "sColor: ")
680 (modify-frame-parameters (selected-frame)
681 (list (cons 'mouse-color color-name))))
682
683 (defun set-border-color (color-name)
684 "Set the color of the border of the selected frame to COLOR.
685 When called interactively, prompt for the name of the color to use.
686 To get the frame's current border color, use `frame-parameters'."
687 (interactive "sColor: ")
688 (modify-frame-parameters (selected-frame)
689 (list (cons 'border-color color-name))))
690
691 (defun auto-raise-mode (arg)
692 "Toggle whether or not the selected frame should auto-raise.
693 With arg, turn auto-raise mode on if and only if arg is positive.
694 Note that this controls Emacs's own auto-raise feature.
695 Some window managers allow you to enable auto-raise for certain windows.
696 You can use that for Emacs windows if you wish, but if you do,
697 that is beyond the control of Emacs and this command has no effect on it."
698 (interactive "P")
699 (if (null arg)
700 (setq arg
701 (if (cdr (assq 'auto-raise (frame-parameters (selected-frame))))
702 -1 1)))
703 (modify-frame-parameters (selected-frame)
704 (list (cons 'auto-raise (> arg 0)))))
705
706 (defun auto-lower-mode (arg)
707 "Toggle whether or not the selected frame should auto-lower.
708 With arg, turn auto-lower mode on if and only if arg is positive.
709 Note that this controls Emacs's own auto-lower feature.
710 Some window managers allow you to enable auto-lower for certain windows.
711 You can use that for Emacs windows if you wish, but if you do,
712 that is beyond the control of Emacs and this command has no effect on it."
713 (interactive "P")
714 (if (null arg)
715 (setq arg
716 (if (cdr (assq 'auto-lower (frame-parameters (selected-frame))))
717 -1 1)))
718 (modify-frame-parameters (selected-frame)
719 (list (cons 'auto-lower (> arg 0)))))
720 (defun set-frame-name (name)
721 "Set the name of the selected frame to NAME.
722 When called interactively, prompt for the name of the frame.
723 The frame name is displayed on the modeline if the terminal displays only
724 one frame, otherwise the name is displayed on the frame's caption bar."
725 (interactive "sFrame name: ")
726 (modify-frame-parameters (selected-frame)
727 (list (cons 'name name))))
728 \f
729 ;;;; Aliases for backward compatibility with Emacs 18.
730 (defalias 'screen-height 'frame-height)
731 (defalias 'screen-width 'frame-width)
732
733 (defun set-screen-width (cols &optional pretend)
734 "Obsolete function to change the size of the screen to COLS columns.\n\
735 Optional second arg non-nil means that redisplay should use COLS columns\n\
736 but that the idea of the actual width of the frame should not be changed.\n\
737 This function is provided only for compatibility with Emacs 18; new code\n\
738 should use `set-frame-width instead'."
739 (set-frame-width (selected-frame) cols pretend))
740
741 (defun set-screen-height (lines &optional pretend)
742 "Obsolete function to change the height of the screen to LINES lines.\n\
743 Optional second arg non-nil means that redisplay should use LINES lines\n\
744 but that the idea of the actual height of the screen should not be changed.\n\
745 This function is provided only for compatibility with Emacs 18; new code\n\
746 should use `set-frame-height' instead."
747 (set-frame-height (selected-frame) lines pretend))
748
749 (make-obsolete 'screen-height 'frame-height)
750 (make-obsolete 'screen-width 'frame-width)
751 (make-obsolete 'set-screen-width 'set-frame-width)
752 (make-obsolete 'set-screen-height 'set-frame-height)
753
754 \f
755 ;;;; Key bindings
756
757 (define-key ctl-x-5-map "2" 'make-frame-command)
758 (define-key ctl-x-5-map "0" 'delete-frame)
759 (define-key ctl-x-5-map "o" 'other-frame)
760
761 (provide 'frame)
762
763 ;;; frame.el ends here