(Other GDB-UI Buffers): Describe how to edit
[bpt/emacs.git] / lisp / frame.el
CommitLineData
55535639 1;;; frame.el --- multi-frame management independent of window systems
c88ab9ce 2
0d30b337 3;; Copyright (C) 1993, 1994, 1996, 1997, 2000, 2001, 2002, 2003,
aaef169d 4;; 2004, 2005, 2006 Free Software Foundation, Inc.
3a801d0c 5
fc68affa 6;; Maintainer: FSF
fd7fa35a 7;; Keywords: internal
fc68affa 8
b578f267
EN
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation; either version 2, or (at your option)
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to the
086add15
LK
23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
64c669bc 25
55535639
PJ
26;;; Commentary:
27
fc68affa
ER
28;;; Code:
29
dc6d9681
JB
30(defvar frame-creation-function nil
31 "Window-system dependent function to call to create a new frame.
32The window system startup file should set this to its frame creation
64c669bc
JB
33function, which should take an alist of parameters as its argument.")
34
7e573c4a
SM
35;; The initial value given here used to ask for a minibuffer.
36;; But that's not necessary, because the default is to have one.
37;; By not specifying it here, we let an X resource specify it.
0c966f88 38(defcustom initial-frame-alist nil
0b9d32af 39 "*Alist of frame parameters for creating the initial X window frame.
eaa974e1 40You can set this in your `.emacs' file; for example,
dc6d9681 41 (setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55)))
de17da15
RS
42Parameters specified here supersede the values given in `default-frame-alist'.
43
44If the value calls for a frame without a minibuffer, and you have not created
45a minibuffer frame on your own, one is created according to
7eadab74 46`minibuffer-frame-alist'.
de17da15
RS
47
48You can specify geometry-related options for just the initial frame
49by setting this variable in your `.emacs' file; however, they won't
85557d7e 50take effect until Emacs reads `.emacs', which happens after first creating
de17da15
RS
51the frame. If you want the frame to have the proper geometry as soon
52as it appears, you need to use this three-step process:
53* Specify X resources to give the geometry you want.
54* Set `default-frame-alist' to override these options so that they
55 don't affect subsequent frames.
56* Set `initial-frame-alist' in a way that matches the X resources,
0c966f88
RS
57 to override what you put in `default-frame-alist'."
58 :type '(repeat (cons :format "%v"
59 (symbol :tag "Parameter")
60 (sexp :tag "Value")))
61 :group 'frames)
64c669bc 62
0b9d32af
RS
63(defcustom minibuffer-frame-alist '((width . 80) (height . 2))
64 "*Alist of frame parameters for initially creating a minibuffer frame.
eaa974e1 65You can set this in your `.emacs' file; for example,
dc6d9681 66 (setq minibuffer-frame-alist
7eadab74 67 '((top . 1) (left . 1) (width . 80) (height . 2)))
eaa974e1 68Parameters specified here supersede the values given in
0b9d32af
RS
69`default-frame-alist', for a minibuffer frame."
70 :type '(repeat (cons :format "%v"
71 (symbol :tag "Parameter")
72 (sexp :tag "Value")))
73 :group 'frames)
64c669bc 74
0b9d32af
RS
75(defcustom pop-up-frame-alist nil
76 "*Alist of frame parameters used when creating pop-up frames.
dc6d9681 77Pop-up frames are used for completions, help, and the like.
64c669bc 78This variable can be set in your init file, like this:
dc6d9681 79 (setq pop-up-frame-alist '((width . 80) (height . 20)))
0b9d32af
RS
80These supersede the values given in `default-frame-alist',
81for pop-up frames."
82 :type '(repeat (cons :format "%v"
83 (symbol :tag "Parameter")
84 (sexp :tag "Value")))
85 :group 'frames)
64c669bc 86
dc6d9681 87(setq pop-up-frame-function
7f18ce22
RS
88 ;; Using `function' here caused some sort of problem.
89 '(lambda ()
90 (make-frame pop-up-frame-alist)))
64c669bc 91
30e19aee 92(defcustom special-display-frame-alist
8a9e86e6
RS
93 '((height . 14) (width . 80) (unsplittable . t))
94 "*Alist of frame parameters used when creating special frames.
95Special frames are used for buffers whose names are in
96`special-display-buffer-names' and for buffers whose names match
97one of the regular expressions in `special-display-regexps'.
98This variable can be set in your init file, like this:
99 (setq special-display-frame-alist '((width . 80) (height . 20)))
30e19aee
RS
100These supersede the values given in `default-frame-alist'."
101 :type '(repeat (cons :format "%v"
102 (symbol :tag "Parameter")
103 (sexp :tag "Value")))
104 :group 'frames)
8a9e86e6 105
95e6cf39 106(defun special-display-popup-frame (buffer &optional args)
40d34803
DL
107 "Display BUFFER in its own frame, reusing an existing window if any.
108Return the window chosen.
109Currently we do not insist on selecting the window within its frame.
110If ARGS is an alist, use it as a list of frame parameter specs.
111If ARGS is a list whose car is a symbol,
112use (car ARGS) as a function to do the work.
113Pass it BUFFER as first arg, and (cdr ARGS) gives the rest of the args."
95e6cf39
RS
114 (if (and args (symbolp (car args)))
115 (apply (car args) buffer (cdr args))
bb2c34b1 116 (let ((window (get-buffer-window buffer 0)))
7e573c4a
SM
117 (or
118 ;; If we have a window already, make it visible.
119 (when window
120 (let ((frame (window-frame window)))
121 (make-frame-visible frame)
122 (raise-frame frame)
123 window))
124 ;; Reuse the current window if the user requested it.
125 (when (cdr (assq 'same-window args))
126 (condition-case nil
127 (progn (switch-to-buffer buffer) (selected-window))
128 (error nil)))
129 ;; Stay on the same frame if requested.
130 (when (or (cdr (assq 'same-frame args)) (cdr (assq 'same-window args)))
131 (let* ((pop-up-frames nil) (pop-up-windows t)
132 special-display-regexps special-display-buffer-names
133 (window (display-buffer buffer)))
bb2c34b1 134 ;; Only do it if this is a new window:
7e573c4a
SM
135 ;; (set-window-dedicated-p window t)
136 window))
137 ;; If no window yet, make one in a new frame.
bf247b6e 138 (let ((frame
86bd482f
RS
139 (with-current-buffer buffer
140 (make-frame (append args special-display-frame-alist)))))
7e573c4a
SM
141 (set-window-buffer (frame-selected-window frame) buffer)
142 (set-window-dedicated-p (frame-selected-window frame) t)
143 (frame-selected-window frame))))))
8a9e86e6 144
924be53a 145(defun handle-delete-frame (event)
40d34803 146 "Handle delete-frame events from the X server."
924be53a
RS
147 (interactive "e")
148 (let ((frame (posn-window (event-start event)))
149 (i 0)
150 (tail (frame-list)))
151 (while tail
152 (and (frame-visible-p (car tail))
153 (not (eq (car tail) frame))
154 (setq i (1+ i)))
155 (setq tail (cdr tail)))
156 (if (> i 0)
157 (delete-frame frame t)
a9562d19
RS
158 ;; Gildea@x.org says it is ok to ask questions before terminating.
159 (save-buffers-kill-emacs))))
64c669bc 160\f
dc6d9681 161;;;; Arrangement of frames at startup
64c669bc 162
7e573c4a
SM
163;; 1) Load the window system startup file from the lisp library and read the
164;; high-priority arguments (-q and the like). The window system startup
165;; file should create any frames specified in the window system defaults.
166;;
167;; 2) If no frames have been opened, we open an initial text frame.
168;;
169;; 3) Once the init file is done, we apply any newly set parameters
170;; in initial-frame-alist to the frame.
64c669bc 171
85557d7e 172;; These are now called explicitly at the proper times,
fc4d4afb
RS
173;; since that is easier to understand.
174;; Actually using hooks within Emacs is bad for future maintenance. --rms.
175;; (add-hook 'before-init-hook 'frame-initialize)
176;; (add-hook 'window-setup-hook 'frame-notice-user-settings)
64c669bc 177
7e573c4a 178;; If we create the initial frame, this is it.
dc6d9681 179(defvar frame-initial-frame nil)
64c669bc 180
3f2f8c83
RS
181;; Record the parameters used in frame-initialize to make the initial frame.
182(defvar frame-initial-frame-alist)
183
791e09d8
RS
184(defvar frame-initial-geometry-arguments nil)
185
7e573c4a
SM
186;; startup.el calls this function before loading the user's init
187;; file - if there is no frame with a minibuffer open now, create
188;; one to display messages while loading the init file.
dc6d9681 189(defun frame-initialize ()
ff2a1c79 190 "Create an initial frame if necessary."
64c669bc 191 ;; Are we actually running under a window system at all?
004f057a 192 (if (and window-system (not noninteractive) (not (eq window-system 'pc)))
7eadab74 193 (progn
62642af9
RS
194 ;; Turn on special-display processing only if there's a window system.
195 (setq special-display-function 'special-display-popup-frame)
196
7eadab74
JB
197 ;; If there is no frame with a minibuffer besides the terminal
198 ;; frame, then we need to create the opening frame. Make sure
199 ;; it has a minibuffer, but let initial-frame-alist omit the
200 ;; minibuffer spec.
201 (or (delq terminal-frame (minibuffer-frame-list))
36fc9c9f 202 (progn
3f2f8c83 203 (setq frame-initial-frame-alist
9688894d 204 (append initial-frame-alist default-frame-alist nil))
a8bb5882
RS
205 (or (assq 'horizontal-scroll-bars frame-initial-frame-alist)
206 (setq frame-initial-frame-alist
207 (cons '(horizontal-scroll-bars . t)
208 frame-initial-frame-alist)))
36fc9c9f
RS
209 (setq default-minibuffer-frame
210 (setq frame-initial-frame
96a84970 211 (make-frame frame-initial-frame-alist)))
11281034
RS
212 ;; Delete any specifications for window geometry parameters
213 ;; so that we won't reapply them in frame-notice-user-settings.
214 ;; It would be wrong to reapply them then,
215 ;; because that would override explicit user resizing.
58bf6042 216 (setq initial-frame-alist
c2079f0a 217 (frame-remove-geometry-params initial-frame-alist))))
85557d7e 218 ;; At this point, we know that we have a frame open, so we
dc6d9681
JB
219 ;; can delete the terminal frame.
220 (delete-frame terminal-frame)
221 (setq terminal-frame nil))
85557d7e 222
0759c4d0
KH
223 ;; No, we're not running a window system. Use make-terminal-frame if
224 ;; we support that feature, otherwise arrange to cause errors.
004f057a
RS
225 (or (eq window-system 'pc)
226 (setq frame-creation-function
81b99826
GM
227 (if (fboundp 'tty-create-frame-with-faces)
228 'tty-create-frame-with-faces
004f057a
RS
229 (function
230 (lambda (parameters)
231 (error
232 "Can't create multiple frames without a window system"))))))))
85557d7e 233
8f2a992b
GM
234(defvar frame-notice-user-settings t
235 "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
236
7e573c4a
SM
237;; startup.el calls this function after loading the user's init
238;; file. Now default-frame-alist and initial-frame-alist contain
239;; information to which we must react; do what needs to be done.
dc6d9681 240(defun frame-notice-user-settings ()
40d34803
DL
241 "Act on user's init file settings of frame parameters.
242React to settings of `default-frame-alist', `initial-frame-alist' there."
2ffa6186 243 ;; Make menu-bar-mode and default-frame-alist consistent.
61f2bcd7
GM
244 (when (boundp 'menu-bar-mode)
245 (let ((default (assq 'menu-bar-lines default-frame-alist)))
246 (if default
247 (setq menu-bar-mode (not (eq (cdr default) 0)))
248 (setq default-frame-alist
249 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
250 default-frame-alist)))))
f39784dd 251
33a33c06
GM
252 ;; Make tool-bar-mode and default-frame-alist consistent. Don't do
253 ;; it in batch mode since that would leave a tool-bar-lines
254 ;; parameter in default-frame-alist in a dumped Emacs, which is not
9688894d 255 ;; what we want.
33a33c06
GM
256 (when (and (boundp 'tool-bar-mode)
257 (not noninteractive))
61f2bcd7
GM
258 (let ((default (assq 'tool-bar-lines default-frame-alist)))
259 (if default
260 (setq tool-bar-mode (not (eq (cdr default) 0)))
261 (setq default-frame-alist
262 (cons (cons 'tool-bar-lines (if tool-bar-mode 1 0))
263 default-frame-alist)))))
2ffa6186 264
7eadab74
JB
265 ;; Creating and deleting frames may shift the selected frame around,
266 ;; and thus the current buffer. Protect against that. We don't
267 ;; want to use save-excursion here, because that may also try to set
268 ;; the buffer of the selected window, which fails when the selected
269 ;; window is the minibuffer.
270 (let ((old-buffer (current-buffer)))
271
8f2a992b
GM
272 (when (and frame-notice-user-settings
273 (null frame-initial-frame))
42002db5
EZ
274 ;; This case happens when we don't have a window system, and
275 ;; also for MS-DOS frames.
8f2a992b
GM
276 (let ((parms (frame-parameters frame-initial-frame)))
277 ;; Don't change the frame names.
278 (setq parms (delq (assq 'name parms) parms))
279 ;; Can't modify the minibuffer parameter, so don't try.
280 (setq parms (delq (assq 'minibuffer parms) parms))
281 (modify-frame-parameters nil
42002db5
EZ
282 (if (null window-system)
283 (append initial-frame-alist
284 default-frame-alist
285 parms
286 nil)
287 ;; initial-frame-alist and
288 ;; default-frame-alist were already
289 ;; applied in pc-win.el.
290 parms))
291 (if (null window-system) ;; MS-DOS does this differently in pc-win.el
292 (let ((newparms (frame-parameters))
293 (frame (selected-frame)))
294 (tty-handle-reverse-video frame newparms)
295 ;; If we changed the background color, we need to update
296 ;; the background-mode parameter, and maybe some faces,
297 ;; too.
298 (when (assq 'background-color newparms)
299 (unless (or (assq 'background-mode initial-frame-alist)
300 (assq 'background-mode default-frame-alist))
301 (frame-set-background-mode frame))
302 (face-set-after-frame-default frame))))))
8f2a992b 303
7eadab74
JB
304 ;; If the initial frame is still around, apply initial-frame-alist
305 ;; and default-frame-alist to it.
9688894d
GM
306 (when (frame-live-p frame-initial-frame)
307
308 ;; When tool-bar has been switched off, correct the frame size
309 ;; by the lines added in x-create-frame for the tool-bar and
310 ;; switch `tool-bar-mode' off.
085ef9b3
GM
311 (when (display-graphic-p)
312 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
313 (assq 'tool-bar-lines default-frame-alist))))
5c39a60f
JR
314 (when (and tool-bar-originally-present
315 (or (null tool-bar-lines)
316 (null (cdr tool-bar-lines))
317 (eq 0 (cdr tool-bar-lines))))
085ef9b3 318 (let* ((char-height (frame-char-height frame-initial-frame))
5c39a60f 319 (image-height tool-bar-images-pixel-height)
085ef9b3
GM
320 (margin (cond ((and (consp tool-bar-button-margin)
321 (integerp (cdr tool-bar-button-margin))
322 (> tool-bar-button-margin 0))
323 (cdr tool-bar-button-margin))
324 ((and (integerp tool-bar-button-margin)
325 (> tool-bar-button-margin 0))
326 tool-bar-button-margin)
327 (t 0)))
328 (relief (if (and (integerp tool-bar-button-relief)
329 (> tool-bar-button-relief 0))
330 tool-bar-button-relief 3))
f39784dd 331 (lines (/ (+ image-height
085ef9b3
GM
332 (* 2 margin)
333 (* 2 relief)
334 (1- char-height))
335 char-height))
336 (height (frame-parameter frame-initial-frame 'height))
337 (newparms (list (cons 'height (- height lines))))
f39784dd 338 (initial-top (cdr (assq 'top
085ef9b3
GM
339 frame-initial-geometry-arguments)))
340 (top (frame-parameter frame-initial-frame 'top)))
341 (when (and (consp initial-top) (eq '- (car initial-top)))
7f18ce22
RS
342 (let ((adjusted-top
343 (cond ((and (consp top)
344 (eq '+ (car top)))
345 (list '+
346 (+ (cadr top)
347 (* lines char-height))))
348 ((and (consp top)
349 (eq '- (car top)))
350 (list '-
351 (- (cadr top)
352 (* lines char-height))))
353 (t (+ top (* lines char-height))))))
354 (setq newparms
355 (append newparms
356 `((top . ,adjusted-top))
357 nil))))
085ef9b3
GM
358 (modify-frame-parameters frame-initial-frame newparms)
359 (tool-bar-mode -1)))))
9688894d
GM
360
361 ;; The initial frame we create above always has a minibuffer.
362 ;; If the user wants to remove it, or make it a minibuffer-only
363 ;; frame, then we'll have to delete the current frame and make a
364 ;; new one; you can't remove or add a root window to/from an
365 ;; existing frame.
366 ;;
367 ;; NOTE: default-frame-alist was nil when we created the
368 ;; existing frame. We need to explicitly include
369 ;; default-frame-alist in the parameters of the screen we
370 ;; create here, so that its new value, gleaned from the user's
371 ;; .emacs file, will be applied to the existing screen.
de2f5dbe
GM
372 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
373 (assq 'minibuffer default-frame-alist)
374 '(minibuffer . t)))
375 t))
376 ;; Create the new frame.
377 (let (parms new)
378 ;; If the frame isn't visible yet, wait till it is.
379 ;; If the user has to position the window,
380 ;; Emacs doesn't know its real position until
381 ;; the frame is seen to be visible.
382 (while (not (cdr (assq 'visibility
383 (frame-parameters frame-initial-frame))))
384 (sleep-for 1))
385 (setq parms (frame-parameters frame-initial-frame))
9688894d 386
f39784dd 387 ;; Get rid of `name' unless it was specified explicitly before.
de2f5dbe
GM
388 (or (assq 'name frame-initial-frame-alist)
389 (setq parms (delq (assq 'name parms) parms)))
390
391 (setq parms (append initial-frame-alist
392 default-frame-alist
393 parms
394 nil))
395
396 ;; Get rid of `reverse', because that was handled
397 ;; when we first made the frame.
398 (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
399
400 (if (assq 'height frame-initial-geometry-arguments)
401 (setq parms (assq-delete-all 'height parms)))
402 (if (assq 'width frame-initial-geometry-arguments)
403 (setq parms (assq-delete-all 'width parms)))
404 (if (assq 'left frame-initial-geometry-arguments)
405 (setq parms (assq-delete-all 'left parms)))
406 (if (assq 'top frame-initial-geometry-arguments)
407 (setq parms (assq-delete-all 'top parms)))
408 (setq new
409 (make-frame
410 ;; Use the geometry args that created the existing
411 ;; frame, rather than the parms we get for it.
412 (append frame-initial-geometry-arguments
413 '((user-size . t) (user-position . t))
414 parms)))
415 ;; The initial frame, which we are about to delete, may be
416 ;; the only frame with a minibuffer. If it is, create a
417 ;; new one.
418 (or (delq frame-initial-frame (minibuffer-frame-list))
419 (make-initial-minibuffer-frame nil))
420
421 ;; If the initial frame is serving as a surrogate
422 ;; minibuffer frame for any frames, we need to wean them
423 ;; onto a new frame. The default-minibuffer-frame
424 ;; variable must be handled similarly.
425 (let ((users-of-initial
426 (filtered-frame-list
427 (function (lambda (frame)
428 (and (not (eq frame frame-initial-frame))
429 (eq (window-frame
430 (minibuffer-window frame))
431 frame-initial-frame)))))))
432 (if (or users-of-initial
433 (eq default-minibuffer-frame frame-initial-frame))
434
435 ;; Choose an appropriate frame. Prefer frames which
436 ;; are only minibuffers.
437 (let* ((new-surrogate
438 (car
439 (or (filtered-frame-list
440 (function
441 (lambda (frame)
442 (eq (cdr (assq 'minibuffer
443 (frame-parameters frame)))
444 'only))))
445 (minibuffer-frame-list))))
446 (new-minibuffer (minibuffer-window new-surrogate)))
447
448 (if (eq default-minibuffer-frame frame-initial-frame)
449 (setq default-minibuffer-frame new-surrogate))
450
451 ;; Wean the frames using frame-initial-frame as
452 ;; their minibuffer frame.
453 (mapcar
454 (function
455 (lambda (frame)
456 (modify-frame-parameters
457 frame (list (cons 'minibuffer new-minibuffer)))))
458 users-of-initial))))
459
460 ;; Redirect events enqueued at this frame to the new frame.
461 ;; Is this a good idea?
462 (redirect-frame-focus frame-initial-frame new)
463
464 ;; Finally, get rid of the old frame.
465 (delete-frame frame-initial-frame t))
9688894d
GM
466
467 ;; Otherwise, we don't need all that rigamarole; just apply
468 ;; the new parameters.
469 (let (newparms allparms tail)
470 (setq allparms (append initial-frame-alist
471 default-frame-alist nil))
472 (if (assq 'height frame-initial-geometry-arguments)
473 (setq allparms (assq-delete-all 'height allparms)))
474 (if (assq 'width frame-initial-geometry-arguments)
475 (setq allparms (assq-delete-all 'width allparms)))
476 (if (assq 'left frame-initial-geometry-arguments)
477 (setq allparms (assq-delete-all 'left allparms)))
478 (if (assq 'top frame-initial-geometry-arguments)
479 (setq allparms (assq-delete-all 'top allparms)))
480 (setq tail allparms)
481 ;; Find just the parms that have changed since we first
482 ;; made this frame. Those are the ones actually set by
f39784dd 483 ;; the init file. For those parms whose values we already knew
9688894d
GM
484 ;; (such as those spec'd by command line options)
485 ;; it is undesirable to specify the parm again
f39784dd 486 ;; once the user has seen the frame and been able to alter it
9688894d
GM
487 ;; manually.
488 (while tail
489 (let (newval oldval)
490 (setq oldval (assq (car (car tail))
491 frame-initial-frame-alist))
492 (setq newval (cdr (assq (car (car tail)) allparms)))
493 (or (and oldval (eq (cdr oldval) newval))
494 (setq newparms
495 (cons (cons (car (car tail)) newval) newparms))))
496 (setq tail (cdr tail)))
497 (setq newparms (nreverse newparms))
498 (modify-frame-parameters frame-initial-frame
499 newparms)
500 ;; If we changed the background color,
501 ;; we need to update the background-mode parameter
502 ;; and maybe some faces too.
503 (when (assq 'background-color newparms)
504 (unless (assq 'background-mode newparms)
505 (frame-set-background-mode frame-initial-frame))
506 (face-set-after-frame-default frame-initial-frame)))))
64c669bc 507
7eadab74
JB
508 ;; Restore the original buffer.
509 (set-buffer old-buffer)
510
511 ;; Make sure the initial frame can be GC'd if it is ever deleted.
d202f1f2 512 ;; Make sure frame-notice-user-settings does nothing if called twice.
8f2a992b 513 (setq frame-notice-user-settings nil)
d202f1f2 514 (setq frame-initial-frame nil)))
64c669bc 515
746bd265
KH
516(defun make-initial-minibuffer-frame (display)
517 (let ((parms (append minibuffer-frame-alist '((minibuffer . only)))))
518 (if display
519 (make-frame-on-display display parms)
520 (make-frame parms))))
521
7eadab74 522;;;; Creation of additional frames, and other frame miscellanea
dc6d9681 523
63019bad 524(defun modify-all-frames-parameters (alist)
d398de43 525 "Modify all current and future frames' parameters according to ALIST.
63019bad
JB
526This changes `default-frame-alist' and possibly `initial-frame-alist'.
527See help of `modify-frame-parameters' for more information."
528 (let (element) ;; temp
529 (dolist (frame (frame-list))
530 (modify-frame-parameters frame alist))
531
532 (dolist (pair alist) ;; conses to add/replace
533 ;; initial-frame-alist needs setting only when
534 ;; frame-notice-user-settings is true
535 (and frame-notice-user-settings
536 (setq element (assoc (car pair) initial-frame-alist))
537 (setq initial-frame-alist (delq element initial-frame-alist)))
538 (and (setq element (assoc (car pair) default-frame-alist))
539 (setq default-frame-alist (delq element default-frame-alist)))))
540 (and frame-notice-user-settings
541 (setq initial-frame-alist (append initial-frame-alist alist)))
542 (setq default-frame-alist (append default-frame-alist alist)))
543
7253d8e0 544(defun get-other-frame ()
40d34803
DL
545 "Return some frame other than the current frame.
546Create one if necessary. Note that the minibuffer frame, if separate,
547is not considered (see `next-frame')."
dc6d9681 548 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
6eb018ba 549 (make-frame)
dc6d9681 550 (next-frame (selected-frame)))))
64c669bc
JB
551 s))
552
dc6d9681
JB
553(defun next-multiframe-window ()
554 "Select the next window, regardless of which frame it is on."
64c669bc
JB
555 (interactive)
556 (select-window (next-window (selected-window)
557 (> (minibuffer-depth) 0)
bb2c34b1 558 0))
030f4537 559 (select-frame-set-input-focus (selected-frame)))
64c669bc 560
dc6d9681
JB
561(defun previous-multiframe-window ()
562 "Select the previous window, regardless of which frame it is on."
64c669bc
JB
563 (interactive)
564 (select-window (previous-window (selected-window)
565 (> (minibuffer-depth) 0)
bb2c34b1 566 0))
030f4537 567 (select-frame-set-input-focus (selected-frame)))
64c669bc 568
6d73e337
RS
569(defun make-frame-on-display (display &optional parameters)
570 "Make a frame on display DISPLAY.
571The optional second argument PARAMETERS specifies additional frame parameters."
572 (interactive "sMake frame on display: ")
a9ca74cd
RS
573 (or (string-match "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display)
574 (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
6d73e337
RS
575 (make-frame (cons (cons 'display display) parameters)))
576
6238bfaf
RS
577(defun make-frame-command ()
578 "Make a new frame, and select it if the terminal displays only one frame."
579 (interactive)
c1b1350b 580 (if (and window-system (not (eq window-system 'pc)))
6238bfaf
RS
581 (make-frame)
582 (select-frame (make-frame))))
583
45c4fdeb
SM
584(defvar before-make-frame-hook nil
585 "Functions to run before a frame is created.")
586
587(defvar after-make-frame-functions nil
588 "Functions to run after a frame is created.
589The functions are run with one arg, the newly created frame.")
590
72bf1a8b 591(defvar after-setting-font-hook nil
81b99826
GM
592 "Functions to run after a frame's font has been changed.")
593
92e443b1 594;; Alias, kept temporarily.
84ed1560 595(define-obsolete-function-alias 'new-frame 'make-frame "22.1")
bc93c097 596
45c4fdeb
SM
597(defun make-frame (&optional parameters)
598 "Return a newly created frame displaying the current buffer.
599Optional argument PARAMETERS is an alist of parameters for the new frame.
600Each element of PARAMETERS should have the form (NAME . VALUE), for example:
a105105a 601
45c4fdeb 602 (name . STRING) The frame should be named STRING.
43a2e52c 603
45c4fdeb
SM
604 (width . NUMBER) The frame should be NUMBER characters in width.
605 (height . NUMBER) The frame should be NUMBER text lines high.
43a2e52c 606
45c4fdeb 607You cannot specify either `width' or `height', you must use neither or both.
43a2e52c 608
45c4fdeb
SM
609 (minibuffer . t) The frame should have a minibuffer.
610 (minibuffer . nil) The frame should have no minibuffer.
611 (minibuffer . only) The frame should contain only a minibuffer.
612 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
43a2e52c 613
45c4fdeb
SM
614Before the frame is created (via `frame-creation-function'), functions on the
615hook `before-make-frame-hook' are run. After the frame is created, functions
8de9d3f6
LT
616on `after-make-frame-functions' are run with one arg, the newly created frame.
617
618This function itself does not make the new frame the selected frame.
619The previously selected frame remains selected. However, the
620window system may select the new frame for its own reasons, for
621instance if the frame appears under the mouse pointer and your
622setup is for focus to follow the pointer."
64c669bc 623 (interactive)
45c4fdeb
SM
624 (run-hooks 'before-make-frame-hook)
625 (let ((frame (funcall frame-creation-function parameters)))
626 (run-hook-with-args 'after-make-frame-functions frame)
627 frame))
64c669bc 628
7eadab74
JB
629(defun filtered-frame-list (predicate)
630 "Return a list of all live frames which satisfy PREDICATE."
047bc928
GM
631 (let* ((frames (frame-list))
632 (list frames))
7eadab74 633 (while (consp frames)
047bc928
GM
634 (unless (funcall predicate (car frames))
635 (setcar frames nil))
7eadab74 636 (setq frames (cdr frames)))
047bc928 637 (delq nil list)))
7eadab74
JB
638
639(defun minibuffer-frame-list ()
640 "Return a list of all frames with their own minibuffers."
641 (filtered-frame-list
642 (function (lambda (frame)
643 (eq frame (window-frame (minibuffer-window frame)))))))
644
9911648b
EZ
645(defun frames-on-display-list (&optional display)
646 "Return a list of all frames on DISPLAY.
647DISPLAY is a name of a display, a string of the form HOST:SERVER.SCREEN.
648If DISPLAY is omitted or nil, it defaults to the selected frame's display."
047bc928
GM
649 (let* ((display (or display (frame-parameter nil 'display)))
650 (func #'(lambda (frame)
f29173c9 651 (equal (frame-parameter frame 'display) display))))
9911648b
EZ
652 (filtered-frame-list func)))
653
654(defun framep-on-display (&optional display)
655 "Return the type of frames on DISPLAY.
656DISPLAY may be a display name or a frame. If it is a frame, its type is
657returned.
658If DISPLAY is omitted or nil, it defaults to the selected frame's display.
659All frames on a given display are of the same type."
660 (or (framep display)
661 (framep (car (frames-on-display-list display)))))
662
58bf6042
JB
663(defun frame-remove-geometry-params (param-list)
664 "Return the parameter list PARAM-LIST, but with geometry specs removed.
665This deletes all bindings in PARAM-LIST for `top', `left', `width',
791e09d8 666`height', `user-size' and `user-position' parameters.
58bf6042
JB
667Emacs uses this to avoid overriding explicit moves and resizings from
668the user during startup."
669 (setq param-list (cons nil param-list))
670 (let ((tail param-list))
671 (while (consp (cdr tail))
672 (if (and (consp (car (cdr tail)))
791e09d8
RS
673 (memq (car (car (cdr tail)))
674 '(height width top left user-position user-size)))
675 (progn
676 (setq frame-initial-geometry-arguments
677 (cons (car (cdr tail)) frame-initial-geometry-arguments))
678 (setcdr tail (cdr (cdr tail))))
58bf6042 679 (setq tail (cdr tail)))))
e11c3dc2
KH
680 (setq frame-initial-geometry-arguments
681 (nreverse frame-initial-geometry-arguments))
58bf6042
JB
682 (cdr param-list))
683
0ac18fb0 684(defcustom focus-follows-mouse t
6527c9b7
RS
685 "*Non-nil if window system changes focus when you move the mouse.
686You should set this variable to tell Emacs how your window manager
687handles focus, since there is no way in general for Emacs to find out
38938eeb
EZ
688automatically.
689
690This variable does not have any effect on MS-Windows."
0ac18fb0 691 :type 'boolean
cd32a7ba
DN
692 :group 'frames
693 :version "20.3")
26ef026d 694
030f4537
GM
695(defun select-frame-set-input-focus (frame)
696 "Select FRAME, raise it, and set input focus, if possible."
697 (select-frame frame)
698 (raise-frame frame)
699 ;; Ensure, if possible, that frame gets input focus.
3c5876d2 700 (cond ((memq window-system '(x mac))
80c39c38
RS
701 (x-focus-frame frame))
702 ((eq window-system 'w32)
703 (w32-focus-frame frame)))
030f4537 704 (cond (focus-follows-mouse
80c39c38 705 (set-mouse-position (selected-frame) (1- (frame-width)) 0))))
030f4537 706
ceab6935 707(defun other-frame (arg)
563283b1 708 "Select the ARG'th different visible frame on current display, and raise it.
ceab6935
RM
709All frames are arranged in a cyclic order.
710This command selects the frame ARG steps away in that order.
bb578a72
RS
711A negative ARG moves in the opposite order.
712
713To make this command work properly, you must tell Emacs
714how the system (or the window manager) generally handles
715focus-switching between windows. If moving the mouse onto a window
716selects it (gives it focus), set `focus-follows-mouse' to t.
717Otherwise, that variable should be nil."
ceab6935
RM
718 (interactive "p")
719 (let ((frame (selected-frame)))
720 (while (> arg 0)
a569dbc3
RM
721 (setq frame (next-frame frame))
722 (while (not (eq (frame-visible-p frame) t))
723 (setq frame (next-frame frame)))
724 (setq arg (1- arg)))
ceab6935 725 (while (< arg 0)
a569dbc3
RM
726 (setq frame (previous-frame frame))
727 (while (not (eq (frame-visible-p frame) t))
728 (setq frame (previous-frame frame)))
915cfd1f 729 (setq arg (1+ arg)))
030f4537 730 (select-frame-set-input-focus frame)))
845cde06 731
3db7df06
SM
732(defun iconify-or-deiconify-frame ()
733 "Iconify the selected frame, or deiconify if it's currently an icon."
734 (interactive)
735 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
736 (iconify-frame)
737 (make-frame-visible)))
738
845cde06
EZ
739(defun make-frame-names-alist ()
740 (let* ((current-frame (selected-frame))
741 (falist
742 (cons
743 (cons (frame-parameter current-frame 'name) current-frame) nil))
744 (frame (next-frame nil t)))
745 (while (not (eq frame current-frame))
746 (progn
747 (setq falist (cons (cons (frame-parameter frame 'name) frame) falist))
748 (setq frame (next-frame frame t))))
749 falist))
750
751(defvar frame-name-history nil)
845cde06 752(defun select-frame-by-name (name)
563283b1 753 "Select the frame on the current terminal whose name is NAME and raise it.
845cde06
EZ
754If there is no frame by that name, signal an error."
755 (interactive
716ff1c9
RS
756 (let* ((frame-names-alist (make-frame-names-alist))
757 (default (car (car frame-names-alist)))
758 (input (completing-read
759 (format "Select Frame (default %s): " default)
760 frame-names-alist nil t nil 'frame-name-history)))
845cde06
EZ
761 (if (= (length input) 0)
762 (list default)
763 (list input))))
716ff1c9
RS
764 (let* ((frame-names-alist (make-frame-names-alist))
765 (frame (cdr (assoc name frame-names-alist))))
845cde06
EZ
766 (or frame
767 (error "There is no frame named `%s'" name))
768 (make-frame-visible frame)
769 (raise-frame frame)
880a9ae1
AI
770 (select-frame frame)
771 ;; Ensure, if possible, that frame gets input focus.
4c08371a 772 (cond ((memq window-system '(x mac))
80c39c38
RS
773 (x-focus-frame frame))
774 ((eq window-system 'w32)
775 (w32-focus-frame frame)))
776 (when focus-follows-mouse
777 (set-mouse-position frame (1- (frame-width frame)) 0))))
64c669bc 778\f
dc6d9681
JB
779;;;; Frame configurations
780
781(defun current-frame-configuration ()
782 "Return a list describing the positions and states of all frames.
376a7584
JB
783Its car is `frame-configuration'.
784Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
785where
786 FRAME is a frame object,
787 ALIST is an association list specifying some of FRAME's parameters, and
788 WINDOW-CONFIG is a window configuration object for FRAME."
789 (cons 'frame-configuration
790 (mapcar (function
791 (lambda (frame)
792 (list frame
793 (frame-parameters frame)
794 (current-window-configuration frame))))
795 (frame-list))))
dc6d9681 796
68cd265f 797(defun set-frame-configuration (configuration &optional nodelete)
dc6d9681
JB
798 "Restore the frames to the state described by CONFIGURATION.
799Each frame listed in CONFIGURATION has its position, size, window
68cd265f 800configuration, and other parameters set as specified in CONFIGURATION.
d398de43
LT
801However, this function does not restore deleted frames.
802
a78db71c
RS
803Ordinarily, this function deletes all existing frames not
804listed in CONFIGURATION. But if optional second argument NODELETE
5da841d2 805is given and non-nil, the unwanted frames are iconified instead."
376a7584
JB
806 (or (frame-configuration-p configuration)
807 (signal 'wrong-type-argument
808 (list 'frame-configuration-p configuration)))
809 (let ((config-alist (cdr configuration))
810 frames-to-delete)
06b1a5ef 811 (mapcar (function
dc6d9681 812 (lambda (frame)
376a7584 813 (let ((parameters (assq frame config-alist)))
06b1a5ef
JB
814 (if parameters
815 (progn
98e9d14b
JB
816 (modify-frame-parameters
817 frame
85557d7e 818 ;; Since we can't set a frame's minibuffer status,
98e9d14b
JB
819 ;; we might as well omit the parameter altogether.
820 (let* ((parms (nth 1 parameters))
821 (mini (assq 'minibuffer parms)))
822 (if mini (setq parms (delq mini parms)))
823 parms))
06b1a5ef 824 (set-window-configuration (nth 2 parameters)))
dc6d9681
JB
825 (setq frames-to-delete (cons frame frames-to-delete))))))
826 (frame-list))
a78db71c 827 (if nodelete
5da841d2
RS
828 ;; Note: making frames invisible here was tried
829 ;; but led to some strange behavior--each time the frame
830 ;; was made visible again, the window manager asked afresh
831 ;; for where to put it.
832 (mapcar 'iconify-frame frames-to-delete)
a78db71c 833 (mapcar 'delete-frame frames-to-delete))))
64c669bc 834\f
dc6d9681
JB
835;;;; Convenience functions for accessing and interactively changing
836;;;; frame parameters.
64c669bc 837
151bdc83 838(defun frame-height (&optional frame)
dc6d9681
JB
839 "Return number of lines available for display on FRAME.
840If FRAME is omitted, describe the currently selected frame."
151bdc83 841 (cdr (assq 'height (frame-parameters frame))))
dc6d9681
JB
842
843(defun frame-width (&optional frame)
844 "Return number of columns available for display on FRAME.
845If FRAME is omitted, describe the currently selected frame."
151bdc83 846 (cdr (assq 'width (frame-parameters frame))))
dc6d9681 847
889611f0 848(defalias 'set-default-font 'set-frame-font)
1cef6541 849(defun set-frame-font (font-name &optional keep-size)
40d34803 850 "Set the font of the selected frame to FONT-NAME.
61298010 851When called interactively, prompt for the name of the font to use.
1cef6541
JB
852To get the frame's current default font, use `frame-parameters'.
853
854The default behavior is to keep the numbers of lines and columns in
84ed1560 855the frame, thus may change its pixel size. If optional KEEP-SIZE is
1cef6541
JB
856non-nil (interactively, prefix argument) the current frame size (in
857pixels) is kept by adjusting the numbers of the lines and columns."
f39784dd 858 (interactive
1cef6541
JB
859 (let* ((completion-ignore-case t)
860 (font (completing-read "Font name: "
861 (mapcar #'list
862 ;; x-list-fonts will fail with an error
863 ;; if this frame doesn't support fonts.
93289292
MB
864 (x-list-fonts "*" nil (selected-frame)))
865 nil nil nil nil
866 (frame-parameter nil 'font))))
1cef6541
JB
867 (list font current-prefix-arg)))
868 (let (fht fwd)
869 (if keep-size
870 (setq fht (* (frame-parameter nil 'height) (frame-char-height))
871 fwd (* (frame-parameter nil 'width) (frame-char-width))))
872 (modify-frame-parameters (selected-frame)
873 (list (cons 'font font-name)))
874 (if keep-size
875 (modify-frame-parameters
876 (selected-frame)
877 (list (cons 'height (round fht (frame-char-height)))
878 (cons 'width (round fwd (frame-char-width)))))))
72bf1a8b 879 (run-hooks 'after-setting-font-hook 'after-setting-font-hooks))
64c669bc 880
7e573c4a 881(defun set-frame-parameter (frame parameter value)
0dac35b8
KL
882 "Set frame parameter PARAMETER to VALUE on FRAME.
883If FRAME is nil, it defaults to the selected frame.
884See `modify-frame-parameters.'"
7e573c4a
SM
885 (modify-frame-parameters frame (list (cons parameter value))))
886
8290babd 887(defun set-background-color (color-name)
40d34803 888 "Set the background color of the selected frame to COLOR-NAME.
61298010
RS
889When called interactively, prompt for the name of the color to use.
890To get the frame's current background color, use `frame-parameters'."
63ec4f94 891 (interactive (list (facemenu-read-color "Background color: ")))
dc6d9681 892 (modify-frame-parameters (selected-frame)
528e1416
EZ
893 (list (cons 'background-color color-name)))
894 (or window-system
895 (face-set-after-frame-default (selected-frame))))
64c669bc 896
8290babd 897(defun set-foreground-color (color-name)
40d34803 898 "Set the foreground color of the selected frame to COLOR-NAME.
61298010
RS
899When called interactively, prompt for the name of the color to use.
900To get the frame's current foreground color, use `frame-parameters'."
63ec4f94 901 (interactive (list (facemenu-read-color "Foreground color: ")))
dc6d9681 902 (modify-frame-parameters (selected-frame)
528e1416
EZ
903 (list (cons 'foreground-color color-name)))
904 (or window-system
905 (face-set-after-frame-default (selected-frame))))
64c669bc
JB
906
907(defun set-cursor-color (color-name)
40d34803 908 "Set the text cursor color of the selected frame to COLOR-NAME.
61298010
RS
909When called interactively, prompt for the name of the color to use.
910To get the frame's current cursor color, use `frame-parameters'."
63ec4f94 911 (interactive (list (facemenu-read-color "Cursor color: ")))
dc6d9681 912 (modify-frame-parameters (selected-frame)
7eadab74 913 (list (cons 'cursor-color color-name))))
64c669bc 914
eaa974e1 915(defun set-mouse-color (color-name)
40d34803 916 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
61298010
RS
917When called interactively, prompt for the name of the color to use.
918To get the frame's current mouse color, use `frame-parameters'."
63ec4f94 919 (interactive (list (facemenu-read-color "Mouse color: ")))
dc6d9681 920 (modify-frame-parameters (selected-frame)
ec6d4463
KH
921 (list (cons 'mouse-color
922 (or color-name
923 (cdr (assq 'mouse-color
924 (frame-parameters))))))))
7eadab74 925
eaa974e1 926(defun set-border-color (color-name)
40d34803 927 "Set the color of the border of the selected frame to COLOR-NAME.
61298010
RS
928When called interactively, prompt for the name of the color to use.
929To get the frame's current border color, use `frame-parameters'."
63ec4f94 930 (interactive (list (facemenu-read-color "Border color: ")))
eaa974e1
JB
931 (modify-frame-parameters (selected-frame)
932 (list (cons 'border-color color-name))))
933
934(defun auto-raise-mode (arg)
7eadab74 935 "Toggle whether or not the selected frame should auto-raise.
79e6ae33
RS
936With arg, turn auto-raise mode on if and only if arg is positive.
937Note that this controls Emacs's own auto-raise feature.
938Some window managers allow you to enable auto-raise for certain windows.
939You can use that for Emacs windows if you wish, but if you do,
940that is beyond the control of Emacs and this command has no effect on it."
7eadab74
JB
941 (interactive "P")
942 (if (null arg)
943 (setq arg
944 (if (cdr (assq 'auto-raise (frame-parameters (selected-frame))))
945 -1 1)))
9626b928
GM
946 (if (> arg 0)
947 (raise-frame (selected-frame)))
dc6d9681 948 (modify-frame-parameters (selected-frame)
7eadab74
JB
949 (list (cons 'auto-raise (> arg 0)))))
950
eaa974e1 951(defun auto-lower-mode (arg)
7eadab74 952 "Toggle whether or not the selected frame should auto-lower.
79e6ae33
RS
953With arg, turn auto-lower mode on if and only if arg is positive.
954Note that this controls Emacs's own auto-lower feature.
955Some window managers allow you to enable auto-lower for certain windows.
956You can use that for Emacs windows if you wish, but if you do,
957that is beyond the control of Emacs and this command has no effect on it."
7eadab74
JB
958 (interactive "P")
959 (if (null arg)
960 (setq arg
961 (if (cdr (assq 'auto-lower (frame-parameters (selected-frame))))
962 -1 1)))
dc6d9681 963 (modify-frame-parameters (selected-frame)
7eadab74 964 (list (cons 'auto-lower (> arg 0)))))
7777d03b
EZ
965(defun set-frame-name (name)
966 "Set the name of the selected frame to NAME.
967When called interactively, prompt for the name of the frame.
968The frame name is displayed on the modeline if the terminal displays only
969one frame, otherwise the name is displayed on the frame's caption bar."
970 (interactive "sFrame name: ")
971 (modify-frame-parameters (selected-frame)
972 (list (cons 'name name))))
56cfea72
KS
973
974(defun frame-current-scroll-bars (&optional frame)
975 "Return the current scroll-bar settings in frame FRAME.
1cecf04d 976Value is a cons (VERTICAL . HORIZ0NTAL) where VERTICAL specifies the
56cfea72 977current location of the vertical scroll-bars (left, right, or nil),
1cecf04d 978and HORIZONTAL specifies the current location of the horizontal scroll
56cfea72
KS
979bars (top, bottom, or nil)."
980 (let ((vert (frame-parameter frame 'vertical-scroll-bars))
981 (hor nil))
982 (unless (memq vert '(left right nil))
983 (setq vert default-frame-scroll-bars))
984 (cons vert hor)))
64c669bc 985\f
9911648b
EZ
986;;;; Frame/display capabilities.
987(defun display-mouse-p (&optional display)
988 "Return non-nil if DISPLAY has a mouse available.
989DISPLAY can be a display name, a frame, or nil (meaning the selected
990frame's display)."
991 (let ((frame-type (framep-on-display display)))
992 (cond
993 ((eq frame-type 'pc)
994 (msdos-mouse-p))
995 ((eq system-type 'windows-nt)
9fa5bb32
RS
996 (with-no-warnings
997 (> w32-num-mouse-buttons 0)))
9911648b
EZ
998 ((memq frame-type '(x mac))
999 t) ;; We assume X and Mac *always* have a pointing device
1000 (t
7565ee93
DL
1001 (or (and (featurep 'xt-mouse)
1002 xterm-mouse-mode)
1003 ;; t-mouse is distributed with the GPM package. It doesn't have
1004 ;; a toggle.
1005 (featurep 't-mouse))))))
9911648b
EZ
1006
1007(defun display-popup-menus-p (&optional display)
1008 "Return non-nil if popup menus are supported on DISPLAY.
1009DISPLAY can be a display name, a frame, or nil (meaning the selected
1010frame's display).
1011Support for popup menus requires that the mouse be available."
1012 (and
1013 (let ((frame-type (framep-on-display display)))
1014 (memq frame-type '(x w32 pc mac)))
1015 (display-mouse-p display)))
1016
1017(defun display-graphic-p (&optional display)
1018 "Return non-nil if DISPLAY is a graphic display.
1019Graphical displays are those which are capable of displaying several
1020frames and several different fonts at once. This is true for displays
1021that use a window system such as X, and false for text-only terminals.
1022DISPLAY can be a display name, a frame, or nil (meaning the selected
1023frame's display)."
1024 (not (null (memq (framep-on-display display) '(x w32 mac)))))
1025
ddc456e4
EZ
1026(defun display-images-p (&optional display)
1027 "Return non-nil if DISPLAY can display images.
1028
1029DISPLAY can be a display name, a frame, or nil (meaning the selected
1030frame's display)."
1031 (and (display-graphic-p display)
1032 (fboundp 'image-mask-p)
fcc6f5cc 1033 (fboundp 'image-size)))
ddc456e4 1034
6693b279
EZ
1035(defalias 'display-multi-frame-p 'display-graphic-p)
1036(defalias 'display-multi-font-p 'display-graphic-p)
1037
9911648b
EZ
1038(defun display-selections-p (&optional display)
1039 "Return non-nil if DISPLAY supports selections.
1040A selection is a way to transfer text or other data between programs
1041via special system buffers called `selection' or `cut buffer' or
1042`clipboard'.
1043DISPLAY can be a display name, a frame, or nil (meaning the selected
1044frame's display)."
1045 (let ((frame-type (framep-on-display display)))
1046 (cond
1047 ((eq frame-type 'pc)
1048 ;; MS-DOG frames support selections when Emacs runs inside
1049 ;; the Windows' DOS Box.
9fa5bb32
RS
1050 (with-no-warnings
1051 (not (null dos-windows-version))))
9911648b
EZ
1052 ((memq frame-type '(x w32 mac))
1053 t) ;; FIXME?
1054 (t
1055 nil))))
1056
1057(defun display-screens (&optional display)
1058 "Return the number of screens associated with DISPLAY."
1059 (let ((frame-type (framep-on-display display)))
1060 (cond
bb9404d6 1061 ((memq frame-type '(x w32 mac))
9911648b 1062 (x-display-screens display))
bb9404d6 1063 (t
9911648b
EZ
1064 1))))
1065
1066(defun display-pixel-height (&optional display)
1067 "Return the height of DISPLAY's screen in pixels.
1068For character terminals, each character counts as a single pixel."
1069 (let ((frame-type (framep-on-display display)))
1070 (cond
1071 ((memq frame-type '(x w32 mac))
1072 (x-display-pixel-height display))
1073 (t
1074 (frame-height (if (framep display) display (selected-frame)))))))
1075
1076(defun display-pixel-width (&optional display)
1077 "Return the width of DISPLAY's screen in pixels.
1078For character terminals, each character counts as a single pixel."
1079 (let ((frame-type (framep-on-display display)))
1080 (cond
1081 ((memq frame-type '(x w32 mac))
1082 (x-display-pixel-width display))
1083 (t
1084 (frame-width (if (framep display) display (selected-frame)))))))
1085
1086(defun display-mm-height (&optional display)
1087 "Return the height of DISPLAY's screen in millimeters.
1088If the information is unavailable, value is nil."
1089 (and (memq (framep-on-display display) '(x w32 mac))
1090 (x-display-mm-height display)))
1091
1092(defun display-mm-width (&optional display)
1093 "Return the width of DISPLAY's screen in millimeters.
1094If the information is unavailable, value is nil."
1095 (and (memq (framep-on-display display) '(x w32 mac))
1096 (x-display-mm-width display)))
1097
1098(defun display-backing-store (&optional display)
1099 "Return the backing store capability of DISPLAY's screen.
1100The value may be `always', `when-mapped', `not-useful', or nil if
1101the question is inapplicable to a certain kind of display."
1102 (let ((frame-type (framep-on-display display)))
1103 (cond
1104 ((memq frame-type '(x w32 mac))
1105 (x-display-backing-store display))
1106 (t
1107 'not-useful))))
1108
1109(defun display-save-under (&optional display)
1110 "Return non-nil if DISPLAY's screen supports the SaveUnder feature."
1111 (let ((frame-type (framep-on-display display)))
1112 (cond
1113 ((memq frame-type '(x w32 mac))
1114 (x-display-save-under display))
1115 (t
1116 'not-useful))))
1117
1118(defun display-planes (&optional display)
1119 "Return the number of planes supported by DISPLAY."
1120 (let ((frame-type (framep-on-display display)))
1121 (cond
1122 ((memq frame-type '(x w32 mac))
1123 (x-display-planes display))
1124 ((eq frame-type 'pc)
1125 4)
1126 (t
1127 (truncate (log (length (tty-color-alist)) 2))))))
1128
1129(defun display-color-cells (&optional display)
1130 "Return the number of color cells supported by DISPLAY."
1131 (let ((frame-type (framep-on-display display)))
1132 (cond
1133 ((memq frame-type '(x w32 mac))
1134 (x-display-color-cells display))
1135 ((eq frame-type 'pc)
1136 16)
1137 (t
a6ab2fcf 1138 (tty-display-color-cells)))))
9911648b
EZ
1139
1140(defun display-visual-class (&optional display)
1141 "Returns the visual class of DISPLAY.
1142The value is one of the symbols `static-gray', `gray-scale',
1143`static-color', `pseudo-color', `true-color', or `direct-color'."
1144 (let ((frame-type (framep-on-display display)))
1145 (cond
1146 ((memq frame-type '(x w32 mac))
1147 (x-display-visual-class display))
1148 ((and (memq frame-type '(pc t))
1149 (tty-display-color-p display))
1150 'static-color)
1151 (t
1152 'static-gray))))
1153
1154\f
dc6d9681 1155;;;; Aliases for backward compatibility with Emacs 18.
84ed1560
JB
1156(define-obsolete-function-alias 'screen-height 'frame-height) ;before 19.15
1157(define-obsolete-function-alias 'screen-width 'frame-width) ;before 19.15
9e2b097b
JB
1158
1159(defun set-screen-width (cols &optional pretend)
84ed1560 1160 "Change the size of the screen to COLS columns.
40d34803
DL
1161Optional second arg non-nil means that redisplay should use COLS columns
1162but that the idea of the actual width of the frame should not be changed.
84ed1560 1163This function is provided only for compatibility with Emacs 18."
9e2b097b
JB
1164 (set-frame-width (selected-frame) cols pretend))
1165
1166(defun set-screen-height (lines &optional pretend)
84ed1560 1167 "Change the height of the screen to LINES lines.
40d34803
DL
1168Optional second arg non-nil means that redisplay should use LINES lines
1169but that the idea of the actual height of the screen should not be changed.
84ed1560 1170This function is provided only for compatibility with Emacs 18."
9e2b097b
JB
1171 (set-frame-height (selected-frame) lines pretend))
1172
154a757e
GM
1173(defun delete-other-frames (&optional frame)
1174 "Delete all frames except FRAME.
a2125918
GM
1175If FRAME uses another frame's minibuffer, the minibuffer frame is
1176left untouched. FRAME nil or omitted means use the selected frame."
154a757e
GM
1177 (interactive)
1178 (unless frame
1179 (setq frame (selected-frame)))
a2125918
GM
1180 (let* ((mini-frame (window-frame (minibuffer-window frame)))
1181 (frames (delq mini-frame (delq frame (frame-list)))))
1182 ;; Delete mon-minibuffer-only frames first, because `delete-frame'
1183 ;; signals an error when trying to delete a mini-frame that's
1184 ;; still in use by another frame.
1185 (dolist (frame frames)
1186 (unless (eq (frame-parameter frame 'minibuffer) 'only)
1187 (delete-frame frame)))
1188 ;; Delete minibuffer-only frames.
1189 (dolist (frame frames)
1190 (when (eq (frame-parameter frame 'minibuffer) 'only)
1191 (delete-frame frame)))))
154a757e 1192
2598a293
SM
1193(make-obsolete 'set-screen-width 'set-frame-width) ;before 19.15
1194(make-obsolete 'set-screen-height 'set-frame-height) ;before 19.15
dc6d9681 1195
da7829a3 1196;; miscellaneous obsolescence declarations
84ed1560
JB
1197(define-obsolete-variable-alias 'delete-frame-hook
1198 'delete-frame-functions "22.1")
da7829a3 1199
dc6d9681 1200\f
7e573c4a 1201;; Highlighting trailing whitespace.
81b99826
GM
1202
1203(make-variable-buffer-local 'show-trailing-whitespace)
1204
1205(defcustom show-trailing-whitespace nil
e6c45c29
LT
1206 "*Non-nil means highlight trailing whitespace.
1207This is done in the face `trailing-whitespace'."
81b99826 1208 :type 'boolean
b4aefb19 1209 :group 'whitespace-faces)
81b99826
GM
1210
1211
1212\f
7e573c4a 1213;; Scrolling
79b14b94
GM
1214
1215(defgroup scrolling nil
1216 "Scrolling windows."
1217 :version "21.1"
1218 :group 'frames)
1219
968ecc28 1220(defcustom auto-hscroll-mode t
310e9a21 1221 "*Allow or disallow automatic scrolling windows horizontally.
9ea60c46 1222If non-nil, windows are automatically scrolled horizontally to make
79b14b94
GM
1223point visible."
1224 :version "21.1"
1225 :type 'boolean
1226 :group 'scrolling)
968ecc28 1227(defvaralias 'automatic-hscrolling 'auto-hscroll-mode)
79b14b94
GM
1228
1229\f
7e573c4a 1230;; Blinking cursor
81b99826
GM
1231
1232(defgroup cursor nil
ca693be8 1233 "Displaying text cursors."
40d34803 1234 :version "21.1"
81b99826
GM
1235 :group 'frames)
1236
1237(defcustom blink-cursor-delay 0.5
ca693be8 1238 "*Seconds of idle time after which cursor starts to blink."
81b99826
GM
1239 :type 'number
1240 :group 'cursor)
1241
1242(defcustom blink-cursor-interval 0.5
1243 "*Length of cursor blink interval in seconds."
81b99826
GM
1244 :type 'number
1245 :group 'cursor)
1246
1247(defvar blink-cursor-idle-timer nil
ca693be8
GM
1248 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
1249The function `blink-cursor-start' is called when the timer fires.")
81b99826
GM
1250
1251(defvar blink-cursor-timer nil
ca693be8 1252 "Timer started from `blink-cursor-start'.
a795e09a
LT
1253This timer calls `blink-cursor-timer-function' every
1254`blink-cursor-interval' seconds.")
1255
485464c4 1256(define-minor-mode blink-cursor-mode
81b99826 1257 "Toggle blinking cursor mode.
be6bbb55 1258With a numeric argument, turn blinking cursor mode on iff ARG is positive.
81b99826 1259When blinking cursor mode is enabled, the cursor of the selected
cacf2193
RS
1260window blinks.
1261
1262Note that this command is effective only when Emacs
1263displays through a window system, because then Emacs does its own
1264cursor display. On a text-only terminal, this is not implemented."
485464c4 1265 :init-value (not (or noninteractive
947d4ae8 1266 no-blinking-cursor
485464c4 1267 (eq system-type 'ms-dos)
7107f6b2 1268 (not (memq window-system '(x w32 mac)))))
947d4ae8 1269 :initialize 'custom-initialize-safe-default
ffa8d0ef 1270 :group 'cursor
485464c4
SM
1271 :global t
1272 (if blink-cursor-idle-timer (cancel-timer blink-cursor-idle-timer))
1273 (if blink-cursor-timer (cancel-timer blink-cursor-timer))
1274 (setq blink-cursor-idle-timer nil
1275 blink-cursor-timer nil)
1276 (if blink-cursor-mode
1277 (progn
1278 ;; Hide the cursor.
1279 ;;(internal-show-cursor nil nil)
1280 (setq blink-cursor-idle-timer
1281 (run-with-idle-timer blink-cursor-delay
1282 blink-cursor-delay
1283 'blink-cursor-start)))
1284 (internal-show-cursor nil t)))
1285
84ed1560 1286(define-obsolete-variable-alias 'blink-cursor 'blink-cursor-mode "22.1")
81b99826 1287
81b99826 1288(defun blink-cursor-start ()
ca693be8
GM
1289 "Timer function called from the timer `blink-cursor-idle-timer'.
1290This starts the timer `blink-cursor-timer', which makes the cursor blink
1291if appropriate. It also arranges to cancel that timer when the next
1292command starts, by installing a pre-command hook."
81b99826 1293 (when (null blink-cursor-timer)
f9ac92c5
CY
1294 ;; Set up the timer first, so that if this signals an error,
1295 ;; blink-cursor-end is not added to pre-command-hook.
81b99826
GM
1296 (setq blink-cursor-timer
1297 (run-with-timer blink-cursor-interval blink-cursor-interval
f9ac92c5
CY
1298 'blink-cursor-timer-function))
1299 (add-hook 'pre-command-hook 'blink-cursor-end)
1300 (internal-show-cursor nil nil)))
0a5ebe4b
GM
1301
1302(defun blink-cursor-timer-function ()
1303 "Timer function of timer `blink-cursor-timer'."
1304 (internal-show-cursor nil (not (internal-show-cursor-p))))
81b99826
GM
1305
1306(defun blink-cursor-end ()
1307 "Stop cursor blinking.
ca693be8 1308This is installed as a pre-command hook by `blink-cursor-start'.
f39784dd 1309When run, it cancels the timer `blink-cursor-timer' and removes
ca693be8 1310itself as a pre-command hook."
81b99826 1311 (remove-hook 'pre-command-hook 'blink-cursor-end)
0a5ebe4b 1312 (internal-show-cursor nil t)
f9ac92c5
CY
1313 (condition-case nil
1314 (cancel-timer blink-cursor-timer)
1315 (error nil))
81b99826
GM
1316 (setq blink-cursor-timer nil))
1317
81b99826 1318\f
7e573c4a 1319;; Hourglass pointer
81b99826 1320
a6c411ff 1321(defcustom display-hourglass t
088e75cc
RS
1322 "*Non-nil means show an hourglass pointer, when Emacs is busy.
1323This feature only works when on a window system that can change
1324cursor shapes."
81b99826 1325 :type 'boolean
a6c411ff 1326 :group 'cursor)
81b99826 1327
a6c411ff 1328(defcustom hourglass-delay 1
63ec4f94 1329 "*Seconds to wait before displaying an hourglass pointer when Emacs is busy."
0a86e779 1330 :type 'number
a6c411ff 1331 :group 'cursor)
1d0a3ef4 1332
5b2c5477 1333\f
c0eb3c10 1334(defcustom cursor-in-non-selected-windows t
84ed1560 1335 "*Non-nil means show a hollow box cursor in non-selected windows.
e053c60f 1336If nil, don't show a cursor except in the selected window.
f39784dd 1337Use Custom to set this variable to get the display updated."
63ec4f94 1338 :tag "Cursor In Non-selected Windows"
5b2c5477
GM
1339 :type 'boolean
1340 :group 'cursor
5b2c5477
GM
1341 :set #'(lambda (symbol value)
1342 (set-default symbol value)
5b2c5477 1343 (force-mode-line-update t)))
f39784dd 1344
81b99826 1345\f
64c669bc 1346;;;; Key bindings
64c669bc 1347
6238bfaf 1348(define-key ctl-x-5-map "2" 'make-frame-command)
154a757e 1349(define-key ctl-x-5-map "1" 'delete-other-frames)
dc6d9681 1350(define-key ctl-x-5-map "0" 'delete-frame)
ceab6935 1351(define-key ctl-x-5-map "o" 'other-frame)
49116ac0 1352
dc6d9681 1353(provide 'frame)
c88ab9ce 1354
485464c4 1355;; arch-tag: 82979c70-b8f2-4306-b2ad-ddbd6b328b56
dc6d9681 1356;;; frame.el ends here