(defcustom): Get rid of eval-and-compile.
[emacs.git] / lisp / frame.el
blobabda506b8a2ef4d5501ff163f82dab40c6dbad11
1 ;;; frame.el --- multi-frame management independent of window systems.
3 ;; Copyright (C) 1993, 1994, 1996, 1997 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
6 ;; Keywords: internal
8 ;; This file is part of GNU Emacs.
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.
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.
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.
25 ;;; Code:
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.")
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'.
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'.
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'.")
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'.")
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'.")
71 (setq pop-up-frame-function
72 (function (lambda ()
73 (make-frame pop-up-frame-alist))))
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)
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))))))
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))))
128 ;;;; Arrangement of frames at startup
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.
134 ;;; 2) If no frames have been opened, we open an initial text frame.
136 ;;; 3) Once the init file is done, we apply any newly set parameters
137 ;;; in initial-frame-alist to the frame.
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)
145 ;;; If we create the initial frame, this is it.
146 (defvar frame-initial-frame nil)
148 ;; Record the parameters used in frame-initialize to make the initial frame.
149 (defvar frame-initial-frame-alist)
151 (defvar frame-initial-geometry-arguments nil)
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 ()
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)
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 ;; Record these with their default values
173 ;; if they don't have any values explicitly.
174 (or (assq 'vertical-scroll-bars frame-initial-frame-alist)
175 (setq frame-initial-frame-alist
176 (cons '(vertical-scroll-bars . t)
177 frame-initial-frame-alist)))
178 (or (assq 'horizontal-scroll-bars frame-initial-frame-alist)
179 (setq frame-initial-frame-alist
180 (cons '(horizontal-scroll-bars . t)
181 frame-initial-frame-alist)))
182 (setq default-minibuffer-frame
183 (setq frame-initial-frame
184 (make-frame initial-frame-alist)))
185 ;; Delete any specifications for window geometry parameters
186 ;; so that we won't reapply them in frame-notice-user-settings.
187 ;; It would be wrong to reapply them then,
188 ;; because that would override explicit user resizing.
189 (setq initial-frame-alist
190 (frame-remove-geometry-params initial-frame-alist))))
191 ;; At this point, we know that we have a frame open, so we
192 ;; can delete the terminal frame.
193 (delete-frame terminal-frame)
194 (setq terminal-frame nil))
196 ;; No, we're not running a window system. Use make-terminal-frame if
197 ;; we support that feature, otherwise arrange to cause errors.
198 (or (eq window-system 'pc)
199 (setq frame-creation-function
200 (if (fboundp 'make-terminal-frame)
201 'make-terminal-frame
202 (function
203 (lambda (parameters)
204 (error
205 "Can't create multiple frames without a window system"))))))))
207 ;;; startup.el calls this function after loading the user's init
208 ;;; file. Now default-frame-alist and initial-frame-alist contain
209 ;;; information to which we must react; do what needs to be done.
210 (defun frame-notice-user-settings ()
212 ;; Make menu-bar-mode and default-frame-alist consistent.
213 (if (boundp 'menu-bar-mode)
214 (let ((default (assq 'menu-bar-lines default-frame-alist)))
215 (if default
216 (setq menu-bar-mode (not (eq (cdr default) 0)))
217 (setq default-frame-alist
218 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
219 default-frame-alist)))))
221 ;; Creating and deleting frames may shift the selected frame around,
222 ;; and thus the current buffer. Protect against that. We don't
223 ;; want to use save-excursion here, because that may also try to set
224 ;; the buffer of the selected window, which fails when the selected
225 ;; window is the minibuffer.
226 (let ((old-buffer (current-buffer)))
228 ;; If the initial frame is still around, apply initial-frame-alist
229 ;; and default-frame-alist to it.
230 (if (frame-live-p frame-initial-frame)
232 ;; The initial frame we create above always has a minibuffer.
233 ;; If the user wants to remove it, or make it a minibuffer-only
234 ;; frame, then we'll have to delete the current frame and make a
235 ;; new one; you can't remove or add a root window to/from an
236 ;; existing frame.
238 ;; NOTE: default-frame-alist was nil when we created the
239 ;; existing frame. We need to explicitly include
240 ;; default-frame-alist in the parameters of the screen we
241 ;; create here, so that its new value, gleaned from the user's
242 ;; .emacs file, will be applied to the existing screen.
243 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
244 (assq 'minibuffer default-frame-alist)
245 '(minibuffer . t)))
247 ;; Create the new frame.
248 (let (parms new)
249 ;; If the frame isn't visible yet, wait till it is.
250 ;; If the user has to position the window,
251 ;; Emacs doesn't know its real position until
252 ;; the frame is seen to be visible.
253 (while (not (cdr (assq 'visibility
254 (frame-parameters frame-initial-frame))))
255 (sleep-for 1))
256 (setq parms (frame-parameters frame-initial-frame))
257 ;; Get rid of `name' unless it was specified explicitly before.
258 (or (assq 'name frame-initial-frame-alist)
259 (setq parms (delq (assq 'name parms) parms)))
260 (setq parms (append initial-frame-alist
261 default-frame-alist
262 parms
263 nil))
264 ;; Get rid of `reverse', because that was handled
265 ;; when we first made the frame.
266 (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
267 (if (assq 'height frame-initial-geometry-arguments)
268 (setq parms (frame-delete-all 'height parms)))
269 (if (assq 'width frame-initial-geometry-arguments)
270 (setq parms (frame-delete-all 'width parms)))
271 (if (assq 'left frame-initial-geometry-arguments)
272 (setq parms (frame-delete-all 'left parms)))
273 (if (assq 'top frame-initial-geometry-arguments)
274 (setq parms (frame-delete-all 'top parms)))
275 (setq new
276 (make-frame
277 ;; Use the geometry args that created the existing
278 ;; frame, rather than the parms we get for it.
279 (append frame-initial-geometry-arguments
280 '((user-size . t) (user-position . t))
281 parms)))
282 ;; The initial frame, which we are about to delete, may be
283 ;; the only frame with a minibuffer. If it is, create a
284 ;; new one.
285 (or (delq frame-initial-frame (minibuffer-frame-list))
286 (make-initial-minibuffer-frame nil))
288 ;; If the initial frame is serving as a surrogate
289 ;; minibuffer frame for any frames, we need to wean them
290 ;; onto a new frame. The default-minibuffer-frame
291 ;; variable must be handled similarly.
292 (let ((users-of-initial
293 (filtered-frame-list
294 (function (lambda (frame)
295 (and (not (eq frame frame-initial-frame))
296 (eq (window-frame
297 (minibuffer-window frame))
298 frame-initial-frame)))))))
299 (if (or users-of-initial
300 (eq default-minibuffer-frame frame-initial-frame))
302 ;; Choose an appropriate frame. Prefer frames which
303 ;; are only minibuffers.
304 (let* ((new-surrogate
305 (car
306 (or (filtered-frame-list
307 (function
308 (lambda (frame)
309 (eq (cdr (assq 'minibuffer
310 (frame-parameters frame)))
311 'only))))
312 (minibuffer-frame-list))))
313 (new-minibuffer (minibuffer-window new-surrogate)))
315 (if (eq default-minibuffer-frame frame-initial-frame)
316 (setq default-minibuffer-frame new-surrogate))
318 ;; Wean the frames using frame-initial-frame as
319 ;; their minibuffer frame.
320 (mapcar
321 (function
322 (lambda (frame)
323 (modify-frame-parameters
324 frame (list (cons 'minibuffer new-minibuffer)))))
325 users-of-initial))))
327 ;; Redirect events enqueued at this frame to the new frame.
328 ;; Is this a good idea?
329 (redirect-frame-focus frame-initial-frame new)
331 ;; Finally, get rid of the old frame.
332 (delete-frame frame-initial-frame t))
334 ;; Otherwise, we don't need all that rigamarole; just apply
335 ;; the new parameters.
336 (let (newparms allparms tail)
337 (setq allparms (append initial-frame-alist
338 default-frame-alist))
339 (if (assq 'height frame-initial-geometry-arguments)
340 (setq allparms (frame-delete-all 'height allparms)))
341 (if (assq 'width frame-initial-geometry-arguments)
342 (setq allparms (frame-delete-all 'width allparms)))
343 (if (assq 'left frame-initial-geometry-arguments)
344 (setq allparms (frame-delete-all 'left allparms)))
345 (if (assq 'top frame-initial-geometry-arguments)
346 (setq allparms (frame-delete-all 'top allparms)))
347 (setq tail allparms)
348 ;; Find just the parms that have changed since we first
349 ;; made this frame. Those are the ones actually set by
350 ;; the init file. For those parms whose values we already knew
351 ;; (such as those spec'd by command line options)
352 ;; it is undesirable to specify the parm again
353 ;; once the user has seen the frame and been able to alter it
354 ;; manually.
355 (while tail
356 (let (newval oldval)
357 (setq oldval (assq (car (car tail))
358 frame-initial-frame-alist))
359 (setq newval (cdr (assq (car (car tail)) allparms)))
360 (or (and oldval (eq (cdr oldval) newval))
361 (setq newparms
362 (cons (cons (car (car tail)) newval) newparms))))
363 (setq tail (cdr tail)))
364 (setq newparms (nreverse newparms))
365 (modify-frame-parameters frame-initial-frame
366 newparms)
367 (if (assq 'font newparms)
368 (frame-update-faces frame-initial-frame)))))
370 ;; Restore the original buffer.
371 (set-buffer old-buffer)
373 ;; Make sure the initial frame can be GC'd if it is ever deleted.
374 ;; Make sure frame-notice-user-settings does nothing if called twice.
375 (setq frame-initial-frame nil)))
377 (defun make-initial-minibuffer-frame (display)
378 (let ((parms (append minibuffer-frame-alist '((minibuffer . only)))))
379 (if display
380 (make-frame-on-display display parms)
381 (make-frame parms))))
383 ;; Delete from ALIST all elements whose car is KEY.
384 ;; Return the modified alist.
385 (defun frame-delete-all (key alist)
386 (setq alist (copy-sequence alist))
387 (let ((tail alist))
388 (while tail
389 (if (eq (car (car tail)) key)
390 (setq alist (delq (car tail) alist)))
391 (setq tail (cdr tail)))
392 alist))
394 ;;;; Creation of additional frames, and other frame miscellanea
396 ;;; Return some frame other than the current frame, creating one if
397 ;;; necessary. Note that the minibuffer frame, if separate, is not
398 ;;; considered (see next-frame).
399 (defun get-other-frame ()
400 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
401 (make-frame)
402 (next-frame (selected-frame)))))
405 (defun next-multiframe-window ()
406 "Select the next window, regardless of which frame it is on."
407 (interactive)
408 (select-window (next-window (selected-window)
409 (> (minibuffer-depth) 0)
410 t)))
412 (defun previous-multiframe-window ()
413 "Select the previous window, regardless of which frame it is on."
414 (interactive)
415 (select-window (previous-window (selected-window)
416 (> (minibuffer-depth) 0)
417 t)))
419 (defun make-frame-on-display (display &optional parameters)
420 "Make a frame on display DISPLAY.
421 The optional second argument PARAMETERS specifies additional frame parameters."
422 (interactive "sMake frame on display: ")
423 (make-frame (cons (cons 'display display) parameters)))
425 (defun make-frame-command ()
426 "Make a new frame, and select it if the terminal displays only one frame."
427 (interactive)
428 (if (and window-system (not (eq window-system 'pc)))
429 (make-frame)
430 (select-frame (make-frame))))
432 (defvar before-make-frame-hook nil
433 "Functions to run before a frame is created.")
435 (defvar after-make-frame-functions nil
436 "Functions to run after a frame is created.
437 The functions are run with one arg, the newly created frame.")
439 ;; Alias, kept temporarily.
440 (defalias 'new-frame 'make-frame)
442 (defun make-frame (&optional parameters)
443 "Return a newly created frame displaying the current buffer.
444 Optional argument PARAMETERS is an alist of parameters for the new frame.
445 Each element of PARAMETERS should have the form (NAME . VALUE), for example:
447 (name . STRING) The frame should be named STRING.
449 (width . NUMBER) The frame should be NUMBER characters in width.
450 (height . NUMBER) The frame should be NUMBER text lines high.
452 You cannot specify either `width' or `height', you must use neither or both.
454 (minibuffer . t) The frame should have a minibuffer.
455 (minibuffer . nil) The frame should have no minibuffer.
456 (minibuffer . only) The frame should contain only a minibuffer.
457 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
459 Before the frame is created (via `frame-creation-function'), functions on the
460 hook `before-make-frame-hook' are run. After the frame is created, functions
461 on `after-make-frame-functions' are run with one arg, the newly created frame."
462 (interactive)
463 (run-hooks 'before-make-frame-hook)
464 (let ((frame (funcall frame-creation-function parameters)))
465 (run-hook-with-args 'after-make-frame-functions frame)
466 frame))
468 (defun filtered-frame-list (predicate)
469 "Return a list of all live frames which satisfy PREDICATE."
470 (let ((frames (frame-list))
471 good-frames)
472 (while (consp frames)
473 (if (funcall predicate (car frames))
474 (setq good-frames (cons (car frames) good-frames)))
475 (setq frames (cdr frames)))
476 good-frames))
478 (defun minibuffer-frame-list ()
479 "Return a list of all frames with their own minibuffers."
480 (filtered-frame-list
481 (function (lambda (frame)
482 (eq frame (window-frame (minibuffer-window frame)))))))
484 (defun frame-remove-geometry-params (param-list)
485 "Return the parameter list PARAM-LIST, but with geometry specs removed.
486 This deletes all bindings in PARAM-LIST for `top', `left', `width',
487 `height', `user-size' and `user-position' parameters.
488 Emacs uses this to avoid overriding explicit moves and resizings from
489 the user during startup."
490 (setq param-list (cons nil param-list))
491 (let ((tail param-list))
492 (while (consp (cdr tail))
493 (if (and (consp (car (cdr tail)))
494 (memq (car (car (cdr tail)))
495 '(height width top left user-position user-size)))
496 (progn
497 (setq frame-initial-geometry-arguments
498 (cons (car (cdr tail)) frame-initial-geometry-arguments))
499 (setcdr tail (cdr (cdr tail))))
500 (setq tail (cdr tail)))))
501 (setq frame-initial-geometry-arguments
502 (nreverse frame-initial-geometry-arguments))
503 (cdr param-list))
506 (defun other-frame (arg)
507 "Select the ARG'th different visible frame, and raise it.
508 All frames are arranged in a cyclic order.
509 This command selects the frame ARG steps away in that order.
510 A negative ARG moves in the opposite order."
511 (interactive "p")
512 (let ((frame (selected-frame)))
513 (while (> arg 0)
514 (setq frame (next-frame frame))
515 (while (not (eq (frame-visible-p frame) t))
516 (setq frame (next-frame frame)))
517 (setq arg (1- arg)))
518 (while (< arg 0)
519 (setq frame (previous-frame frame))
520 (while (not (eq (frame-visible-p frame) t))
521 (setq frame (previous-frame frame)))
522 (setq arg (1+ arg)))
523 (raise-frame frame)
524 (select-frame frame)
525 (set-mouse-position (selected-frame) (1- (frame-width)) 0)))
527 ;;;; Frame configurations
529 (defun current-frame-configuration ()
530 "Return a list describing the positions and states of all frames.
531 Its car is `frame-configuration'.
532 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
533 where
534 FRAME is a frame object,
535 ALIST is an association list specifying some of FRAME's parameters, and
536 WINDOW-CONFIG is a window configuration object for FRAME."
537 (cons 'frame-configuration
538 (mapcar (function
539 (lambda (frame)
540 (list frame
541 (frame-parameters frame)
542 (current-window-configuration frame))))
543 (frame-list))))
545 (defun set-frame-configuration (configuration &optional nodelete)
546 "Restore the frames to the state described by CONFIGURATION.
547 Each frame listed in CONFIGURATION has its position, size, window
548 configuration, and other parameters set as specified in CONFIGURATION.
549 Ordinarily, this function deletes all existing frames not
550 listed in CONFIGURATION. But if optional second argument NODELETE
551 is given and non-nil, the unwanted frames are iconified instead."
552 (or (frame-configuration-p configuration)
553 (signal 'wrong-type-argument
554 (list 'frame-configuration-p configuration)))
555 (let ((config-alist (cdr configuration))
556 frames-to-delete)
557 (mapcar (function
558 (lambda (frame)
559 (let ((parameters (assq frame config-alist)))
560 (if parameters
561 (progn
562 (modify-frame-parameters
563 frame
564 ;; Since we can't set a frame's minibuffer status,
565 ;; we might as well omit the parameter altogether.
566 (let* ((parms (nth 1 parameters))
567 (mini (assq 'minibuffer parms)))
568 (if mini (setq parms (delq mini parms)))
569 parms))
570 (set-window-configuration (nth 2 parameters)))
571 (setq frames-to-delete (cons frame frames-to-delete))))))
572 (frame-list))
573 (if nodelete
574 ;; Note: making frames invisible here was tried
575 ;; but led to some strange behavior--each time the frame
576 ;; was made visible again, the window manager asked afresh
577 ;; for where to put it.
578 (mapcar 'iconify-frame frames-to-delete)
579 (mapcar 'delete-frame frames-to-delete))))
581 ;;;; Convenience functions for accessing and interactively changing
582 ;;;; frame parameters.
584 (defun frame-parameter (frame parameter)
585 "Return FRAME's value for parameter PARAMETER.
586 If FRAME is omitted, describe the currently selected frame."
587 (cdr (assq parameter (frame-parameters frame))))
589 (defun frame-height (&optional frame)
590 "Return number of lines available for display on FRAME.
591 If FRAME is omitted, describe the currently selected frame."
592 (cdr (assq 'height (frame-parameters frame))))
594 (defun frame-width (&optional frame)
595 "Return number of columns available for display on FRAME.
596 If FRAME is omitted, describe the currently selected frame."
597 (cdr (assq 'width (frame-parameters frame))))
599 (defalias 'set-default-font 'set-frame-font)
600 (defun set-frame-font (font-name)
601 "Set the font of the selected frame to FONT.
602 When called interactively, prompt for the name of the font to use.
603 To get the frame's current default font, use `frame-parameters'."
604 (interactive "sFont name: ")
605 (modify-frame-parameters (selected-frame)
606 (list (cons 'font font-name)))
607 ;; Update faces that want a bold or italic version of the default font.
608 (frame-update-faces (selected-frame)))
610 (defun set-background-color (color-name)
611 "Set the background color of the selected frame to COLOR.
612 When called interactively, prompt for the name of the color to use.
613 To get the frame's current background color, use `frame-parameters'."
614 (interactive "sColor: ")
615 (modify-frame-parameters (selected-frame)
616 (list (cons 'background-color color-name)))
617 (frame-update-face-colors (selected-frame)))
619 (defun set-foreground-color (color-name)
620 "Set the foreground color of the selected frame to COLOR.
621 When called interactively, prompt for the name of the color to use.
622 To get the frame's current foreground color, use `frame-parameters'."
623 (interactive "sColor: ")
624 (modify-frame-parameters (selected-frame)
625 (list (cons 'foreground-color color-name)))
626 (frame-update-face-colors (selected-frame)))
628 (defun set-cursor-color (color-name)
629 "Set the text cursor color of the selected frame to COLOR.
630 When called interactively, prompt for the name of the color to use.
631 To get the frame's current cursor color, use `frame-parameters'."
632 (interactive "sColor: ")
633 (modify-frame-parameters (selected-frame)
634 (list (cons 'cursor-color color-name))))
636 (defun set-mouse-color (color-name)
637 "Set the color of the mouse pointer of the selected frame to COLOR.
638 When called interactively, prompt for the name of the color to use.
639 To get the frame's current mouse color, use `frame-parameters'."
640 (interactive "sColor: ")
641 (modify-frame-parameters (selected-frame)
642 (list (cons 'mouse-color color-name))))
644 (defun set-border-color (color-name)
645 "Set the color of the border of the selected frame to COLOR.
646 When called interactively, prompt for the name of the color to use.
647 To get the frame's current border color, use `frame-parameters'."
648 (interactive "sColor: ")
649 (modify-frame-parameters (selected-frame)
650 (list (cons 'border-color color-name))))
652 (defun auto-raise-mode (arg)
653 "Toggle whether or not the selected frame should auto-raise.
654 With arg, turn auto-raise mode on if and only if arg is positive.
655 Note that this controls Emacs's own auto-raise feature.
656 Some window managers allow you to enable auto-raise for certain windows.
657 You can use that for Emacs windows if you wish, but if you do,
658 that is beyond the control of Emacs and this command has no effect on it."
659 (interactive "P")
660 (if (null arg)
661 (setq arg
662 (if (cdr (assq 'auto-raise (frame-parameters (selected-frame))))
663 -1 1)))
664 (modify-frame-parameters (selected-frame)
665 (list (cons 'auto-raise (> arg 0)))))
667 (defun auto-lower-mode (arg)
668 "Toggle whether or not the selected frame should auto-lower.
669 With arg, turn auto-lower mode on if and only if arg is positive.
670 Note that this controls Emacs's own auto-lower feature.
671 Some window managers allow you to enable auto-lower for certain windows.
672 You can use that for Emacs windows if you wish, but if you do,
673 that is beyond the control of Emacs and this command has no effect on it."
674 (interactive "P")
675 (if (null arg)
676 (setq arg
677 (if (cdr (assq 'auto-lower (frame-parameters (selected-frame))))
678 -1 1)))
679 (modify-frame-parameters (selected-frame)
680 (list (cons 'auto-lower (> arg 0)))))
682 (defcustom scroll-bar-side 'left
683 "*Specify which side scroll bars should be on. Value is `left' or `right'."
684 :type '(choice (const left)
685 (const right))
686 :group 'frames)
688 (defun toggle-scroll-bar (arg)
689 "Toggle whether or not the selected frame has vertical scroll bars.
690 With arg, turn vertical scroll bars on if and only if arg is positive."
691 (interactive "P")
692 (if (null arg)
693 (setq arg
694 (if (cdr (assq 'vertical-scroll-bars
695 (frame-parameters (selected-frame))))
696 -1 1)))
697 (modify-frame-parameters (selected-frame)
698 (list (cons 'vertical-scroll-bars
699 (if (> arg 0)
700 scroll-bar-side)))))
702 (defun toggle-horizontal-scroll-bar (arg)
703 "Toggle whether or not the selected frame has horizontal scroll bars.
704 With arg, turn horizontal scroll bars on if and only if arg is positive.
705 Horizontal scroll bars aren't implemented yet."
706 (interactive "P")
707 (error "Horizontal scroll bars aren't implemented yet"))
710 ;;;; Aliases for backward compatibility with Emacs 18.
711 (defalias 'screen-height 'frame-height)
712 (defalias 'screen-width 'frame-width)
714 (defun set-screen-width (cols &optional pretend)
715 "Obsolete function to change the size of the screen to COLS columns.\n\
716 Optional second arg non-nil means that redisplay should use COLS columns\n\
717 but that the idea of the actual width of the frame should not be changed.\n\
718 This function is provided only for compatibility with Emacs 18; new code\n\
719 should use `set-frame-width instead'."
720 (set-frame-width (selected-frame) cols pretend))
722 (defun set-screen-height (lines &optional pretend)
723 "Obsolete function to change the height of the screen to LINES lines.\n\
724 Optional second arg non-nil means that redisplay should use LINES lines\n\
725 but that the idea of the actual height of the screen should not be changed.\n\
726 This function is provided only for compatibility with Emacs 18; new code\n\
727 should use `set-frame-height' instead."
728 (set-frame-height (selected-frame) lines pretend))
730 (make-obsolete 'screen-height 'frame-height)
731 (make-obsolete 'screen-width 'frame-width)
732 (make-obsolete 'set-screen-width 'set-frame-width)
733 (make-obsolete 'set-screen-height 'set-frame-height)
736 ;;;; Key bindings
738 (define-key ctl-x-5-map "2" 'make-frame-command)
739 (define-key ctl-x-5-map "0" 'delete-frame)
740 (define-key ctl-x-5-map "o" 'other-frame)
742 (provide 'frame)
744 ;;; frame.el ends here