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