1 ;;; frame.el --- multi-frame management independent of window systems
3 ;; Copyright (C) 1993, 1994, 1996, 1997, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 ;; Free Software Foundation, Inc.
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 (eval-when-compile (require 'cl
))
31 (defvar frame-creation-function-alist
33 (if (fboundp 'tty-create-frame-with-faces
)
34 'tty-create-frame-with-faces
36 (error "Can't create multiple frames without a window system")))))
37 "Alist of window-system dependent functions to call to create a new frame.
38 The window system startup file should add its frame creation
39 function to this list, which should take an alist of parameters
42 (defvar window-system-default-frame-alist nil
43 "Alist of window-system dependent default frame parameters.
44 Parameters specified here supersede the values given in
45 `default-frame-alist'.")
47 ;; The initial value given here used to ask for a minibuffer.
48 ;; But that's not necessary, because the default is to have one.
49 ;; By not specifying it here, we let an X resource specify it.
50 (defcustom initial-frame-alist nil
51 "Alist of parameters for the initial X window frame.
52 You can set this in your init file; for example,
54 (setq initial-frame-alist
55 '((top . 1) (left . 1) (width . 80) (height . 55)))
57 Parameters specified here supersede the values given in
58 `default-frame-alist'.
60 If the value calls for a frame without a minibuffer, and you have
61 not created a minibuffer frame on your own, a minibuffer frame is
62 created according to `minibuffer-frame-alist'.
64 You can specify geometry-related options for just the initial
65 frame by setting this variable in your init file; however, they
66 won't take effect until Emacs reads your init file, which happens
67 after creating the initial frame. If you want the initial frame
68 to have the proper geometry as soon as it appears, you need to
69 use this three-step process:
70 * Specify X resources to give the geometry you want.
71 * Set `default-frame-alist' to override these options so that they
72 don't affect subsequent frames.
73 * Set `initial-frame-alist' in a way that matches the X resources,
74 to override what you put in `default-frame-alist'."
75 :type
'(repeat (cons :format
"%v"
76 (symbol :tag
"Parameter")
80 (defcustom minibuffer-frame-alist
'((width .
80) (height .
2))
81 "Alist of parameters for the initial minibuffer frame.
82 This is the minibuffer frame created if `initial-frame-alist'
83 calls for a frame without a minibuffer. The parameters specified
84 here supersede those given in `default-frame-alist', for the
85 initial minibuffer frame.
87 You can set this in your init file; for example,
89 (setq minibuffer-frame-alist
90 '((top . 1) (left . 1) (width . 80) (height . 2)))
92 It is not necessary to include (minibuffer . only); that is
93 appended when the minibuffer frame is created."
94 :type
'(repeat (cons :format
"%v"
95 (symbol :tag
"Parameter")
99 (defcustom pop-up-frame-alist nil
100 "Alist of parameters for automatically generated new frames.
101 You can set this in your init file; for example,
103 (setq pop-up-frame-alist '((width . 80) (height . 20)))
105 If non-nil, the value you specify here is used by the default
106 `pop-up-frame-function' for the creation of new frames.
108 Since `pop-up-frame-function' is used by `display-buffer' for
109 making new frames, any value specified here by default affects
110 the automatic generation of new frames via `display-buffer' and
111 all functions based on it. The behavior of `make-frame' is not
112 affected by this variable."
113 :type
'(repeat (cons :format
"%v"
114 (symbol :tag
"Parameter")
115 (sexp :tag
"Value")))
117 (make-obsolete-variable
119 "use `display-buffer-names', `display-buffer-regexps' or 2nd arg of `display-buffer' instead."
122 (defcustom pop-up-frame-function
123 (lambda () (make-frame pop-up-frame-alist
))
124 "Function used by `display-buffer' for creating a new frame.
125 This function is called with no arguments and should return a new
126 frame. The default value calls `make-frame' with the argument
127 `pop-up-frame-alist'."
130 (make-obsolete-variable
131 'pop-up-frame-function
132 "use `display-buffer-names', `display-buffer-regexps' or 2nd arg of `display-buffer' instead."
135 (defcustom special-display-frame-alist
136 '((height .
14) (width .
80) (unsplittable . t
))
137 "Alist of parameters for special frames.
138 Special frames are used for buffers whose names are listed in
139 `special-display-buffer-names' and for buffers whose names match
140 one of the regular expressions in `special-display-regexps'.
142 This variable can be set in your init file, like this:
144 (setq special-display-frame-alist '((width . 80) (height . 20)))
146 These supersede the values given in `default-frame-alist'."
147 :type
'(repeat (cons :format
"%v"
148 (symbol :tag
"Parameter")
149 (sexp :tag
"Value")))
151 (make-obsolete-variable
152 'special-display-frame-alist
153 "use `display-buffer-names', `display-buffer-regexps' or 2nd arg of `display-buffer' instead."
156 (defun special-display-popup-frame (buffer &optional args
)
157 "Display BUFFER and return the window chosen.
158 If BUFFER is already displayed in a visible or iconified frame,
159 raise that frame. Otherwise, display BUFFER in a new frame.
161 Optional argument ARGS is a list specifying additional
164 If ARGS is an alist, use it as a list of frame parameters. If
165 these parameters contain \(same-window . t), display BUFFER in
166 the selected window. If they contain \(same-frame . t), display
167 BUFFER in a window of the selected frame.
169 If ARGS is a list whose car is a symbol, use (car ARGS) as a
170 function to do the work. Pass it BUFFER as first argument,
171 and (cdr ARGS) as second."
172 (if (and args
(symbolp (car args
)))
173 (apply (car args
) buffer
(cdr args
))
174 (let ((window (get-buffer-window buffer
0)))
176 ;; If we have a window already, make it visible.
178 (let ((frame (window-frame window
)))
179 (make-frame-visible frame
)
182 ;; Reuse the current window if the user requested it.
183 (when (cdr (assq 'same-window args
))
185 (progn (switch-to-buffer buffer
) (selected-window))
187 ;; Stay on the same frame if requested.
188 (when (or (cdr (assq 'same-frame args
)) (cdr (assq 'same-window args
)))
189 (let* ((pop-up-windows t
)
191 special-display-buffer-names special-display-regexps
)
192 (display-buffer buffer
)))
193 ;; If no window yet, make one in a new frame.
195 (with-current-buffer buffer
196 (make-frame (append args special-display-frame-alist
)))))
197 (set-window-buffer (frame-selected-window frame
) buffer
)
198 (set-window-dedicated-p (frame-selected-window frame
) t
)
199 (frame-selected-window frame
))))))
201 (defun handle-delete-frame (event)
202 "Handle delete-frame events from the X server."
204 (let ((frame (posn-window (event-start event
)))
208 (and (frame-visible-p (car tail
))
209 (not (eq (car tail
) frame
))
211 (setq tail
(cdr tail
)))
213 (delete-frame frame t
)
214 ;; Gildea@x.org says it is ok to ask questions before terminating.
215 (save-buffers-kill-emacs))))
217 ;;;; Arrangement of frames at startup
219 ;; 1) Load the window system startup file from the lisp library and read the
220 ;; high-priority arguments (-q and the like). The window system startup
221 ;; file should create any frames specified in the window system defaults.
223 ;; 2) If no frames have been opened, we open an initial text frame.
225 ;; 3) Once the init file is done, we apply any newly set parameters
226 ;; in initial-frame-alist to the frame.
228 ;; These are now called explicitly at the proper times,
229 ;; since that is easier to understand.
230 ;; Actually using hooks within Emacs is bad for future maintenance. --rms.
231 ;; (add-hook 'before-init-hook 'frame-initialize)
232 ;; (add-hook 'window-setup-hook 'frame-notice-user-settings)
234 ;; If we create the initial frame, this is it.
235 (defvar frame-initial-frame nil
)
237 ;; Record the parameters used in frame-initialize to make the initial frame.
238 (defvar frame-initial-frame-alist
)
240 (defvar frame-initial-geometry-arguments nil
)
242 ;; startup.el calls this function before loading the user's init
243 ;; file - if there is no frame with a minibuffer open now, create
244 ;; one to display messages while loading the init file.
245 (defun frame-initialize ()
246 "Create an initial frame if necessary."
247 ;; Are we actually running under a window system at all?
248 (if (and initial-window-system
250 (not (eq initial-window-system
'pc
)))
252 ;; If there is no frame with a minibuffer besides the terminal
253 ;; frame, then we need to create the opening frame. Make sure
254 ;; it has a minibuffer, but let initial-frame-alist omit the
256 (or (delq terminal-frame
(minibuffer-frame-list))
258 (setq frame-initial-frame-alist
259 (append initial-frame-alist default-frame-alist nil
))
260 (or (assq 'horizontal-scroll-bars frame-initial-frame-alist
)
261 (setq frame-initial-frame-alist
262 (cons '(horizontal-scroll-bars . t
)
263 frame-initial-frame-alist
)))
264 (setq frame-initial-frame-alist
265 (cons (cons 'window-system initial-window-system
)
266 frame-initial-frame-alist
))
267 (setq default-minibuffer-frame
268 (setq frame-initial-frame
269 (make-frame frame-initial-frame-alist
)))
270 ;; Delete any specifications for window geometry parameters
271 ;; so that we won't reapply them in frame-notice-user-settings.
272 ;; It would be wrong to reapply them then,
273 ;; because that would override explicit user resizing.
274 (setq initial-frame-alist
275 (frame-remove-geometry-params initial-frame-alist
))))
276 ;; Copy the environment of the Emacs process into the new frame.
277 (set-frame-parameter frame-initial-frame
'environment
278 (frame-parameter terminal-frame
'environment
))
279 ;; At this point, we know that we have a frame open, so we
280 ;; can delete the terminal frame.
281 (delete-frame terminal-frame
)
282 (setq terminal-frame nil
))))
284 (defvar frame-notice-user-settings t
285 "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
287 (declare-function tool-bar-mode
"tool-bar" (&optional arg
))
289 ;; startup.el calls this function after loading the user's init
290 ;; file. Now default-frame-alist and initial-frame-alist contain
291 ;; information to which we must react; do what needs to be done.
292 (defun frame-notice-user-settings ()
293 "Act on user's init file settings of frame parameters.
294 React to settings of `initial-frame-alist',
295 `window-system-default-frame-alist' and `default-frame-alist'
296 there (in decreasing order of priority)."
297 ;; Creating and deleting frames may shift the selected frame around,
298 ;; and thus the current buffer. Protect against that. We don't
299 ;; want to use save-excursion here, because that may also try to set
300 ;; the buffer of the selected window, which fails when the selected
301 ;; window is the minibuffer.
302 (let ((old-buffer (current-buffer))
303 (window-system-frame-alist
304 (cdr (assq initial-window-system
305 window-system-default-frame-alist
))))
307 (when (and frame-notice-user-settings
308 (null frame-initial-frame
))
309 ;; This case happens when we don't have a window system, and
310 ;; also for MS-DOS frames.
311 (let ((parms (frame-parameters frame-initial-frame
)))
312 ;; Don't change the frame names.
313 (setq parms
(delq (assq 'name parms
) parms
))
314 ;; Can't modify the minibuffer parameter, so don't try.
315 (setq parms
(delq (assq 'minibuffer parms
) parms
))
316 (modify-frame-parameters nil
317 (if (null initial-window-system
)
318 (append initial-frame-alist
319 window-system-frame-alist
323 ;; initial-frame-alist and
324 ;; default-frame-alist were already
325 ;; applied in pc-win.el.
327 (if (null initial-window-system
) ;; MS-DOS does this differently in pc-win.el
328 (let ((newparms (frame-parameters))
329 (frame (selected-frame)))
330 (tty-handle-reverse-video frame newparms
)
331 ;; If we changed the background color, we need to update
332 ;; the background-mode parameter, and maybe some faces,
334 (when (assq 'background-color newparms
)
335 (unless (or (assq 'background-mode initial-frame-alist
)
336 (assq 'background-mode default-frame-alist
))
337 (frame-set-background-mode frame
))
338 (face-set-after-frame-default frame
))))))
340 ;; If the initial frame is still around, apply initial-frame-alist
341 ;; and default-frame-alist to it.
342 (when (frame-live-p frame-initial-frame
)
344 ;; When tool-bar has been switched off, correct the frame size
345 ;; by the lines added in x-create-frame for the tool-bar and
346 ;; switch `tool-bar-mode' off.
347 (when (display-graphic-p)
348 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist
)
349 (assq 'tool-bar-lines window-system-frame-alist
)
350 (assq 'tool-bar-lines default-frame-alist
))))
351 (when (and tool-bar-originally-present
352 (or (null tool-bar-lines
)
353 (null (cdr tool-bar-lines
))
354 (eq 0 (cdr tool-bar-lines
))))
355 (let* ((char-height (frame-char-height frame-initial-frame
))
356 (image-height tool-bar-images-pixel-height
)
357 (margin (cond ((and (consp tool-bar-button-margin
)
358 (integerp (cdr tool-bar-button-margin
))
359 (> tool-bar-button-margin
0))
360 (cdr tool-bar-button-margin
))
361 ((and (integerp tool-bar-button-margin
)
362 (> tool-bar-button-margin
0))
363 tool-bar-button-margin
)
365 (relief (if (and (integerp tool-bar-button-relief
)
366 (> tool-bar-button-relief
0))
367 tool-bar-button-relief
3))
368 (lines (/ (+ image-height
373 (height (frame-parameter frame-initial-frame
'height
))
374 (newparms (list (cons 'height
(- height lines
))))
375 (initial-top (cdr (assq 'top
376 frame-initial-geometry-arguments
)))
377 (top (frame-parameter frame-initial-frame
'top
)))
378 (when (and (consp initial-top
) (eq '-
(car initial-top
)))
380 (cond ((and (consp top
)
384 (* lines char-height
))))
389 (* lines char-height
))))
390 (t (+ top
(* lines char-height
))))))
393 `((top .
,adjusted-top
))
395 (modify-frame-parameters frame-initial-frame newparms
)
396 (tool-bar-mode -
1)))))
398 ;; The initial frame we create above always has a minibuffer.
399 ;; If the user wants to remove it, or make it a minibuffer-only
400 ;; frame, then we'll have to delete the current frame and make a
401 ;; new one; you can't remove or add a root window to/from an
404 ;; NOTE: default-frame-alist was nil when we created the
405 ;; existing frame. We need to explicitly include
406 ;; default-frame-alist in the parameters of the screen we
407 ;; create here, so that its new value, gleaned from the user's
408 ;; .emacs file, will be applied to the existing screen.
409 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist
)
410 (assq 'minibuffer window-system-frame-alist
)
411 (assq 'minibuffer default-frame-alist
)
414 ;; Create the new frame.
416 ;; If the frame isn't visible yet, wait till it is.
417 ;; If the user has to position the window,
418 ;; Emacs doesn't know its real position until
419 ;; the frame is seen to be visible.
420 (while (not (cdr (assq 'visibility
421 (frame-parameters frame-initial-frame
))))
423 (setq parms
(frame-parameters frame-initial-frame
))
425 ;; Get rid of `name' unless it was specified explicitly before.
426 (or (assq 'name frame-initial-frame-alist
)
427 (setq parms
(delq (assq 'name parms
) parms
)))
428 ;; An explicit parent-id is a request to XEmbed the frame.
429 (or (assq 'parent-id frame-initial-frame-alist
)
430 (setq parms
(delq (assq 'parent-id parms
) parms
)))
432 (setq parms
(append initial-frame-alist
433 window-system-frame-alist
438 ;; Get rid of `reverse', because that was handled
439 ;; when we first made the frame.
440 (setq parms
(cons '(reverse) (delq (assq 'reverse parms
) parms
)))
442 (if (assq 'height frame-initial-geometry-arguments
)
443 (setq parms
(assq-delete-all 'height parms
)))
444 (if (assq 'width frame-initial-geometry-arguments
)
445 (setq parms
(assq-delete-all 'width parms
)))
446 (if (assq 'left frame-initial-geometry-arguments
)
447 (setq parms
(assq-delete-all 'left parms
)))
448 (if (assq 'top frame-initial-geometry-arguments
)
449 (setq parms
(assq-delete-all 'top parms
)))
452 ;; Use the geometry args that created the existing
453 ;; frame, rather than the parms we get for it.
454 (append frame-initial-geometry-arguments
455 '((user-size . t
) (user-position . t
))
457 ;; The initial frame, which we are about to delete, may be
458 ;; the only frame with a minibuffer. If it is, create a
460 (or (delq frame-initial-frame
(minibuffer-frame-list))
461 (make-initial-minibuffer-frame nil
))
463 ;; If the initial frame is serving as a surrogate
464 ;; minibuffer frame for any frames, we need to wean them
465 ;; onto a new frame. The default-minibuffer-frame
466 ;; variable must be handled similarly.
467 (let ((users-of-initial
470 (and (not (eq frame frame-initial-frame
))
472 (minibuffer-window frame
))
473 frame-initial-frame
))))))
474 (if (or users-of-initial
475 (eq default-minibuffer-frame frame-initial-frame
))
477 ;; Choose an appropriate frame. Prefer frames which
478 ;; are only minibuffers.
479 (let* ((new-surrogate
481 (or (filtered-frame-list
483 (eq (cdr (assq 'minibuffer
484 (frame-parameters frame
)))
486 (minibuffer-frame-list))))
487 (new-minibuffer (minibuffer-window new-surrogate
)))
489 (if (eq default-minibuffer-frame frame-initial-frame
)
490 (setq default-minibuffer-frame new-surrogate
))
492 ;; Wean the frames using frame-initial-frame as
493 ;; their minibuffer frame.
494 (dolist (frame users-of-initial
)
495 (modify-frame-parameters
496 frame
(list (cons 'minibuffer new-minibuffer
)))))))
498 ;; Redirect events enqueued at this frame to the new frame.
499 ;; Is this a good idea?
500 (redirect-frame-focus frame-initial-frame new
)
502 ;; Finally, get rid of the old frame.
503 (delete-frame frame-initial-frame t
))
505 ;; Otherwise, we don't need all that rigamarole; just apply
506 ;; the new parameters.
507 (let (newparms allparms tail
)
508 (setq allparms
(append initial-frame-alist
509 window-system-frame-alist
510 default-frame-alist nil
))
511 (if (assq 'height frame-initial-geometry-arguments
)
512 (setq allparms
(assq-delete-all 'height allparms
)))
513 (if (assq 'width frame-initial-geometry-arguments
)
514 (setq allparms
(assq-delete-all 'width allparms
)))
515 (if (assq 'left frame-initial-geometry-arguments
)
516 (setq allparms
(assq-delete-all 'left allparms
)))
517 (if (assq 'top frame-initial-geometry-arguments
)
518 (setq allparms
(assq-delete-all 'top allparms
)))
520 ;; Find just the parms that have changed since we first
521 ;; made this frame. Those are the ones actually set by
522 ;; the init file. For those parms whose values we already knew
523 ;; (such as those spec'd by command line options)
524 ;; it is undesirable to specify the parm again
525 ;; once the user has seen the frame and been able to alter it
529 (setq oldval
(assq (car (car tail
))
530 frame-initial-frame-alist
))
531 (setq newval
(cdr (assq (car (car tail
)) allparms
)))
532 (or (and oldval
(eq (cdr oldval
) newval
))
534 (cons (cons (car (car tail
)) newval
) newparms
))))
535 (setq tail
(cdr tail
)))
536 (setq newparms
(nreverse newparms
))
537 (modify-frame-parameters frame-initial-frame
539 ;; If we changed the background color,
540 ;; we need to update the background-mode parameter
541 ;; and maybe some faces too.
542 (when (assq 'background-color newparms
)
543 (unless (assq 'background-mode newparms
)
544 (frame-set-background-mode frame-initial-frame
))
545 (face-set-after-frame-default frame-initial-frame
)))))
547 ;; Restore the original buffer.
548 (set-buffer old-buffer
)
550 ;; Make sure the initial frame can be GC'd if it is ever deleted.
551 ;; Make sure frame-notice-user-settings does nothing if called twice.
552 (setq frame-notice-user-settings nil
)
553 (setq frame-initial-frame nil
)))
555 (defun make-initial-minibuffer-frame (display)
556 (let ((parms (append minibuffer-frame-alist
'((minibuffer . only
)))))
558 (make-frame-on-display display parms
)
559 (make-frame parms
))))
561 ;;;; Creation of additional frames, and other frame miscellanea
563 (defun modify-all-frames-parameters (alist)
564 "Modify all current and future frames' parameters according to ALIST.
565 This changes `default-frame-alist' and possibly `initial-frame-alist'.
566 Furthermore, this function removes all parameters in ALIST from
567 `window-system-default-frame-alist'.
568 See help of `modify-frame-parameters' for more information."
569 (dolist (frame (frame-list))
570 (modify-frame-parameters frame alist
))
572 (dolist (pair alist
) ;; conses to add/replace
573 ;; initial-frame-alist needs setting only when
574 ;; frame-notice-user-settings is true.
575 (and frame-notice-user-settings
576 (setq initial-frame-alist
577 (assq-delete-all (car pair
) initial-frame-alist
)))
578 (setq default-frame-alist
579 (assq-delete-all (car pair
) default-frame-alist
))
580 ;; Remove any similar settings from the window-system specific
581 ;; parameters---they would override default-frame-alist.
582 (dolist (w window-system-default-frame-alist
)
583 (setcdr w
(assq-delete-all (car pair
) (cdr w
)))))
585 (and frame-notice-user-settings
586 (setq initial-frame-alist
(append initial-frame-alist alist
)))
587 (setq default-frame-alist
(append default-frame-alist alist
)))
589 (defun get-other-frame ()
590 "Return some frame other than the current frame.
591 Create one if necessary. Note that the minibuffer frame, if separate,
592 is not considered (see `next-frame')."
593 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
595 (next-frame (selected-frame)))))
598 (defun next-multiframe-window ()
599 "Select the next window, regardless of which frame it is on."
601 (select-window (next-window (selected-window)
602 (> (minibuffer-depth) 0)
604 (select-frame-set-input-focus (selected-frame)))
606 (defun previous-multiframe-window ()
607 "Select the previous window, regardless of which frame it is on."
609 (select-window (previous-window (selected-window)
610 (> (minibuffer-depth) 0)
612 (select-frame-set-input-focus (selected-frame)))
614 (declare-function x-initialize-window-system
"term/x-win" ())
615 (declare-function ns-initialize-window-system
"term/ns-win" ())
616 (defvar x-display-name
) ; term/x-win
618 (defun make-frame-on-display (display &optional parameters
)
619 "Make a frame on display DISPLAY.
620 The optional argument PARAMETERS specifies additional frame parameters."
621 (interactive "sMake frame on display: ")
622 (cond ((featurep 'ns
)
623 (when (and (boundp 'ns-initialized
) (not ns-initialized
))
624 (setq x-display-name display
)
625 (ns-initialize-window-system))
626 (make-frame `((window-system . ns
)
627 (display .
,display
) .
,parameters
)))
628 ((eq system-type
'windows-nt
)
629 ;; On Windows, ignore DISPLAY.
630 (make-frame parameters
))
632 (unless (string-match-p "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display
)
633 (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
634 (when (and (boundp 'x-initialized
) (not x-initialized
))
635 (setq x-display-name display
)
636 (x-initialize-window-system))
637 (make-frame `((window-system . x
)
638 (display .
,display
) .
,parameters
)))))
640 (declare-function x-close-connection
"xfns.c" (terminal))
642 (defun close-display-connection (display)
643 "Close the connection to a display, deleting all its associated frames.
644 For DISPLAY, specify either a frame or a display name (a string).
645 If DISPLAY is nil, that stands for the selected frame's display."
648 (let* ((default (frame-parameter nil
'display
))
649 (display (completing-read
650 (format "Close display (default %s): " default
)
652 (mapcar (lambda (frame)
653 (frame-parameter frame
'display
))
657 (if (zerop (length display
)) default display
))))
658 (let ((frames (delq nil
659 (mapcar (lambda (frame)
661 (frame-parameter frame
'display
))
664 (if (and (consp frames
)
665 (not (y-or-n-p (if (cdr frames
)
666 (format "Delete %s frames? " (length frames
))
667 (format "Delete %s ? " (car frames
))))))
669 (mapc 'delete-frame frames
)
670 (x-close-connection display
))))
672 (defun make-frame-command ()
673 "Make a new frame, on the same terminal as the selected frame.
674 If the terminal is a text-only terminal, this also selects the
677 (if (display-graphic-p)
679 (select-frame (make-frame))))
681 (defvar before-make-frame-hook nil
682 "Functions to run before a frame is created.")
684 (defvar after-make-frame-functions nil
685 "Functions to run after a frame is created.
686 The functions are run with one arg, the newly created frame.")
688 (defvar after-setting-font-hook nil
689 "Functions to run after a frame's font has been changed.")
691 ;; Alias, kept temporarily.
692 (define-obsolete-function-alias 'new-frame
'make-frame
"22.1")
694 (defvar frame-inherited-parameters
'()
695 ;; FIXME: Shouldn't we add `font' here as well?
696 "Parameters `make-frame' copies from the `selected-frame' to the new frame.")
698 (defun make-frame (&optional parameters
)
699 "Return a newly created frame displaying the current buffer.
700 Optional argument PARAMETERS is an alist of frame parameters for
701 the new frame. Each element of PARAMETERS should have the
702 form (NAME . VALUE), for example:
704 (name . STRING) The frame should be named STRING.
706 (width . NUMBER) The frame should be NUMBER characters in width.
707 (height . NUMBER) The frame should be NUMBER text lines high.
709 You cannot specify either `width' or `height', you must specify
712 (minibuffer . t) The frame should have a minibuffer.
713 (minibuffer . nil) The frame should have no minibuffer.
714 (minibuffer . only) The frame should contain only a minibuffer.
715 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
717 (window-system . nil) The frame should be displayed on a terminal device.
718 (window-system . x) The frame should be displayed in an X window.
720 (terminal . TERMINAL) The frame should use the terminal object TERMINAL.
722 In addition, any parameter specified in `default-frame-alist',
723 but not present in PARAMETERS, is applied.
725 Before creating the frame (via `frame-creation-function-alist'),
726 this function runs the hook `before-make-frame-hook'. After
727 creating the frame, it runs the hook `after-make-frame-functions'
728 with one arg, the newly created frame.
730 On graphical displays, this function does not itself make the new
731 frame the selected frame. However, the window system may select
732 the new frame according to its own rules."
735 ((assq 'terminal parameters
)
736 (let ((type (terminal-live-p (cdr (assq 'terminal parameters
)))))
739 ((eq type nil
) (error "Terminal %s does not exist"
740 (cdr (assq 'terminal parameters
))))
742 ((assq 'window-system parameters
)
743 (cdr (assq 'window-system parameters
)))
745 (frame-creation-function (cdr (assq w frame-creation-function-alist
)))
746 (oldframe (selected-frame))
749 (unless frame-creation-function
750 (error "Don't know how to create a frame on window system %s" w
))
751 ;; Add parameters from `window-system-default-frame-alist'.
752 (dolist (p (cdr (assq w window-system-default-frame-alist
)))
753 (unless (assq (car p
) params
)
755 ;; Add parameters from `default-frame-alist'.
756 (dolist (p default-frame-alist
)
757 (unless (assq (car p
) params
)
759 ;; Now make the frame.
760 (run-hooks 'before-make-frame-hook
)
761 (setq frame
(funcall frame-creation-function params
))
762 (normal-erase-is-backspace-setup-frame frame
)
763 ;; Inherit the original frame's parameters.
764 (dolist (param frame-inherited-parameters
)
765 (unless (assq param parameters
) ;Overridden by explicit parameters.
766 (let ((val (frame-parameter oldframe param
)))
767 (when val
(set-frame-parameter frame param val
)))))
768 (run-hook-with-args 'after-make-frame-functions frame
)
771 (defun filtered-frame-list (predicate)
772 "Return a list of all live frames which satisfy PREDICATE."
773 (let* ((frames (frame-list))
775 (while (consp frames
)
776 (unless (funcall predicate
(car frames
))
778 (setq frames
(cdr frames
)))
781 (defun minibuffer-frame-list ()
782 "Return a list of all frames with their own minibuffers."
785 (eq frame
(window-frame (minibuffer-window frame
))))))
787 ;; Used to be called `terminal-id' in termdev.el.
788 (defun get-device-terminal (device)
789 "Return the terminal corresponding to DEVICE.
790 DEVICE can be a terminal, a frame, nil (meaning the selected frame's terminal),
791 the name of an X display device (HOST.SERVER.SCREEN) or a tty device file."
793 ((or (null device
) (framep device
))
794 (frame-terminal device
))
796 (let ((f (car (filtered-frame-list
798 (or (equal (frame-parameter frame
'display
) device
)
799 (equal (frame-parameter frame
'tty
) device
)))))))
800 (or f
(error "Display %s does not exist" device
))
802 ((terminal-live-p device
) device
)
804 (error "Invalid argument %s in `get-device-terminal'" device
))))
806 (defun frames-on-display-list (&optional device
)
807 "Return a list of all frames on DEVICE.
809 DEVICE should be a terminal, a frame,
810 or a name of an X display or tty (a string of the form
813 If DEVICE is omitted or nil, it defaults to the selected
814 frame's terminal device."
815 (let* ((terminal (get-device-terminal device
))
816 (func #'(lambda (frame)
817 (eq (frame-terminal frame
) terminal
))))
818 (filtered-frame-list func
)))
820 (defun framep-on-display (&optional terminal
)
821 "Return the type of frames on TERMINAL.
822 TERMINAL may be a terminal id, a display name or a frame. If it
823 is a frame, its type is returned. If TERMINAL is omitted or nil,
824 it defaults to the selected frame's terminal device. All frames
825 on a given display are of the same type."
826 (or (terminal-live-p terminal
)
828 (framep (car (frames-on-display-list terminal
)))))
830 (defun frame-remove-geometry-params (param-list)
831 "Return the parameter list PARAM-LIST, but with geometry specs removed.
832 This deletes all bindings in PARAM-LIST for `top', `left', `width',
833 `height', `user-size' and `user-position' parameters.
834 Emacs uses this to avoid overriding explicit moves and resizings from
835 the user during startup."
836 (setq param-list
(cons nil param-list
))
837 (let ((tail param-list
))
838 (while (consp (cdr tail
))
839 (if (and (consp (car (cdr tail
)))
840 (memq (car (car (cdr tail
)))
841 '(height width top left user-position user-size
)))
843 (setq frame-initial-geometry-arguments
844 (cons (car (cdr tail
)) frame-initial-geometry-arguments
))
845 (setcdr tail
(cdr (cdr tail
))))
846 (setq tail
(cdr tail
)))))
847 (setq frame-initial-geometry-arguments
848 (nreverse frame-initial-geometry-arguments
))
851 (declare-function x-focus-frame
"xfns.c" (frame))
853 (defun select-frame-set-input-focus (frame)
854 "Select FRAME, raise it, and set input focus, if possible.
855 If `mouse-autoselect-window' is non-nil, also move mouse pointer
856 to FRAME's selected window. Otherwise, if `focus-follows-mouse'
857 is non-nil, move mouse cursor to FRAME."
860 ;; Ensure, if possible, that FRAME gets input focus.
861 (when (memq (window-system frame
) '(x w32 ns
))
862 (x-focus-frame frame
))
863 ;; Move mouse cursor if necessary.
865 (mouse-autoselect-window
866 (let ((edges (window-inside-edges (frame-selected-window frame
))))
867 ;; Move mouse cursor into FRAME's selected window to avoid that
868 ;; Emacs mouse-autoselects another window.
869 (set-mouse-position frame
(nth 2 edges
) (nth 1 edges
))))
871 ;; Move mouse cursor into FRAME to avoid that another frame gets
872 ;; selected by the window manager.
873 (set-mouse-position frame
(1- (frame-width frame
)) 0))))
875 (defun other-frame (arg)
876 "Select the ARGth different visible frame on current display, and raise it.
877 All frames are arranged in a cyclic order.
878 This command selects the frame ARG steps away in that order.
879 A negative ARG moves in the opposite order.
881 To make this command work properly, you must tell Emacs
882 how the system (or the window manager) generally handles
883 focus-switching between windows. If moving the mouse onto a window
884 selects it (gives it focus), set `focus-follows-mouse' to t.
885 Otherwise, that variable should be nil."
887 (let ((frame (selected-frame)))
889 (setq frame
(next-frame frame
))
890 (while (not (eq (frame-visible-p frame
) t
))
891 (setq frame
(next-frame frame
)))
894 (setq frame
(previous-frame frame
))
895 (while (not (eq (frame-visible-p frame
) t
))
896 (setq frame
(previous-frame frame
)))
898 (select-frame-set-input-focus frame
)))
900 (defun iconify-or-deiconify-frame ()
901 "Iconify the selected frame, or deiconify if it's currently an icon."
903 (if (eq (cdr (assq 'visibility
(frame-parameters))) t
)
905 (make-frame-visible)))
907 (defun suspend-frame ()
908 "Do whatever is right to suspend the current frame.
909 Calls `suspend-emacs' if invoked from the controlling tty device,
910 `suspend-tty' from a secondary tty device, and
911 `iconify-or-deiconify-frame' from an X frame."
913 (let ((type (framep (selected-frame))))
915 ((memq type
'(x ns w32
)) (iconify-or-deiconify-frame))
917 (if (controlling-tty-p)
920 (t (suspend-emacs)))))
922 (defun make-frame-names-alist ()
923 ;; Only consider the frames on the same display.
924 (let* ((current-frame (selected-frame))
927 (cons (frame-parameter current-frame
'name
) current-frame
) nil
))
928 (frame (next-frame nil
0)))
929 (while (not (eq frame current-frame
))
931 (push (cons (frame-parameter frame
'name
) frame
) falist
)
932 (setq frame
(next-frame frame
0))))
935 (defvar frame-name-history nil
)
936 (defun select-frame-by-name (name)
937 "Select the frame on the current terminal whose name is NAME and raise it.
938 If there is no frame by that name, signal an error."
940 (let* ((frame-names-alist (make-frame-names-alist))
941 (default (car (car frame-names-alist
)))
942 (input (completing-read
943 (format "Select Frame (default %s): " default
)
944 frame-names-alist nil t nil
'frame-name-history
)))
945 (if (= (length input
) 0)
948 (let* ((frame-names-alist (make-frame-names-alist))
949 (frame (cdr (assoc name frame-names-alist
))))
951 (select-frame-set-input-focus frame
)
952 (error "There is no frame named `%s'" name
))))
954 ;;;; Frame configurations
956 (defun current-frame-configuration ()
957 "Return a list describing the positions and states of all frames.
958 Its car is `frame-configuration'.
959 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
961 FRAME is a frame object,
962 ALIST is an association list specifying some of FRAME's parameters, and
963 WINDOW-CONFIG is a window configuration object for FRAME."
964 (cons 'frame-configuration
965 (mapcar (lambda (frame)
967 (frame-parameters frame
)
968 (current-window-configuration frame
)))
971 (defun set-frame-configuration (configuration &optional nodelete
)
972 "Restore the frames to the state described by CONFIGURATION.
973 Each frame listed in CONFIGURATION has its position, size, window
974 configuration, and other parameters set as specified in CONFIGURATION.
975 However, this function does not restore deleted frames.
977 Ordinarily, this function deletes all existing frames not
978 listed in CONFIGURATION. But if optional second argument NODELETE
979 is given and non-nil, the unwanted frames are iconified instead."
980 (or (frame-configuration-p configuration
)
981 (signal 'wrong-type-argument
982 (list 'frame-configuration-p configuration
)))
983 (let ((config-alist (cdr configuration
))
985 (dolist (frame (frame-list))
986 (let ((parameters (assq frame config-alist
)))
989 (modify-frame-parameters
991 ;; Since we can't set a frame's minibuffer status,
992 ;; we might as well omit the parameter altogether.
993 (let* ((parms (nth 1 parameters
))
994 (mini (assq 'minibuffer parms
))
995 (name (assq 'name parms
))
996 (explicit-name (cdr (assq 'explicit-name parms
))))
997 (when mini
(setq parms
(delq mini parms
)))
998 ;; Leave name in iff it was set explicitly.
999 ;; This should fix the behavior reported in
1000 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg01632.html
1001 (when (and name
(not explicit-name
))
1002 (setq parms
(delq name parms
)))
1004 (set-window-configuration (nth 2 parameters
)))
1005 (setq frames-to-delete
(cons frame frames-to-delete
)))))
1007 ;; Note: making frames invisible here was tried
1008 ;; but led to some strange behavior--each time the frame
1009 ;; was made visible again, the window manager asked afresh
1010 ;; for where to put it.
1015 ;;;; Convenience functions for accessing and interactively changing
1016 ;;;; frame parameters.
1018 (defun frame-height (&optional frame
)
1019 "Return number of lines available for display on FRAME.
1020 If FRAME is omitted, describe the currently selected frame.
1021 Exactly what is included in the return value depends on the
1022 window-system and toolkit in use - see `frame-pixel-height' for
1023 more details. The lines are in units of the default font height.
1025 The result is roughly related to the frame pixel height via
1026 height in pixels = height in lines * `frame-char-height'.
1027 However, this is only approximate, and is complicated e.g. by the
1028 fact that individual window lines and menu bar lines can have
1029 differing font heights."
1030 (cdr (assq 'height
(frame-parameters frame
))))
1032 (defun frame-width (&optional frame
)
1033 "Return number of columns available for display on FRAME.
1034 If FRAME is omitted, describe the currently selected frame."
1035 (cdr (assq 'width
(frame-parameters frame
))))
1037 (declare-function x-list-fonts
"xfaces.c"
1038 (pattern &optional face frame maximum width
))
1040 (define-obsolete-function-alias 'set-default-font
'set-frame-font
"23.1")
1041 (defun set-frame-font (font-name &optional keep-size
)
1042 "Set the font of the selected frame to FONT-NAME.
1043 When called interactively, prompt for the name of the font to use.
1044 To get the frame's current default font, use `frame-parameters'.
1046 The default behavior is to keep the numbers of lines and columns in
1047 the frame, thus may change its pixel size. If optional KEEP-SIZE is
1048 non-nil (interactively, prefix argument) the current frame size (in
1049 pixels) is kept by adjusting the numbers of the lines and columns."
1051 (let* ((completion-ignore-case t
)
1052 (font (completing-read "Font name: "
1053 ;; x-list-fonts will fail with an error
1054 ;; if this frame doesn't support fonts.
1055 (x-list-fonts "*" nil
(selected-frame))
1057 (frame-parameter nil
'font
))))
1058 (list font current-prefix-arg
)))
1061 (setq fht
(* (frame-parameter nil
'height
) (frame-char-height))
1062 fwd
(* (frame-parameter nil
'width
) (frame-char-width))))
1063 (modify-frame-parameters (selected-frame)
1064 (list (cons 'font font-name
)))
1066 (modify-frame-parameters
1068 (list (cons 'height
(round fht
(frame-char-height)))
1069 (cons 'width
(round fwd
(frame-char-width)))))))
1070 (run-hooks 'after-setting-font-hook
'after-setting-font-hooks
))
1072 (defun set-frame-parameter (frame parameter value
)
1073 "Set frame parameter PARAMETER to VALUE on FRAME.
1074 If FRAME is nil, it defaults to the selected frame.
1075 See `modify-frame-parameters'."
1076 (modify-frame-parameters frame
(list (cons parameter value
))))
1078 (defun set-background-color (color-name)
1079 "Set the background color of the selected frame to COLOR-NAME.
1080 When called interactively, prompt for the name of the color to use.
1081 To get the frame's current background color, use `frame-parameters'."
1082 (interactive (list (read-color "Background color: ")))
1083 (modify-frame-parameters (selected-frame)
1084 (list (cons 'background-color color-name
)))
1086 (face-set-after-frame-default (selected-frame))))
1088 (defun set-foreground-color (color-name)
1089 "Set the foreground color of the selected frame to COLOR-NAME.
1090 When called interactively, prompt for the name of the color to use.
1091 To get the frame's current foreground color, use `frame-parameters'."
1092 (interactive (list (read-color "Foreground color: ")))
1093 (modify-frame-parameters (selected-frame)
1094 (list (cons 'foreground-color color-name
)))
1096 (face-set-after-frame-default (selected-frame))))
1098 (defun set-cursor-color (color-name)
1099 "Set the text cursor color of the selected frame to COLOR-NAME.
1100 When called interactively, prompt for the name of the color to use.
1101 To get the frame's current cursor color, use `frame-parameters'."
1102 (interactive (list (read-color "Cursor color: ")))
1103 (modify-frame-parameters (selected-frame)
1104 (list (cons 'cursor-color color-name
))))
1106 (defun set-mouse-color (color-name)
1107 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
1108 When called interactively, prompt for the name of the color to use.
1109 To get the frame's current mouse color, use `frame-parameters'."
1110 (interactive (list (read-color "Mouse color: ")))
1111 (modify-frame-parameters (selected-frame)
1112 (list (cons 'mouse-color
1114 (cdr (assq 'mouse-color
1115 (frame-parameters))))))))
1117 (defun set-border-color (color-name)
1118 "Set the color of the border of the selected frame to COLOR-NAME.
1119 When called interactively, prompt for the name of the color to use.
1120 To get the frame's current border color, use `frame-parameters'."
1121 (interactive (list (read-color "Border color: ")))
1122 (modify-frame-parameters (selected-frame)
1123 (list (cons 'border-color color-name
))))
1125 (define-minor-mode auto-raise-mode
1126 "Toggle whether or not the selected frame should auto-raise.
1127 With ARG, turn auto-raise mode on if and only if ARG is positive.
1128 Note that this controls Emacs's own auto-raise feature.
1129 Some window managers allow you to enable auto-raise for certain windows.
1130 You can use that for Emacs windows if you wish, but if you do,
1131 that is beyond the control of Emacs and this command has no effect on it."
1132 :variable
(frame-parameter nil
'auto-raise
)
1133 (if (frame-parameter nil
'auto-raise
)
1136 (define-minor-mode auto-lower-mode
1137 "Toggle whether or not the selected frame should auto-lower.
1138 With ARG, turn auto-lower mode on if and only if ARG is positive.
1139 Note that this controls Emacs's own auto-lower feature.
1140 Some window managers allow you to enable auto-lower for certain windows.
1141 You can use that for Emacs windows if you wish, but if you do,
1142 that is beyond the control of Emacs and this command has no effect on it."
1143 :variable
(frame-parameter nil
'auto-lower
))
1145 (defun set-frame-name (name)
1146 "Set the name of the selected frame to NAME.
1147 When called interactively, prompt for the name of the frame.
1148 The frame name is displayed on the modeline if the terminal displays only
1149 one frame, otherwise the name is displayed on the frame's caption bar."
1150 (interactive "sFrame name: ")
1151 (modify-frame-parameters (selected-frame)
1152 (list (cons 'name name
))))
1154 (defun frame-current-scroll-bars (&optional frame
)
1155 "Return the current scroll-bar settings in frame FRAME.
1156 Value is a cons (VERTICAL . HORIZ0NTAL) where VERTICAL specifies the
1157 current location of the vertical scroll-bars (left, right, or nil),
1158 and HORIZONTAL specifies the current location of the horizontal scroll
1159 bars (top, bottom, or nil)."
1160 (let ((vert (frame-parameter frame
'vertical-scroll-bars
))
1162 (unless (memq vert
'(left right nil
))
1163 (setq vert default-frame-scroll-bars
))
1166 ;;;; Frame/display capabilities.
1167 (defun selected-terminal ()
1168 "Return the terminal that is now selected."
1169 (frame-terminal (selected-frame)))
1171 (declare-function msdos-mouse-p
"dosfns.c")
1173 (defun display-mouse-p (&optional display
)
1174 "Return non-nil if DISPLAY has a mouse available.
1175 DISPLAY can be a display name, a frame, or nil (meaning the selected
1177 (let ((frame-type (framep-on-display display
)))
1179 ((eq frame-type
'pc
)
1181 ((eq system-type
'windows-nt
)
1183 (> w32-num-mouse-buttons
0)))
1184 ((memq frame-type
'(x ns
))
1185 t
) ;; We assume X and NeXTstep *always* have a pointing device
1187 (or (and (featurep 'xt-mouse
)
1189 ;; t-mouse is distributed with the GPM package. It doesn't have
1191 (featurep 't-mouse
))))))
1193 (defun display-popup-menus-p (&optional display
)
1194 "Return non-nil if popup menus are supported on DISPLAY.
1195 DISPLAY can be a display name, a frame, or nil (meaning the selected
1197 Support for popup menus requires that the mouse be available."
1199 (let ((frame-type (framep-on-display display
)))
1200 (memq frame-type
'(x w32 pc ns
)))
1201 (display-mouse-p display
)))
1203 (defun display-graphic-p (&optional display
)
1204 "Return non-nil if DISPLAY is a graphic display.
1205 Graphical displays are those which are capable of displaying several
1206 frames and several different fonts at once. This is true for displays
1207 that use a window system such as X, and false for text-only terminals.
1208 DISPLAY can be a display name, a frame, or nil (meaning the selected
1210 (not (null (memq (framep-on-display display
) '(x w32 ns
)))))
1212 (defun display-images-p (&optional display
)
1213 "Return non-nil if DISPLAY can display images.
1215 DISPLAY can be a display name, a frame, or nil (meaning the selected
1217 (and (display-graphic-p display
)
1218 (fboundp 'image-mask-p
)
1219 (fboundp 'image-size
)))
1221 (defalias 'display-multi-frame-p
'display-graphic-p
)
1222 (defalias 'display-multi-font-p
'display-graphic-p
)
1224 (defun display-selections-p (&optional display
)
1225 "Return non-nil if DISPLAY supports selections.
1226 A selection is a way to transfer text or other data between programs
1227 via special system buffers called `selection' or `clipboard'.
1228 DISPLAY can be a display name, a frame, or nil (meaning the selected
1230 (let ((frame-type (framep-on-display display
)))
1232 ((eq frame-type
'pc
)
1233 ;; MS-DOG frames support selections when Emacs runs inside
1234 ;; the Windows' DOS Box.
1236 (not (null dos-windows-version
))))
1237 ((memq frame-type
'(x w32 ns
))
1242 (declare-function x-display-screens
"xfns.c" (&optional terminal
))
1244 (defun display-screens (&optional display
)
1245 "Return the number of screens associated with DISPLAY."
1246 (let ((frame-type (framep-on-display display
)))
1248 ((memq frame-type
'(x w32 ns
))
1249 (x-display-screens display
))
1253 (declare-function x-display-pixel-height
"xfns.c" (&optional terminal
))
1255 (defun display-pixel-height (&optional display
)
1256 "Return the height of DISPLAY's screen in pixels.
1257 For character terminals, each character counts as a single pixel."
1258 (let ((frame-type (framep-on-display display
)))
1260 ((memq frame-type
'(x w32 ns
))
1261 (x-display-pixel-height display
))
1263 (frame-height (if (framep display
) display
(selected-frame)))))))
1265 (declare-function x-display-pixel-width
"xfns.c" (&optional terminal
))
1267 (defun display-pixel-width (&optional display
)
1268 "Return the width of DISPLAY's screen in pixels.
1269 For character terminals, each character counts as a single pixel."
1270 (let ((frame-type (framep-on-display display
)))
1272 ((memq frame-type
'(x w32 ns
))
1273 (x-display-pixel-width display
))
1275 (frame-width (if (framep display
) display
(selected-frame)))))))
1277 (defcustom display-mm-dimensions-alist nil
1278 "Alist for specifying screen dimensions in millimeters.
1279 The dimensions will be used for `display-mm-height' and
1280 `display-mm-width' if defined for the respective display.
1282 Each element of the alist has the form (display . (width . height)),
1283 e.g. (\":0.0\" . (287 . 215)).
1285 If `display' equals t, it specifies dimensions for all graphical
1286 displays not explicitely specified."
1288 :type
'(alist :key-type
(choice (string :tag
"Display name")
1289 (const :tag
"Default" t
))
1290 :value-type
(cons :tag
"Dimensions"
1291 (integer :tag
"Width")
1292 (integer :tag
"Height")))
1295 (declare-function x-display-mm-height
"xfns.c" (&optional terminal
))
1297 (defun display-mm-height (&optional display
)
1298 "Return the height of DISPLAY's screen in millimeters.
1299 System values can be overridden by `display-mm-dimensions-alist'.
1300 If the information is unavailable, value is nil."
1301 (and (memq (framep-on-display display
) '(x w32 ns
))
1302 (or (cddr (assoc (or display
(frame-parameter nil
'display
))
1303 display-mm-dimensions-alist
))
1304 (cddr (assoc t display-mm-dimensions-alist
))
1305 (x-display-mm-height display
))))
1307 (declare-function x-display-mm-width
"xfns.c" (&optional terminal
))
1309 (defun display-mm-width (&optional display
)
1310 "Return the width of DISPLAY's screen in millimeters.
1311 System values can be overridden by `display-mm-dimensions-alist'.
1312 If the information is unavailable, value is nil."
1313 (and (memq (framep-on-display display
) '(x w32 ns
))
1314 (or (cadr (assoc (or display
(frame-parameter nil
'display
))
1315 display-mm-dimensions-alist
))
1316 (cadr (assoc t display-mm-dimensions-alist
))
1317 (x-display-mm-width display
))))
1319 (declare-function x-display-backing-store
"xfns.c" (&optional terminal
))
1321 (defun display-backing-store (&optional display
)
1322 "Return the backing store capability of DISPLAY's screen.
1323 The value may be `always', `when-mapped', `not-useful', or nil if
1324 the question is inapplicable to a certain kind of display."
1325 (let ((frame-type (framep-on-display display
)))
1327 ((memq frame-type
'(x w32 ns
))
1328 (x-display-backing-store display
))
1332 (declare-function x-display-save-under
"xfns.c" (&optional terminal
))
1334 (defun display-save-under (&optional display
)
1335 "Return non-nil if DISPLAY's screen supports the SaveUnder feature."
1336 (let ((frame-type (framep-on-display display
)))
1338 ((memq frame-type
'(x w32 ns
))
1339 (x-display-save-under display
))
1343 (declare-function x-display-planes
"xfns.c" (&optional terminal
))
1345 (defun display-planes (&optional display
)
1346 "Return the number of planes supported by DISPLAY."
1347 (let ((frame-type (framep-on-display display
)))
1349 ((memq frame-type
'(x w32 ns
))
1350 (x-display-planes display
))
1351 ((eq frame-type
'pc
)
1354 (truncate (log (length (tty-color-alist)) 2))))))
1356 (declare-function x-display-color-cells
"xfns.c" (&optional terminal
))
1358 (defun display-color-cells (&optional display
)
1359 "Return the number of color cells supported by DISPLAY."
1360 (let ((frame-type (framep-on-display display
)))
1362 ((memq frame-type
'(x w32 ns
))
1363 (x-display-color-cells display
))
1364 ((eq frame-type
'pc
)
1367 (tty-display-color-cells display
)))))
1369 (declare-function x-display-visual-class
"xfns.c" (&optional terminal
))
1371 (defun display-visual-class (&optional display
)
1372 "Return the visual class of DISPLAY.
1373 The value is one of the symbols `static-gray', `gray-scale',
1374 `static-color', `pseudo-color', `true-color', or `direct-color'."
1375 (let ((frame-type (framep-on-display display
)))
1377 ((memq frame-type
'(x w32 ns
))
1378 (x-display-visual-class display
))
1379 ((and (memq frame-type
'(pc t
))
1380 (tty-display-color-p display
))
1386 ;;;; Frame geometry values
1388 (defun frame-geom-value-cons (type value
&optional frame
)
1389 "Return equivalent geometry value for FRAME as a cons with car `+'.
1390 A geometry value equivalent to VALUE for FRAME is returned,
1391 where the value is a cons with car `+', not numeric.
1392 TYPE is the car of the original geometry spec (TYPE . VALUE).
1393 It is `top' or `left', depending on which edge VALUE is related to.
1394 VALUE is the cdr of a frame geometry spec: (left/top . VALUE).
1395 If VALUE is a number, then it is converted to a cons value, perhaps
1396 relative to the opposite frame edge from that in the original spec.
1397 FRAME defaults to the selected frame.
1399 Examples (measures in pixels) -
1400 Assuming display height/width=1024, frame height/width=600:
1401 300 inside display edge: 300 => (+ 300)
1403 300 inside opposite display edge: (- 300) => (+ 124)
1405 300 beyond display edge
1406 (= 724 inside opposite display edge): (+ -300) => (+ -300)
1407 300 beyond display edge
1408 (= 724 inside opposite display edge): (- -300) => (+ 724)
1410 In the 3rd, 4th, and 6th examples, the returned value is relative to
1411 the opposite frame edge from the edge indicated in the input spec."
1412 (cond ((and (consp value
) (eq '+ (car value
))) ; e.g. (+ 300), (+ -300)
1414 ((natnump value
) (list '+ value
)) ; e.g. 300 => (+ 300)
1415 (t ; e.g. -300, (- 300), (- -300)
1416 (list '+ (- (if (eq 'left type
) ; => (+ 124), (+ 124), (+ 724)
1417 (x-display-pixel-width)
1418 (x-display-pixel-height))
1419 (if (integerp value
) (- value
) (cadr value
))
1421 (frame-pixel-width frame
)
1422 (frame-pixel-height frame
)))))))
1424 (defun frame-geom-spec-cons (spec &optional frame
)
1425 "Return equivalent geometry spec for FRAME as a cons with car `+'.
1426 A geometry specification equivalent to SPEC for FRAME is returned,
1427 where the value is a cons with car `+', not numeric.
1428 SPEC is a frame geometry spec: (left . VALUE) or (top . VALUE).
1429 If VALUE is a number, then it is converted to a cons value, perhaps
1430 relative to the opposite frame edge from that in the original spec.
1431 FRAME defaults to the selected frame.
1433 Examples (measures in pixels) -
1434 Assuming display height=1024, frame height=600:
1435 top 300 below display top: (top . 300) => (top + 300)
1436 (top + 300) => (top + 300)
1437 bottom 300 above display bottom: (top - 300) => (top + 124)
1438 (top . -300) => (top + 124)
1439 top 300 above display top
1440 (= bottom 724 above display bottom): (top + -300) => (top + -300)
1441 bottom 300 below display bottom
1442 (= top 724 below display top): (top - -300) => (top + 724)
1444 In the 3rd, 4th, and 6th examples, the returned value is relative to
1445 the opposite frame edge from the edge indicated in the input spec."
1446 (cons (car spec
) (frame-geom-value-cons (car spec
) (cdr spec
))))
1449 (defun delete-other-frames (&optional frame
)
1450 "Delete all frames except FRAME.
1451 If FRAME uses another frame's minibuffer, the minibuffer frame is
1452 left untouched. FRAME nil or omitted means use the selected frame."
1455 (setq frame
(selected-frame)))
1456 (let* ((mini-frame (window-frame (minibuffer-window frame
)))
1457 (frames (delq mini-frame
(delq frame
(frame-list)))))
1458 ;; Only consider frames on the same terminal.
1459 (dolist (frame (prog1 frames
(setq frames nil
)))
1460 (if (eq (frame-terminal) (frame-terminal frame
))
1461 (push frame frames
)))
1462 ;; Delete mon-minibuffer-only frames first, because `delete-frame'
1463 ;; signals an error when trying to delete a mini-frame that's
1464 ;; still in use by another frame.
1465 (dolist (frame frames
)
1466 (unless (eq (frame-parameter frame
'minibuffer
) 'only
)
1467 (delete-frame frame
)))
1468 ;; Delete minibuffer-only frames.
1469 (dolist (frame frames
)
1470 (when (eq (frame-parameter frame
'minibuffer
) 'only
)
1471 (delete-frame frame
)))))
1473 ;; miscellaneous obsolescence declarations
1474 (define-obsolete-variable-alias 'delete-frame-hook
1475 'delete-frame-functions
"22.1")
1478 ;; Highlighting trailing whitespace.
1480 (make-variable-buffer-local 'show-trailing-whitespace
)
1485 (defgroup scrolling nil
1486 "Scrolling windows."
1490 (defvaralias 'automatic-hscrolling
'auto-hscroll-mode
)
1495 (defgroup cursor nil
1496 "Displaying text cursors."
1500 (defcustom blink-cursor-delay
0.5
1501 "Seconds of idle time after which cursor starts to blink."
1505 (defcustom blink-cursor-interval
0.5
1506 "Length of cursor blink interval in seconds."
1510 (defvar blink-cursor-idle-timer nil
1511 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
1512 The function `blink-cursor-start' is called when the timer fires.")
1514 (defvar blink-cursor-timer nil
1515 "Timer started from `blink-cursor-start'.
1516 This timer calls `blink-cursor-timer-function' every
1517 `blink-cursor-interval' seconds.")
1519 (defun blink-cursor-start ()
1520 "Timer function called from the timer `blink-cursor-idle-timer'.
1521 This starts the timer `blink-cursor-timer', which makes the cursor blink
1522 if appropriate. It also arranges to cancel that timer when the next
1523 command starts, by installing a pre-command hook."
1524 (when (null blink-cursor-timer
)
1525 ;; Set up the timer first, so that if this signals an error,
1526 ;; blink-cursor-end is not added to pre-command-hook.
1527 (setq blink-cursor-timer
1528 (run-with-timer blink-cursor-interval blink-cursor-interval
1529 'blink-cursor-timer-function
))
1530 (add-hook 'pre-command-hook
'blink-cursor-end
)
1531 (internal-show-cursor nil nil
)))
1533 (defun blink-cursor-timer-function ()
1534 "Timer function of timer `blink-cursor-timer'."
1535 (internal-show-cursor nil
(not (internal-show-cursor-p))))
1537 (defun blink-cursor-end ()
1538 "Stop cursor blinking.
1539 This is installed as a pre-command hook by `blink-cursor-start'.
1540 When run, it cancels the timer `blink-cursor-timer' and removes
1541 itself as a pre-command hook."
1542 (remove-hook 'pre-command-hook
'blink-cursor-end
)
1543 (internal-show-cursor nil t
)
1544 (when blink-cursor-timer
1545 (cancel-timer blink-cursor-timer
)
1546 (setq blink-cursor-timer nil
)))
1548 (define-minor-mode blink-cursor-mode
1549 "Toggle blinking cursor mode.
1550 With a numeric argument, turn blinking cursor mode on if ARG is positive,
1551 otherwise turn it off. When blinking cursor mode is enabled, the
1552 cursor of the selected window blinks.
1554 Note that this command is effective only when Emacs
1555 displays through a window system, because then Emacs does its own
1556 cursor display. On a text-only terminal, this is not implemented."
1557 :init-value
(not (or noninteractive
1559 (eq system-type
'ms-dos
)
1560 (not (memq window-system
'(x w32
)))))
1561 :initialize
'custom-initialize-delay
1564 (if blink-cursor-idle-timer
(cancel-timer blink-cursor-idle-timer
))
1565 (setq blink-cursor-idle-timer nil
)
1567 (when blink-cursor-mode
1569 ;;(internal-show-cursor nil nil)
1570 (setq blink-cursor-idle-timer
1571 (run-with-idle-timer blink-cursor-delay
1573 'blink-cursor-start
))))
1575 (define-obsolete-variable-alias 'blink-cursor
'blink-cursor-mode
"22.1")
1580 (define-key ctl-x-5-map
"2" 'make-frame-command
)
1581 (define-key ctl-x-5-map
"1" 'delete-other-frames
)
1582 (define-key ctl-x-5-map
"0" 'delete-frame
)
1583 (define-key ctl-x-5-map
"o" 'other-frame
)
1587 ;;; frame.el ends here