]> code.delx.au - gnu-emacs/blob - lisp/frame.el
Merge from emacs--rel--22
[gnu-emacs] / lisp / frame.el
1 ;;; frame.el --- multi-frame management independent of window systems
2
3 ;; Copyright (C) 1993, 1994, 1996, 1997, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5
6 ;; Maintainer: FSF
7 ;; Keywords: internal
8
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 3, 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., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (defvar frame-creation-function nil
31 "Window-system dependent function to call to create a new frame.
32 The window system startup file should set this to its frame creation
33 function, which should take an alist of parameters as its argument.")
34
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.
38 (defcustom initial-frame-alist nil
39 "*Alist of frame parameters for creating the initial X window frame.
40 You can set this in your `.emacs' file; for example,
41 (setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55)))
42 Parameters specified here supersede the values given in `default-frame-alist'.
43
44 If the value calls for a frame without a minibuffer, and you have not created
45 a minibuffer frame on your own, one is created according to
46 `minibuffer-frame-alist'.
47
48 You can specify geometry-related options for just the initial frame
49 by setting this variable in your `.emacs' file; however, they won't
50 take effect until Emacs reads `.emacs', which happens after first creating
51 the frame. If you want the frame to have the proper geometry as soon
52 as 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,
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)
62
63 (defcustom minibuffer-frame-alist '((width . 80) (height . 2))
64 "*Alist of frame parameters for initially creating a minibuffer frame.
65 You can set this in your `.emacs' file; for example,
66 (setq minibuffer-frame-alist
67 '((top . 1) (left . 1) (width . 80) (height . 2)))
68 Parameters specified here supersede the values given in
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)
74
75 (defcustom pop-up-frame-alist nil
76 "*Alist of frame parameters used when creating pop-up frames.
77 Pop-up frames are used for completions, help, and the like.
78 This variable can be set in your init file, like this:
79 (setq pop-up-frame-alist '((width . 80) (height . 20)))
80 These supersede the values given in `default-frame-alist',
81 for pop-up frames."
82 :type '(repeat (cons :format "%v"
83 (symbol :tag "Parameter")
84 (sexp :tag "Value")))
85 :group 'frames)
86
87 (setq pop-up-frame-function
88 ;; Using `function' here caused some sort of problem.
89 '(lambda ()
90 (make-frame pop-up-frame-alist)))
91
92 (defcustom special-display-frame-alist
93 '((height . 14) (width . 80) (unsplittable . t))
94 "*Alist of frame parameters used when creating special frames.
95 Special frames are used for buffers whose names are in
96 `special-display-buffer-names' and for buffers whose names match
97 one of the regular expressions in `special-display-regexps'.
98 This variable can be set in your init file, like this:
99 (setq special-display-frame-alist '((width . 80) (height . 20)))
100 These supersede the values given in `default-frame-alist'."
101 :type '(repeat (cons :format "%v"
102 (symbol :tag "Parameter")
103 (sexp :tag "Value")))
104 :group 'frames)
105
106 (defun special-display-popup-frame (buffer &optional args)
107 "Display BUFFER in its own frame, reusing an existing window if any.
108 Return the window chosen.
109 Currently we do not insist on selecting the window within its frame.
110 If ARGS is an alist, use it as a list of frame parameter specs.
111 If ARGS is a list whose car is a symbol,
112 use (car ARGS) as a function to do the work.
113 Pass it BUFFER as first arg, and (cdr ARGS) gives the rest of the args."
114 (if (and args (symbolp (car args)))
115 (apply (car args) buffer (cdr args))
116 (let ((window (get-buffer-window buffer 0)))
117 (or
118 ;; If we have a window already, make it visible.
119 (when window
120 (let ((frame (window-frame window)))
121 (make-frame-visible frame)
122 (raise-frame frame)
123 window))
124 ;; Reuse the current window if the user requested it.
125 (when (cdr (assq 'same-window args))
126 (condition-case nil
127 (progn (switch-to-buffer buffer) (selected-window))
128 (error nil)))
129 ;; Stay on the same frame if requested.
130 (when (or (cdr (assq 'same-frame args)) (cdr (assq 'same-window args)))
131 (let* ((pop-up-frames nil) (pop-up-windows t)
132 special-display-regexps special-display-buffer-names
133 (window (display-buffer buffer)))
134 ;; Only do it if this is a new window:
135 ;; (set-window-dedicated-p window t)
136 window))
137 ;; If no window yet, make one in a new frame.
138 (let ((frame
139 (with-current-buffer buffer
140 (make-frame (append args special-display-frame-alist)))))
141 (set-window-buffer (frame-selected-window frame) buffer)
142 (set-window-dedicated-p (frame-selected-window frame) t)
143 (frame-selected-window frame))))))
144
145 (defun handle-delete-frame (event)
146 "Handle delete-frame events from the X server."
147 (interactive "e")
148 (let ((frame (posn-window (event-start event)))
149 (i 0)
150 (tail (frame-list)))
151 (while tail
152 (and (frame-visible-p (car tail))
153 (not (eq (car tail) frame))
154 (setq i (1+ i)))
155 (setq tail (cdr tail)))
156 (if (> i 0)
157 (delete-frame frame t)
158 ;; Gildea@x.org says it is ok to ask questions before terminating.
159 (save-buffers-kill-emacs))))
160 \f
161 ;;;; Arrangement of frames at startup
162
163 ;; 1) Load the window system startup file from the lisp library and read the
164 ;; high-priority arguments (-q and the like). The window system startup
165 ;; file should create any frames specified in the window system defaults.
166 ;;
167 ;; 2) If no frames have been opened, we open an initial text frame.
168 ;;
169 ;; 3) Once the init file is done, we apply any newly set parameters
170 ;; in initial-frame-alist to the frame.
171
172 ;; These are now called explicitly at the proper times,
173 ;; since that is easier to understand.
174 ;; Actually using hooks within Emacs is bad for future maintenance. --rms.
175 ;; (add-hook 'before-init-hook 'frame-initialize)
176 ;; (add-hook 'window-setup-hook 'frame-notice-user-settings)
177
178 ;; If we create the initial frame, this is it.
179 (defvar frame-initial-frame nil)
180
181 ;; Record the parameters used in frame-initialize to make the initial frame.
182 (defvar frame-initial-frame-alist)
183
184 (defvar frame-initial-geometry-arguments nil)
185
186 ;; startup.el calls this function before loading the user's init
187 ;; file - if there is no frame with a minibuffer open now, create
188 ;; one to display messages while loading the init file.
189 (defun frame-initialize ()
190 "Create an initial frame if necessary."
191 ;; Are we actually running under a window system at all?
192 (if (and window-system (not noninteractive) (not (eq window-system 'pc)))
193 (progn
194 ;; Turn on special-display processing only if there's a window system.
195 (setq special-display-function 'special-display-popup-frame)
196
197 ;; If there is no frame with a minibuffer besides the terminal
198 ;; frame, then we need to create the opening frame. Make sure
199 ;; it has a minibuffer, but let initial-frame-alist omit the
200 ;; minibuffer spec.
201 (or (delq terminal-frame (minibuffer-frame-list))
202 (progn
203 (setq frame-initial-frame-alist
204 (append initial-frame-alist default-frame-alist nil))
205 (or (assq 'horizontal-scroll-bars frame-initial-frame-alist)
206 (setq frame-initial-frame-alist
207 (cons '(horizontal-scroll-bars . t)
208 frame-initial-frame-alist)))
209 (setq default-minibuffer-frame
210 (setq frame-initial-frame
211 (make-frame frame-initial-frame-alist)))
212 ;; Delete any specifications for window geometry parameters
213 ;; so that we won't reapply them in frame-notice-user-settings.
214 ;; It would be wrong to reapply them then,
215 ;; because that would override explicit user resizing.
216 (setq initial-frame-alist
217 (frame-remove-geometry-params initial-frame-alist))))
218 ;; At this point, we know that we have a frame open, so we
219 ;; can delete the terminal frame.
220 (delete-frame terminal-frame)
221 (setq terminal-frame nil))
222
223 ;; No, we're not running a window system. Use make-terminal-frame if
224 ;; we support that feature, otherwise arrange to cause errors.
225 (or (eq window-system 'pc)
226 (setq frame-creation-function
227 (if (fboundp 'tty-create-frame-with-faces)
228 'tty-create-frame-with-faces
229 (lambda (parameters)
230 (error
231 "Can't create multiple frames without a window system")))))))
232
233 (defvar frame-notice-user-settings t
234 "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
235
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.
239 (defun frame-notice-user-settings ()
240 "Act on user's init file settings of frame parameters.
241 React to settings of `default-frame-alist', `initial-frame-alist' there."
242 ;; Make menu-bar-mode and default-frame-alist consistent.
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)))))
250
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
254 ;; what we want.
255 (when (and (boundp 'tool-bar-mode)
256 (not noninteractive))
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)))))
263
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
271 (when (and frame-notice-user-settings
272 (null frame-initial-frame))
273 ;; This case happens when we don't have a window system, and
274 ;; also for MS-DOS frames.
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
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))))))
302
303 ;; If the initial frame is still around, apply initial-frame-alist
304 ;; and default-frame-alist to it.
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.
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))))
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))))
317 (let* ((char-height (frame-char-height frame-initial-frame))
318 (image-height tool-bar-images-pixel-height)
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))
330 (lines (/ (+ image-height
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))))
337 (initial-top (cdr (assq 'top
338 frame-initial-geometry-arguments)))
339 (top (frame-parameter frame-initial-frame 'top)))
340 (when (and (consp initial-top) (eq '- (car initial-top)))
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))))
357 (modify-frame-parameters frame-initial-frame newparms)
358 (tool-bar-mode -1)))))
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.
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))
385
386 ;; Get rid of `name' unless it was specified explicitly before.
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 (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 (lambda (frame)
440 (eq (cdr (assq 'minibuffer
441 (frame-parameters frame)))
442 'only)))
443 (minibuffer-frame-list))))
444 (new-minibuffer (minibuffer-window new-surrogate)))
445
446 (if (eq default-minibuffer-frame frame-initial-frame)
447 (setq default-minibuffer-frame new-surrogate))
448
449 ;; Wean the frames using frame-initial-frame as
450 ;; their minibuffer frame.
451 (dolist (frame users-of-initial)
452 (modify-frame-parameters
453 frame (list (cons 'minibuffer new-minibuffer)))))))
454
455 ;; Redirect events enqueued at this frame to the new frame.
456 ;; Is this a good idea?
457 (redirect-frame-focus frame-initial-frame new)
458
459 ;; Finally, get rid of the old frame.
460 (delete-frame frame-initial-frame t))
461
462 ;; Otherwise, we don't need all that rigamarole; just apply
463 ;; the new parameters.
464 (let (newparms allparms tail)
465 (setq allparms (append initial-frame-alist
466 default-frame-alist nil))
467 (if (assq 'height frame-initial-geometry-arguments)
468 (setq allparms (assq-delete-all 'height allparms)))
469 (if (assq 'width frame-initial-geometry-arguments)
470 (setq allparms (assq-delete-all 'width allparms)))
471 (if (assq 'left frame-initial-geometry-arguments)
472 (setq allparms (assq-delete-all 'left allparms)))
473 (if (assq 'top frame-initial-geometry-arguments)
474 (setq allparms (assq-delete-all 'top allparms)))
475 (setq tail allparms)
476 ;; Find just the parms that have changed since we first
477 ;; made this frame. Those are the ones actually set by
478 ;; the init file. For those parms whose values we already knew
479 ;; (such as those spec'd by command line options)
480 ;; it is undesirable to specify the parm again
481 ;; once the user has seen the frame and been able to alter it
482 ;; manually.
483 (while tail
484 (let (newval oldval)
485 (setq oldval (assq (car (car tail))
486 frame-initial-frame-alist))
487 (setq newval (cdr (assq (car (car tail)) allparms)))
488 (or (and oldval (eq (cdr oldval) newval))
489 (setq newparms
490 (cons (cons (car (car tail)) newval) newparms))))
491 (setq tail (cdr tail)))
492 (setq newparms (nreverse newparms))
493 (modify-frame-parameters frame-initial-frame
494 newparms)
495 ;; If we changed the background color,
496 ;; we need to update the background-mode parameter
497 ;; and maybe some faces too.
498 (when (assq 'background-color newparms)
499 (unless (assq 'background-mode newparms)
500 (frame-set-background-mode frame-initial-frame))
501 (face-set-after-frame-default frame-initial-frame)))))
502
503 ;; Restore the original buffer.
504 (set-buffer old-buffer)
505
506 ;; Make sure the initial frame can be GC'd if it is ever deleted.
507 ;; Make sure frame-notice-user-settings does nothing if called twice.
508 (setq frame-notice-user-settings nil)
509 (setq frame-initial-frame nil)))
510
511 (defun make-initial-minibuffer-frame (display)
512 (let ((parms (append minibuffer-frame-alist '((minibuffer . only)))))
513 (if display
514 (make-frame-on-display display parms)
515 (make-frame parms))))
516
517 ;;;; Creation of additional frames, and other frame miscellanea
518
519 (defun modify-all-frames-parameters (alist)
520 "Modify all current and future frames' parameters according to ALIST.
521 This changes `default-frame-alist' and possibly `initial-frame-alist'.
522 See help of `modify-frame-parameters' for more information."
523 (let (element) ;; temp
524 (dolist (frame (frame-list))
525 (modify-frame-parameters frame alist))
526
527 (dolist (pair alist) ;; conses to add/replace
528 ;; initial-frame-alist needs setting only when
529 ;; frame-notice-user-settings is true
530 (and frame-notice-user-settings
531 (setq element (assoc (car pair) initial-frame-alist))
532 (setq initial-frame-alist (delq element initial-frame-alist)))
533 (and (setq element (assoc (car pair) default-frame-alist))
534 (setq default-frame-alist (delq element default-frame-alist)))))
535 (and frame-notice-user-settings
536 (setq initial-frame-alist (append initial-frame-alist alist)))
537 (setq default-frame-alist (append default-frame-alist alist)))
538
539 (defun get-other-frame ()
540 "Return some frame other than the current frame.
541 Create one if necessary. Note that the minibuffer frame, if separate,
542 is not considered (see `next-frame')."
543 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
544 (make-frame)
545 (next-frame (selected-frame)))))
546 s))
547
548 (defun next-multiframe-window ()
549 "Select the next window, regardless of which frame it is on."
550 (interactive)
551 (select-window (next-window (selected-window)
552 (> (minibuffer-depth) 0)
553 0))
554 (select-frame-set-input-focus (selected-frame)))
555
556 (defun previous-multiframe-window ()
557 "Select the previous window, regardless of which frame it is on."
558 (interactive)
559 (select-window (previous-window (selected-window)
560 (> (minibuffer-depth) 0)
561 0))
562 (select-frame-set-input-focus (selected-frame)))
563
564 (defun make-frame-on-display (display &optional parameters)
565 "Make a frame on display DISPLAY.
566 The optional second argument PARAMETERS specifies additional frame parameters."
567 (interactive "sMake frame on display: ")
568 (or (string-match "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display)
569 (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
570 (make-frame (cons (cons 'display display) parameters)))
571
572 (defun close-display-connection (display)
573 "Close the connection to a display, deleting all its associated frames.
574 For DISPLAY, specify either a frame or a display name (a string).
575 If DISPLAY is nil, that stands for the selected frame's display."
576 (interactive
577 (list
578 (let* ((default (frame-parameter nil 'display))
579 (display (completing-read
580 (format "Close display (default %s): " default)
581 (delete-dups
582 (mapcar (lambda (frame)
583 (frame-parameter frame 'display))
584 (frame-list)))
585 nil t nil nil
586 default)))
587 (if (zerop (length display)) default display))))
588 (let ((frames (delq nil
589 (mapcar (lambda (frame)
590 (if (equal display
591 (frame-parameter frame 'display))
592 frame))
593 (frame-list)))))
594 (if (and (consp frames)
595 (not (y-or-n-p (if (cdr frames)
596 (format "Delete %s frames? " (length frames))
597 (format "Delete %s ? " (car frames))))))
598 (error "Abort!")
599 (mapc 'delete-frame frames)
600 (x-close-connection display))))
601
602 (defun make-frame-command ()
603 "Make a new frame, and select it if the terminal displays only one frame."
604 (interactive)
605 (if (and window-system (not (eq window-system 'pc)))
606 (make-frame)
607 (select-frame (make-frame))))
608
609 (defvar before-make-frame-hook nil
610 "Functions to run before a frame is created.")
611
612 (defvar after-make-frame-functions nil
613 "Functions to run after a frame is created.
614 The functions are run with one arg, the newly created frame.")
615
616 (defvar after-setting-font-hook nil
617 "Functions to run after a frame's font has been changed.")
618
619 ;; Alias, kept temporarily.
620 (define-obsolete-function-alias 'new-frame 'make-frame "22.1")
621
622 (defun make-frame (&optional parameters)
623 "Return a newly created frame displaying the current buffer.
624 Optional argument PARAMETERS is an alist of parameters for the new frame.
625 Each element of PARAMETERS should have the form (NAME . VALUE), for example:
626
627 (name . STRING) The frame should be named STRING.
628
629 (width . NUMBER) The frame should be NUMBER characters in width.
630 (height . NUMBER) The frame should be NUMBER text lines high.
631
632 You cannot specify either `width' or `height', you must use neither or both.
633
634 (minibuffer . t) The frame should have a minibuffer.
635 (minibuffer . nil) The frame should have no minibuffer.
636 (minibuffer . only) The frame should contain only a minibuffer.
637 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
638
639 Before the frame is created (via `frame-creation-function'), functions on the
640 hook `before-make-frame-hook' are run. After the frame is created, functions
641 on `after-make-frame-functions' are run with one arg, the newly created frame.
642
643 This function itself does not make the new frame the selected frame.
644 The previously selected frame remains selected. However, the
645 window system may select the new frame for its own reasons, for
646 instance if the frame appears under the mouse pointer and your
647 setup is for focus to follow the pointer."
648 (interactive)
649 (run-hooks 'before-make-frame-hook)
650 (let ((frame (funcall frame-creation-function parameters)))
651 (run-hook-with-args 'after-make-frame-functions frame)
652 frame))
653
654 (defun filtered-frame-list (predicate)
655 "Return a list of all live frames which satisfy PREDICATE."
656 (let* ((frames (frame-list))
657 (list frames))
658 (while (consp frames)
659 (unless (funcall predicate (car frames))
660 (setcar frames nil))
661 (setq frames (cdr frames)))
662 (delq nil list)))
663
664 (defun minibuffer-frame-list ()
665 "Return a list of all frames with their own minibuffers."
666 (filtered-frame-list
667 (lambda (frame)
668 (eq frame (window-frame (minibuffer-window frame))))))
669
670 (defun frames-on-display-list (&optional display)
671 "Return a list of all frames on DISPLAY.
672 DISPLAY is a name of a display, a string of the form HOST:SERVER.SCREEN.
673 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
674 (let* ((display (or display (frame-parameter nil 'display)))
675 (func #'(lambda (frame)
676 (equal (frame-parameter frame 'display) display))))
677 (filtered-frame-list func)))
678
679 (defun framep-on-display (&optional display)
680 "Return the type of frames on DISPLAY.
681 DISPLAY may be a display name or a frame. If it is a frame, its type is
682 returned.
683 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
684 All frames on a given display are of the same type."
685 (or (framep display)
686 (framep (car (frames-on-display-list display)))))
687
688 (defun frame-remove-geometry-params (param-list)
689 "Return the parameter list PARAM-LIST, but with geometry specs removed.
690 This deletes all bindings in PARAM-LIST for `top', `left', `width',
691 `height', `user-size' and `user-position' parameters.
692 Emacs uses this to avoid overriding explicit moves and resizings from
693 the user during startup."
694 (setq param-list (cons nil param-list))
695 (let ((tail param-list))
696 (while (consp (cdr tail))
697 (if (and (consp (car (cdr tail)))
698 (memq (car (car (cdr tail)))
699 '(height width top left user-position user-size)))
700 (progn
701 (setq frame-initial-geometry-arguments
702 (cons (car (cdr tail)) frame-initial-geometry-arguments))
703 (setcdr tail (cdr (cdr tail))))
704 (setq tail (cdr tail)))))
705 (setq frame-initial-geometry-arguments
706 (nreverse frame-initial-geometry-arguments))
707 (cdr param-list))
708
709 (defcustom focus-follows-mouse (not (eq window-system 'mac))
710 "*Non-nil if window system changes focus when you move the mouse.
711 You should set this variable to tell Emacs how your window manager
712 handles focus, since there is no way in general for Emacs to find out
713 automatically.
714
715 This variable does not have any effect on MS-Windows."
716 :type 'boolean
717 :group 'frames
718 :version "20.3")
719
720 (defun select-frame-set-input-focus (frame)
721 "Select FRAME, raise it, and set input focus, if possible."
722 (select-frame frame)
723 (raise-frame frame)
724 ;; Ensure, if possible, that frame gets input focus.
725 (cond ((memq window-system '(x mac))
726 (x-focus-frame frame))
727 ((eq window-system 'w32)
728 (w32-focus-frame frame)))
729 (cond (focus-follows-mouse
730 (set-mouse-position (selected-frame) (1- (frame-width)) 0))))
731
732 (defun other-frame (arg)
733 "Select the ARGth different visible frame on current display, and raise it.
734 All frames are arranged in a cyclic order.
735 This command selects the frame ARG steps away in that order.
736 A negative ARG moves in the opposite order.
737
738 To make this command work properly, you must tell Emacs
739 how the system (or the window manager) generally handles
740 focus-switching between windows. If moving the mouse onto a window
741 selects it (gives it focus), set `focus-follows-mouse' to t.
742 Otherwise, that variable should be nil."
743 (interactive "p")
744 (let ((frame (selected-frame)))
745 (while (> arg 0)
746 (setq frame (next-frame frame))
747 (while (not (eq (frame-visible-p frame) t))
748 (setq frame (next-frame frame)))
749 (setq arg (1- arg)))
750 (while (< arg 0)
751 (setq frame (previous-frame frame))
752 (while (not (eq (frame-visible-p frame) t))
753 (setq frame (previous-frame frame)))
754 (setq arg (1+ arg)))
755 (select-frame-set-input-focus frame)))
756
757 (defun iconify-or-deiconify-frame ()
758 "Iconify the selected frame, or deiconify if it's currently an icon."
759 (interactive)
760 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
761 (iconify-frame)
762 (make-frame-visible)))
763
764 (defun make-frame-names-alist ()
765 (let* ((current-frame (selected-frame))
766 (falist
767 (cons
768 (cons (frame-parameter current-frame 'name) current-frame) nil))
769 (frame (next-frame nil t)))
770 (while (not (eq frame current-frame))
771 (progn
772 (setq falist (cons (cons (frame-parameter frame 'name) frame) falist))
773 (setq frame (next-frame frame t))))
774 falist))
775
776 (defvar frame-name-history nil)
777 (defun select-frame-by-name (name)
778 "Select the frame on the current terminal whose name is NAME and raise it.
779 If there is no frame by that name, signal an error."
780 (interactive
781 (let* ((frame-names-alist (make-frame-names-alist))
782 (default (car (car frame-names-alist)))
783 (input (completing-read
784 (format "Select Frame (default %s): " default)
785 frame-names-alist nil t nil 'frame-name-history)))
786 (if (= (length input) 0)
787 (list default)
788 (list input))))
789 (let* ((frame-names-alist (make-frame-names-alist))
790 (frame (cdr (assoc name frame-names-alist))))
791 (or frame
792 (error "There is no frame named `%s'" name))
793 (make-frame-visible frame)
794 (raise-frame frame)
795 (select-frame frame)
796 ;; Ensure, if possible, that frame gets input focus.
797 (cond ((memq window-system '(x mac))
798 (x-focus-frame frame))
799 ((eq window-system 'w32)
800 (w32-focus-frame frame)))
801 (when focus-follows-mouse
802 (set-mouse-position frame (1- (frame-width frame)) 0))))
803 \f
804 ;;;; Frame configurations
805
806 (defun current-frame-configuration ()
807 "Return a list describing the positions and states of all frames.
808 Its car is `frame-configuration'.
809 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
810 where
811 FRAME is a frame object,
812 ALIST is an association list specifying some of FRAME's parameters, and
813 WINDOW-CONFIG is a window configuration object for FRAME."
814 (cons 'frame-configuration
815 (mapcar (lambda (frame)
816 (list frame
817 (frame-parameters frame)
818 (current-window-configuration frame)))
819 (frame-list))))
820
821 (defun set-frame-configuration (configuration &optional nodelete)
822 "Restore the frames to the state described by CONFIGURATION.
823 Each frame listed in CONFIGURATION has its position, size, window
824 configuration, and other parameters set as specified in CONFIGURATION.
825 However, this function does not restore deleted frames.
826
827 Ordinarily, this function deletes all existing frames not
828 listed in CONFIGURATION. But if optional second argument NODELETE
829 is given and non-nil, the unwanted frames are iconified instead."
830 (or (frame-configuration-p configuration)
831 (signal 'wrong-type-argument
832 (list 'frame-configuration-p configuration)))
833 (let ((config-alist (cdr configuration))
834 frames-to-delete)
835 (dolist (frame (frame-list))
836 (let ((parameters (assq frame config-alist)))
837 (if parameters
838 (progn
839 (modify-frame-parameters
840 frame
841 ;; Since we can't set a frame's minibuffer status,
842 ;; we might as well omit the parameter altogether.
843 (let* ((parms (nth 1 parameters))
844 (mini (assq 'minibuffer parms)))
845 (if mini (setq parms (delq mini parms)))
846 parms))
847 (set-window-configuration (nth 2 parameters)))
848 (setq frames-to-delete (cons frame frames-to-delete)))))
849 (mapc (if nodelete
850 ;; Note: making frames invisible here was tried
851 ;; but led to some strange behavior--each time the frame
852 ;; was made visible again, the window manager asked afresh
853 ;; for where to put it.
854 'iconify-frame
855 'delete-frame)
856 frames-to-delete)))
857 \f
858 ;;;; Convenience functions for accessing and interactively changing
859 ;;;; frame parameters.
860
861 (defun frame-height (&optional frame)
862 "Return number of lines available for display on FRAME.
863 If FRAME is omitted, describe the currently selected frame."
864 (cdr (assq 'height (frame-parameters frame))))
865
866 (defun frame-width (&optional frame)
867 "Return number of columns available for display on FRAME.
868 If FRAME is omitted, describe the currently selected frame."
869 (cdr (assq 'width (frame-parameters frame))))
870
871 (defalias 'set-default-font 'set-frame-font)
872 (defun set-frame-font (font-name &optional keep-size)
873 "Set the font of the selected frame to FONT-NAME.
874 When called interactively, prompt for the name of the font to use.
875 To get the frame's current default font, use `frame-parameters'.
876
877 The default behavior is to keep the numbers of lines and columns in
878 the frame, thus may change its pixel size. If optional KEEP-SIZE is
879 non-nil (interactively, prefix argument) the current frame size (in
880 pixels) is kept by adjusting the numbers of the lines and columns."
881 (interactive
882 (let* ((completion-ignore-case t)
883 (font (completing-read "Font name: "
884 ;; x-list-fonts will fail with an error
885 ;; if this frame doesn't support fonts.
886 (x-list-fonts "*" nil (selected-frame))
887 nil nil nil nil
888 (frame-parameter nil 'font))))
889 (list font current-prefix-arg)))
890 (let (fht fwd)
891 (if keep-size
892 (setq fht (* (frame-parameter nil 'height) (frame-char-height))
893 fwd (* (frame-parameter nil 'width) (frame-char-width))))
894 (modify-frame-parameters (selected-frame)
895 (list (cons 'font font-name)))
896 (if keep-size
897 (modify-frame-parameters
898 (selected-frame)
899 (list (cons 'height (round fht (frame-char-height)))
900 (cons 'width (round fwd (frame-char-width)))))))
901 (run-hooks 'after-setting-font-hook 'after-setting-font-hooks))
902
903 (defun set-frame-parameter (frame parameter value)
904 "Set frame parameter PARAMETER to VALUE on FRAME.
905 If FRAME is nil, it defaults to the selected frame.
906 See `modify-frame-parameters'."
907 (modify-frame-parameters frame (list (cons parameter value))))
908
909 (defun set-background-color (color-name)
910 "Set the background color of the selected frame to COLOR-NAME.
911 When called interactively, prompt for the name of the color to use.
912 To get the frame's current background color, use `frame-parameters'."
913 (interactive (list (facemenu-read-color "Background color: ")))
914 (modify-frame-parameters (selected-frame)
915 (list (cons 'background-color color-name)))
916 (or window-system
917 (face-set-after-frame-default (selected-frame))))
918
919 (defun set-foreground-color (color-name)
920 "Set the foreground color of the selected frame to COLOR-NAME.
921 When called interactively, prompt for the name of the color to use.
922 To get the frame's current foreground color, use `frame-parameters'."
923 (interactive (list (facemenu-read-color "Foreground color: ")))
924 (modify-frame-parameters (selected-frame)
925 (list (cons 'foreground-color color-name)))
926 (or window-system
927 (face-set-after-frame-default (selected-frame))))
928
929 (defun set-cursor-color (color-name)
930 "Set the text cursor color of the selected frame to COLOR-NAME.
931 When called interactively, prompt for the name of the color to use.
932 To get the frame's current cursor color, use `frame-parameters'."
933 (interactive (list (facemenu-read-color "Cursor color: ")))
934 (modify-frame-parameters (selected-frame)
935 (list (cons 'cursor-color color-name))))
936
937 (defun set-mouse-color (color-name)
938 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
939 When called interactively, prompt for the name of the color to use.
940 To get the frame's current mouse color, use `frame-parameters'."
941 (interactive (list (facemenu-read-color "Mouse color: ")))
942 (modify-frame-parameters (selected-frame)
943 (list (cons 'mouse-color
944 (or color-name
945 (cdr (assq 'mouse-color
946 (frame-parameters))))))))
947
948 (defun set-border-color (color-name)
949 "Set the color of the border of the selected frame to COLOR-NAME.
950 When called interactively, prompt for the name of the color to use.
951 To get the frame's current border color, use `frame-parameters'."
952 (interactive (list (facemenu-read-color "Border color: ")))
953 (modify-frame-parameters (selected-frame)
954 (list (cons 'border-color color-name))))
955
956 (defun auto-raise-mode (arg)
957 "Toggle whether or not the selected frame should auto-raise.
958 With arg, turn auto-raise mode on if and only if arg is positive.
959 Note that this controls Emacs's own auto-raise feature.
960 Some window managers allow you to enable auto-raise for certain windows.
961 You can use that for Emacs windows if you wish, but if you do,
962 that is beyond the control of Emacs and this command has no effect on it."
963 (interactive "P")
964 (if (null arg)
965 (setq arg
966 (if (cdr (assq 'auto-raise (frame-parameters (selected-frame))))
967 -1 1)))
968 (if (> arg 0)
969 (raise-frame (selected-frame)))
970 (modify-frame-parameters (selected-frame)
971 (list (cons 'auto-raise (> arg 0)))))
972
973 (defun auto-lower-mode (arg)
974 "Toggle whether or not the selected frame should auto-lower.
975 With arg, turn auto-lower mode on if and only if arg is positive.
976 Note that this controls Emacs's own auto-lower feature.
977 Some window managers allow you to enable auto-lower for certain windows.
978 You can use that for Emacs windows if you wish, but if you do,
979 that is beyond the control of Emacs and this command has no effect on it."
980 (interactive "P")
981 (if (null arg)
982 (setq arg
983 (if (cdr (assq 'auto-lower (frame-parameters (selected-frame))))
984 -1 1)))
985 (modify-frame-parameters (selected-frame)
986 (list (cons 'auto-lower (> arg 0)))))
987 (defun set-frame-name (name)
988 "Set the name of the selected frame to NAME.
989 When called interactively, prompt for the name of the frame.
990 The frame name is displayed on the modeline if the terminal displays only
991 one frame, otherwise the name is displayed on the frame's caption bar."
992 (interactive "sFrame name: ")
993 (modify-frame-parameters (selected-frame)
994 (list (cons 'name name))))
995
996 (defun frame-current-scroll-bars (&optional frame)
997 "Return the current scroll-bar settings in frame FRAME.
998 Value is a cons (VERTICAL . HORIZ0NTAL) where VERTICAL specifies the
999 current location of the vertical scroll-bars (left, right, or nil),
1000 and HORIZONTAL specifies the current location of the horizontal scroll
1001 bars (top, bottom, or nil)."
1002 (let ((vert (frame-parameter frame 'vertical-scroll-bars))
1003 (hor nil))
1004 (unless (memq vert '(left right nil))
1005 (setq vert default-frame-scroll-bars))
1006 (cons vert hor)))
1007 \f
1008 ;;;; Frame/display capabilities.
1009 (defun display-mouse-p (&optional display)
1010 "Return non-nil if DISPLAY has a mouse available.
1011 DISPLAY can be a display name, a frame, or nil (meaning the selected
1012 frame's display)."
1013 (let ((frame-type (framep-on-display display)))
1014 (cond
1015 ((eq frame-type 'pc)
1016 (msdos-mouse-p))
1017 ((eq system-type 'windows-nt)
1018 (with-no-warnings
1019 (> w32-num-mouse-buttons 0)))
1020 ((memq frame-type '(x mac))
1021 t) ;; We assume X and Mac *always* have a pointing device
1022 (t
1023 (or (and (featurep 'xt-mouse)
1024 xterm-mouse-mode)
1025 ;; t-mouse is distributed with the GPM package. It doesn't have
1026 ;; a toggle.
1027 (featurep 't-mouse))))))
1028
1029 (defun display-popup-menus-p (&optional display)
1030 "Return non-nil if popup menus are supported on DISPLAY.
1031 DISPLAY can be a display name, a frame, or nil (meaning the selected
1032 frame's display).
1033 Support for popup menus requires that the mouse be available."
1034 (and
1035 (let ((frame-type (framep-on-display display)))
1036 (memq frame-type '(x w32 pc mac)))
1037 (display-mouse-p display)))
1038
1039 (defun display-graphic-p (&optional display)
1040 "Return non-nil if DISPLAY is a graphic display.
1041 Graphical displays are those which are capable of displaying several
1042 frames and several different fonts at once. This is true for displays
1043 that use a window system such as X, and false for text-only terminals.
1044 DISPLAY can be a display name, a frame, or nil (meaning the selected
1045 frame's display)."
1046 (not (null (memq (framep-on-display display) '(x w32 mac)))))
1047
1048 (defun display-images-p (&optional display)
1049 "Return non-nil if DISPLAY can display images.
1050
1051 DISPLAY can be a display name, a frame, or nil (meaning the selected
1052 frame's display)."
1053 (and (display-graphic-p display)
1054 (fboundp 'image-mask-p)
1055 (fboundp 'image-size)))
1056
1057 (defalias 'display-multi-frame-p 'display-graphic-p)
1058 (defalias 'display-multi-font-p 'display-graphic-p)
1059
1060 (defun display-selections-p (&optional display)
1061 "Return non-nil if DISPLAY supports selections.
1062 A selection is a way to transfer text or other data between programs
1063 via special system buffers called `selection' or `cut buffer' or
1064 `clipboard'.
1065 DISPLAY can be a display name, a frame, or nil (meaning the selected
1066 frame's display)."
1067 (let ((frame-type (framep-on-display display)))
1068 (cond
1069 ((eq frame-type 'pc)
1070 ;; MS-DOG frames support selections when Emacs runs inside
1071 ;; the Windows' DOS Box.
1072 (with-no-warnings
1073 (not (null dos-windows-version))))
1074 ((memq frame-type '(x w32 mac))
1075 t) ;; FIXME?
1076 (t
1077 nil))))
1078
1079 (defun display-screens (&optional display)
1080 "Return the number of screens associated with DISPLAY."
1081 (let ((frame-type (framep-on-display display)))
1082 (cond
1083 ((memq frame-type '(x w32 mac))
1084 (x-display-screens display))
1085 (t
1086 1))))
1087
1088 (defun display-pixel-height (&optional display)
1089 "Return the height of DISPLAY's screen in pixels.
1090 For character terminals, each character counts as a single pixel."
1091 (let ((frame-type (framep-on-display display)))
1092 (cond
1093 ((memq frame-type '(x w32 mac))
1094 (x-display-pixel-height display))
1095 (t
1096 (frame-height (if (framep display) display (selected-frame)))))))
1097
1098 (defun display-pixel-width (&optional display)
1099 "Return the width of DISPLAY's screen in pixels.
1100 For character terminals, each character counts as a single pixel."
1101 (let ((frame-type (framep-on-display display)))
1102 (cond
1103 ((memq frame-type '(x w32 mac))
1104 (x-display-pixel-width display))
1105 (t
1106 (frame-width (if (framep display) display (selected-frame)))))))
1107
1108 (defcustom display-mm-dimensions-alist nil
1109 "Alist for specifying screen dimensions in millimeters.
1110 The dimensions will be used for `display-mm-height' and
1111 `display-mm-width' if defined for the respective display.
1112
1113 Each element of the alist has the form (display . (width . height)),
1114 e.g. (\":0.0\" . (287 . 215)).
1115
1116 If `display' equals t, it specifies dimensions for all graphical
1117 displays not explicitely specified."
1118 :version "22.1"
1119 :type '(alist :key-type (choice (string :tag "Display name")
1120 (const :tag "Default" t))
1121 :value-type (cons :tag "Dimensions"
1122 (integer :tag "Width")
1123 (integer :tag "Height")))
1124 :group 'frames)
1125
1126 (defun display-mm-height (&optional display)
1127 "Return the height of DISPLAY's screen in millimeters.
1128 System values can be overriden by `display-mm-dimensions-alist'.
1129 If the information is unavailable, value is nil."
1130 (and (memq (framep-on-display display) '(x w32 mac))
1131 (or (cddr (assoc (or display (frame-parameter nil 'display))
1132 display-mm-dimensions-alist))
1133 (cddr (assoc t display-mm-dimensions-alist))
1134 (x-display-mm-height display))))
1135
1136 (defun display-mm-width (&optional display)
1137 "Return the width of DISPLAY's screen in millimeters.
1138 System values can be overriden by `display-mm-dimensions-alist'.
1139 If the information is unavailable, value is nil."
1140 (and (memq (framep-on-display display) '(x w32 mac))
1141 (or (cadr (assoc (or display (frame-parameter nil 'display))
1142 display-mm-dimensions-alist))
1143 (cadr (assoc t display-mm-dimensions-alist))
1144 (x-display-mm-width display))))
1145
1146 (defun display-backing-store (&optional display)
1147 "Return the backing store capability of DISPLAY's screen.
1148 The value may be `always', `when-mapped', `not-useful', or nil if
1149 the question is inapplicable to a certain kind of display."
1150 (let ((frame-type (framep-on-display display)))
1151 (cond
1152 ((memq frame-type '(x w32 mac))
1153 (x-display-backing-store display))
1154 (t
1155 'not-useful))))
1156
1157 (defun display-save-under (&optional display)
1158 "Return non-nil if DISPLAY's screen supports the SaveUnder feature."
1159 (let ((frame-type (framep-on-display display)))
1160 (cond
1161 ((memq frame-type '(x w32 mac))
1162 (x-display-save-under display))
1163 (t
1164 'not-useful))))
1165
1166 (defun display-planes (&optional display)
1167 "Return the number of planes supported by DISPLAY."
1168 (let ((frame-type (framep-on-display display)))
1169 (cond
1170 ((memq frame-type '(x w32 mac))
1171 (x-display-planes display))
1172 ((eq frame-type 'pc)
1173 4)
1174 (t
1175 (truncate (log (length (tty-color-alist)) 2))))))
1176
1177 (defun display-color-cells (&optional display)
1178 "Return the number of color cells supported by DISPLAY."
1179 (let ((frame-type (framep-on-display display)))
1180 (cond
1181 ((memq frame-type '(x w32 mac))
1182 (x-display-color-cells display))
1183 ((eq frame-type 'pc)
1184 16)
1185 (t
1186 (tty-display-color-cells)))))
1187
1188 (defun display-visual-class (&optional display)
1189 "Returns the visual class of DISPLAY.
1190 The value is one of the symbols `static-gray', `gray-scale',
1191 `static-color', `pseudo-color', `true-color', or `direct-color'."
1192 (let ((frame-type (framep-on-display display)))
1193 (cond
1194 ((memq frame-type '(x w32 mac))
1195 (x-display-visual-class display))
1196 ((and (memq frame-type '(pc t))
1197 (tty-display-color-p display))
1198 'static-color)
1199 (t
1200 'static-gray))))
1201
1202 \f
1203 ;;;; Aliases for backward compatibility with Emacs 18.
1204 (define-obsolete-function-alias 'screen-height 'frame-height) ;before 19.15
1205 (define-obsolete-function-alias 'screen-width 'frame-width) ;before 19.15
1206
1207 (defun set-screen-width (cols &optional pretend)
1208 "Change the size of the screen to COLS columns.
1209 Optional second arg non-nil means that redisplay should use COLS columns
1210 but that the idea of the actual width of the frame should not be changed.
1211 This function is provided only for compatibility with Emacs 18."
1212 (set-frame-width (selected-frame) cols pretend))
1213
1214 (defun set-screen-height (lines &optional pretend)
1215 "Change the height of the screen to LINES lines.
1216 Optional second arg non-nil means that redisplay should use LINES lines
1217 but that the idea of the actual height of the screen should not be changed.
1218 This function is provided only for compatibility with Emacs 18."
1219 (set-frame-height (selected-frame) lines pretend))
1220
1221 (defun delete-other-frames (&optional frame)
1222 "Delete all frames except FRAME.
1223 If FRAME uses another frame's minibuffer, the minibuffer frame is
1224 left untouched. FRAME nil or omitted means use the selected frame."
1225 (interactive)
1226 (unless frame
1227 (setq frame (selected-frame)))
1228 (let* ((mini-frame (window-frame (minibuffer-window frame)))
1229 (frames (delq mini-frame (delq frame (frame-list)))))
1230 ;; Delete mon-minibuffer-only frames first, because `delete-frame'
1231 ;; signals an error when trying to delete a mini-frame that's
1232 ;; still in use by another frame.
1233 (dolist (frame frames)
1234 (unless (eq (frame-parameter frame 'minibuffer) 'only)
1235 (delete-frame frame)))
1236 ;; Delete minibuffer-only frames.
1237 (dolist (frame frames)
1238 (when (eq (frame-parameter frame 'minibuffer) 'only)
1239 (delete-frame frame)))))
1240
1241 (make-obsolete 'set-screen-width 'set-frame-width) ;before 19.15
1242 (make-obsolete 'set-screen-height 'set-frame-height) ;before 19.15
1243
1244 ;; miscellaneous obsolescence declarations
1245 (define-obsolete-variable-alias 'delete-frame-hook
1246 'delete-frame-functions "22.1")
1247
1248 \f
1249 ;; Highlighting trailing whitespace.
1250
1251 (make-variable-buffer-local 'show-trailing-whitespace)
1252
1253 (defcustom show-trailing-whitespace nil
1254 "*Non-nil means highlight trailing whitespace.
1255 This is done in the face `trailing-whitespace'."
1256 :type 'boolean
1257 :group 'whitespace-faces)
1258
1259
1260 \f
1261 ;; Scrolling
1262
1263 (defgroup scrolling nil
1264 "Scrolling windows."
1265 :version "21.1"
1266 :group 'frames)
1267
1268 (defcustom auto-hscroll-mode t
1269 "*Allow or disallow automatic scrolling windows horizontally.
1270 If non-nil, windows are automatically scrolled horizontally to make
1271 point visible."
1272 :version "21.1"
1273 :type 'boolean
1274 :group 'scrolling)
1275 (defvaralias 'automatic-hscrolling 'auto-hscroll-mode)
1276
1277 \f
1278 ;; Blinking cursor
1279
1280 (defgroup cursor nil
1281 "Displaying text cursors."
1282 :version "21.1"
1283 :group 'frames)
1284
1285 (defcustom blink-cursor-delay 0.5
1286 "*Seconds of idle time after which cursor starts to blink."
1287 :type 'number
1288 :group 'cursor)
1289
1290 (defcustom blink-cursor-interval 0.5
1291 "*Length of cursor blink interval in seconds."
1292 :type 'number
1293 :group 'cursor)
1294
1295 (defvar blink-cursor-idle-timer nil
1296 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
1297 The function `blink-cursor-start' is called when the timer fires.")
1298
1299 (defvar blink-cursor-timer nil
1300 "Timer started from `blink-cursor-start'.
1301 This timer calls `blink-cursor-timer-function' every
1302 `blink-cursor-interval' seconds.")
1303
1304 (defun blink-cursor-start ()
1305 "Timer function called from the timer `blink-cursor-idle-timer'.
1306 This starts the timer `blink-cursor-timer', which makes the cursor blink
1307 if appropriate. It also arranges to cancel that timer when the next
1308 command starts, by installing a pre-command hook."
1309 (when (null blink-cursor-timer)
1310 ;; Set up the timer first, so that if this signals an error,
1311 ;; blink-cursor-end is not added to pre-command-hook.
1312 (setq blink-cursor-timer
1313 (run-with-timer blink-cursor-interval blink-cursor-interval
1314 'blink-cursor-timer-function))
1315 (add-hook 'pre-command-hook 'blink-cursor-end)
1316 (internal-show-cursor nil nil)))
1317
1318 (defun blink-cursor-timer-function ()
1319 "Timer function of timer `blink-cursor-timer'."
1320 (internal-show-cursor nil (not (internal-show-cursor-p))))
1321
1322 (defun blink-cursor-end ()
1323 "Stop cursor blinking.
1324 This is installed as a pre-command hook by `blink-cursor-start'.
1325 When run, it cancels the timer `blink-cursor-timer' and removes
1326 itself as a pre-command hook."
1327 (remove-hook 'pre-command-hook 'blink-cursor-end)
1328 (internal-show-cursor nil t)
1329 (when blink-cursor-timer
1330 (cancel-timer blink-cursor-timer)
1331 (setq blink-cursor-timer nil)))
1332
1333 (define-minor-mode blink-cursor-mode
1334 "Toggle blinking cursor mode.
1335 With a numeric argument, turn blinking cursor mode on iff ARG is positive.
1336 When blinking cursor mode is enabled, the cursor of the selected
1337 window blinks.
1338
1339 Note that this command is effective only when Emacs
1340 displays through a window system, because then Emacs does its own
1341 cursor display. On a text-only terminal, this is not implemented."
1342 :init-value (not (or noninteractive
1343 no-blinking-cursor
1344 (eq system-type 'ms-dos)
1345 (not (memq window-system '(x w32 mac)))))
1346 :initialize 'custom-initialize-safe-default
1347 :group 'cursor
1348 :global t
1349 (if blink-cursor-idle-timer (cancel-timer blink-cursor-idle-timer))
1350 (setq blink-cursor-idle-timer nil)
1351 (blink-cursor-end)
1352 (when blink-cursor-mode
1353 ;; Hide the cursor.
1354 ;;(internal-show-cursor nil nil)
1355 (setq blink-cursor-idle-timer
1356 (run-with-idle-timer blink-cursor-delay
1357 blink-cursor-delay
1358 'blink-cursor-start))))
1359
1360 (define-obsolete-variable-alias 'blink-cursor 'blink-cursor-mode "22.1")
1361 \f
1362 ;; Hourglass pointer
1363
1364 (defcustom display-hourglass t
1365 "*Non-nil means show an hourglass pointer, when Emacs is busy.
1366 This feature only works when on a window system that can change
1367 cursor shapes."
1368 :type 'boolean
1369 :group 'cursor)
1370
1371 (defcustom hourglass-delay 1
1372 "*Seconds to wait before displaying an hourglass pointer when Emacs is busy."
1373 :type 'number
1374 :group 'cursor)
1375
1376 \f
1377 (defcustom cursor-in-non-selected-windows t
1378 "*Non-nil means show a hollow box cursor in non-selected windows.
1379 If nil, don't show a cursor except in the selected window.
1380 Use Custom to set this variable to get the display updated."
1381 :tag "Cursor In Non-selected Windows"
1382 :type 'boolean
1383 :group 'cursor
1384 :set #'(lambda (symbol value)
1385 (set-default symbol value)
1386 (force-mode-line-update t)))
1387
1388 \f
1389 ;;;; Key bindings
1390
1391 (define-key ctl-x-5-map "2" 'make-frame-command)
1392 (define-key ctl-x-5-map "1" 'delete-other-frames)
1393 (define-key ctl-x-5-map "0" 'delete-frame)
1394 (define-key ctl-x-5-map "o" 'other-frame)
1395
1396 (provide 'frame)
1397
1398 ;; arch-tag: 82979c70-b8f2-4306-b2ad-ddbd6b328b56
1399 ;;; frame.el ends here