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