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