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")))
118 (defcustom pop-up-frame-function
119 (lambda () (make-frame pop-up-frame-alist
))
120 "Function used by `display-buffer' for creating a new frame.
121 This function is called with no arguments and should return a new
122 frame. The default value calls `make-frame' with the argument
123 `pop-up-frame-alist'."
127 (defcustom special-display-frame-alist
128 '((height .
14) (width .
80) (unsplittable . t
))
129 "Alist of parameters for special frames.
130 Special frames are used for buffers whose names are listed in
131 `special-display-buffer-names' and for buffers whose names match
132 one of the regular expressions in `special-display-regexps'.
134 This variable can be set in your init file, like this:
136 (setq special-display-frame-alist '((width . 80) (height . 20)))
138 These supersede the values given in `default-frame-alist'."
139 :type
'(repeat (cons :format
"%v"
140 (symbol :tag
"Parameter")
141 (sexp :tag
"Value")))
144 (defun special-display-popup-frame (buffer &optional args
)
145 "Display BUFFER and return the window chosen.
146 If BUFFER is already displayed in a visible or iconified frame,
147 raise that frame. Otherwise, display BUFFER in a new frame.
149 Optional argument ARGS is a list specifying additional
152 If ARGS is an alist, use it as a list of frame parameters. If
153 these parameters contain \(same-window . t), display BUFFER in
154 the selected window. If they contain \(same-frame . t), display
155 BUFFER in a window of the selected frame.
157 If ARGS is a list whose car is a symbol, use (car ARGS) as a
158 function to do the work. Pass it BUFFER as first argument,
159 and (cdr ARGS) as second."
160 (if (and args
(symbolp (car args
)))
161 (apply (car args
) buffer
(cdr args
))
162 (let ((window (get-buffer-window buffer
0)))
164 ;; If we have a window already, make it visible.
166 (let ((frame (window-frame window
)))
167 (make-frame-visible frame
)
170 ;; Reuse the current window if the user requested it.
171 (when (cdr (assq 'same-window args
))
173 (progn (switch-to-buffer buffer
) (selected-window))
175 ;; Stay on the same frame if requested.
176 (when (or (cdr (assq 'same-frame args
)) (cdr (assq 'same-window args
)))
177 (let* ((pop-up-windows t
)
179 special-display-buffer-names special-display-regexps
)
180 (display-buffer buffer
)))
181 ;; If no window yet, make one in a new frame.
183 (with-current-buffer buffer
184 (make-frame (append args special-display-frame-alist
)))))
185 (set-window-buffer (frame-selected-window frame
) buffer
)
186 (set-window-dedicated-p (frame-selected-window frame
) t
)
187 (frame-selected-window frame
))))))
189 (defun handle-delete-frame (event)
190 "Handle delete-frame events from the X server."
192 (let ((frame (posn-window (event-start event
)))
196 (and (frame-visible-p (car tail
))
197 (not (eq (car tail
) frame
))
199 (setq tail
(cdr tail
)))
201 (delete-frame frame t
)
202 ;; Gildea@x.org says it is ok to ask questions before terminating.
203 (save-buffers-kill-emacs))))
205 ;;;; Arrangement of frames at startup
207 ;; 1) Load the window system startup file from the lisp library and read the
208 ;; high-priority arguments (-q and the like). The window system startup
209 ;; file should create any frames specified in the window system defaults.
211 ;; 2) If no frames have been opened, we open an initial text frame.
213 ;; 3) Once the init file is done, we apply any newly set parameters
214 ;; in initial-frame-alist to the frame.
216 ;; These are now called explicitly at the proper times,
217 ;; since that is easier to understand.
218 ;; Actually using hooks within Emacs is bad for future maintenance. --rms.
219 ;; (add-hook 'before-init-hook 'frame-initialize)
220 ;; (add-hook 'window-setup-hook 'frame-notice-user-settings)
222 ;; If we create the initial frame, this is it.
223 (defvar frame-initial-frame nil
)
225 ;; Record the parameters used in frame-initialize to make the initial frame.
226 (defvar frame-initial-frame-alist
)
228 (defvar frame-initial-geometry-arguments nil
)
230 ;; startup.el calls this function before loading the user's init
231 ;; file - if there is no frame with a minibuffer open now, create
232 ;; one to display messages while loading the init file.
233 (defun frame-initialize ()
234 "Create an initial frame if necessary."
235 ;; Are we actually running under a window system at all?
236 (if (and initial-window-system
238 (not (eq initial-window-system
'pc
)))
240 ;; If there is no frame with a minibuffer besides the terminal
241 ;; frame, then we need to create the opening frame. Make sure
242 ;; it has a minibuffer, but let initial-frame-alist omit the
244 (or (delq terminal-frame
(minibuffer-frame-list))
246 (setq frame-initial-frame-alist
247 (append initial-frame-alist default-frame-alist nil
))
248 (or (assq 'horizontal-scroll-bars frame-initial-frame-alist
)
249 (setq frame-initial-frame-alist
250 (cons '(horizontal-scroll-bars . t
)
251 frame-initial-frame-alist
)))
252 (setq frame-initial-frame-alist
253 (cons (cons 'window-system initial-window-system
)
254 frame-initial-frame-alist
))
255 (setq default-minibuffer-frame
256 (setq frame-initial-frame
257 (make-frame frame-initial-frame-alist
)))
258 ;; Delete any specifications for window geometry parameters
259 ;; so that we won't reapply them in frame-notice-user-settings.
260 ;; It would be wrong to reapply them then,
261 ;; because that would override explicit user resizing.
262 (setq initial-frame-alist
263 (frame-remove-geometry-params initial-frame-alist
))))
264 ;; Copy the environment of the Emacs process into the new frame.
265 (set-frame-parameter frame-initial-frame
'environment
266 (frame-parameter terminal-frame
'environment
))
267 ;; At this point, we know that we have a frame open, so we
268 ;; can delete the terminal frame.
269 (delete-frame terminal-frame
)
270 (setq terminal-frame nil
))))
272 (defvar frame-notice-user-settings t
273 "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
275 (declare-function tool-bar-mode
"tool-bar" (&optional arg
))
277 ;; startup.el calls this function after loading the user's init
278 ;; file. Now default-frame-alist and initial-frame-alist contain
279 ;; information to which we must react; do what needs to be done.
280 (defun frame-notice-user-settings ()
281 "Act on user's init file settings of frame parameters.
282 React to settings of `initial-frame-alist',
283 `window-system-default-frame-alist' and `default-frame-alist'
284 there (in decreasing order of priority)."
285 ;; Creating and deleting frames may shift the selected frame around,
286 ;; and thus the current buffer. Protect against that. We don't
287 ;; want to use save-excursion here, because that may also try to set
288 ;; the buffer of the selected window, which fails when the selected
289 ;; window is the minibuffer.
290 (let ((old-buffer (current-buffer))
291 (window-system-frame-alist
292 (cdr (assq initial-window-system
293 window-system-default-frame-alist
))))
295 (when (and frame-notice-user-settings
296 (null frame-initial-frame
))
297 ;; This case happens when we don't have a window system, and
298 ;; also for MS-DOS frames.
299 (let ((parms (frame-parameters)))
300 ;; Don't change the frame names.
301 (setq parms
(delq (assq 'name parms
) parms
))
302 ;; Can't modify the minibuffer parameter, so don't try.
303 (setq parms
(delq (assq 'minibuffer parms
) parms
))
304 (modify-frame-parameters
306 (if initial-window-system
308 ;; initial-frame-alist and default-frame-alist were already
309 ;; applied in pc-win.el.
310 (append initial-frame-alist window-system-frame-alist
311 default-frame-alist parms nil
)))
312 (if (null initial-window-system
) ;; MS-DOS does this differently in pc-win.el
313 (let ((newparms (frame-parameters))
314 (frame (selected-frame)))
315 (tty-handle-reverse-video frame newparms
)
316 ;; If we changed the background color, we need to update
317 ;; the background-mode parameter, and maybe some faces,
319 (when (assq 'background-color newparms
)
320 (unless (or (assq 'background-mode initial-frame-alist
)
321 (assq 'background-mode default-frame-alist
))
322 (frame-set-background-mode frame
))
323 (face-set-after-frame-default frame
))))))
325 ;; If the initial frame is still around, apply initial-frame-alist
326 ;; and default-frame-alist to it.
327 (when (frame-live-p frame-initial-frame
)
329 ;; When tool-bar has been switched off, correct the frame size
330 ;; by the lines added in x-create-frame for the tool-bar and
331 ;; switch `tool-bar-mode' off.
332 (when (display-graphic-p)
333 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist
)
334 (assq 'tool-bar-lines window-system-frame-alist
)
335 (assq 'tool-bar-lines default-frame-alist
))))
336 (when (and tool-bar-originally-present
337 (or (null tool-bar-lines
)
338 (null (cdr tool-bar-lines
))
339 (eq 0 (cdr tool-bar-lines
))))
340 (let* ((char-height (frame-char-height frame-initial-frame
))
341 (image-height tool-bar-images-pixel-height
)
342 (margin (cond ((and (consp tool-bar-button-margin
)
343 (integerp (cdr tool-bar-button-margin
))
344 (> tool-bar-button-margin
0))
345 (cdr tool-bar-button-margin
))
346 ((and (integerp tool-bar-button-margin
)
347 (> tool-bar-button-margin
0))
348 tool-bar-button-margin
)
350 (relief (if (and (integerp tool-bar-button-relief
)
351 (> tool-bar-button-relief
0))
352 tool-bar-button-relief
3))
353 (lines (/ (+ image-height
358 (height (frame-parameter frame-initial-frame
'height
))
359 (newparms (list (cons 'height
(- height lines
))))
360 (initial-top (cdr (assq 'top
361 frame-initial-geometry-arguments
)))
362 (top (frame-parameter frame-initial-frame
'top
)))
363 (when (and (consp initial-top
) (eq '-
(car initial-top
)))
365 (cond ((and (consp top
)
369 (* lines char-height
))))
374 (* lines char-height
))))
375 (t (+ top
(* lines char-height
))))))
378 `((top .
,adjusted-top
))
380 (modify-frame-parameters frame-initial-frame newparms
)
381 (tool-bar-mode -
1)))))
383 ;; The initial frame we create above always has a minibuffer.
384 ;; If the user wants to remove it, or make it a minibuffer-only
385 ;; frame, then we'll have to delete the current frame and make a
386 ;; new one; you can't remove or add a root window to/from an
389 ;; NOTE: default-frame-alist was nil when we created the
390 ;; existing frame. We need to explicitly include
391 ;; default-frame-alist in the parameters of the screen we
392 ;; create here, so that its new value, gleaned from the user's
393 ;; .emacs file, will be applied to the existing screen.
394 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist
)
395 (assq 'minibuffer window-system-frame-alist
)
396 (assq 'minibuffer default-frame-alist
)
399 ;; Create the new frame.
401 ;; If the frame isn't visible yet, wait till it is.
402 ;; If the user has to position the window,
403 ;; Emacs doesn't know its real position until
404 ;; the frame is seen to be visible.
405 (while (not (cdr (assq 'visibility
406 (frame-parameters frame-initial-frame
))))
408 (setq parms
(frame-parameters frame-initial-frame
))
410 ;; Get rid of `name' unless it was specified explicitly before.
411 (or (assq 'name frame-initial-frame-alist
)
412 (setq parms
(delq (assq 'name parms
) parms
)))
413 ;; An explicit parent-id is a request to XEmbed the frame.
414 (or (assq 'parent-id frame-initial-frame-alist
)
415 (setq parms
(delq (assq 'parent-id parms
) parms
)))
417 (setq parms
(append initial-frame-alist
418 window-system-frame-alist
423 ;; Get rid of `reverse', because that was handled
424 ;; when we first made the frame.
425 (setq parms
(cons '(reverse) (delq (assq 'reverse parms
) parms
)))
427 (if (assq 'height frame-initial-geometry-arguments
)
428 (setq parms
(assq-delete-all 'height parms
)))
429 (if (assq 'width frame-initial-geometry-arguments
)
430 (setq parms
(assq-delete-all 'width parms
)))
431 (if (assq 'left frame-initial-geometry-arguments
)
432 (setq parms
(assq-delete-all 'left parms
)))
433 (if (assq 'top frame-initial-geometry-arguments
)
434 (setq parms
(assq-delete-all 'top parms
)))
437 ;; Use the geometry args that created the existing
438 ;; frame, rather than the parms we get for it.
439 (append frame-initial-geometry-arguments
440 '((user-size . t
) (user-position . t
))
442 ;; The initial frame, which we are about to delete, may be
443 ;; the only frame with a minibuffer. If it is, create a
445 (or (delq frame-initial-frame
(minibuffer-frame-list))
446 (make-initial-minibuffer-frame nil
))
448 ;; If the initial frame is serving as a surrogate
449 ;; minibuffer frame for any frames, we need to wean them
450 ;; onto a new frame. The default-minibuffer-frame
451 ;; variable must be handled similarly.
452 (let ((users-of-initial
455 (and (not (eq frame frame-initial-frame
))
457 (minibuffer-window frame
))
458 frame-initial-frame
))))))
459 (if (or users-of-initial
460 (eq default-minibuffer-frame frame-initial-frame
))
462 ;; Choose an appropriate frame. Prefer frames which
463 ;; are only minibuffers.
464 (let* ((new-surrogate
466 (or (filtered-frame-list
468 (eq (cdr (assq 'minibuffer
469 (frame-parameters frame
)))
471 (minibuffer-frame-list))))
472 (new-minibuffer (minibuffer-window new-surrogate
)))
474 (if (eq default-minibuffer-frame frame-initial-frame
)
475 (setq default-minibuffer-frame new-surrogate
))
477 ;; Wean the frames using frame-initial-frame as
478 ;; their minibuffer frame.
479 (dolist (frame users-of-initial
)
480 (modify-frame-parameters
481 frame
(list (cons 'minibuffer new-minibuffer
)))))))
483 ;; Redirect events enqueued at this frame to the new frame.
484 ;; Is this a good idea?
485 (redirect-frame-focus frame-initial-frame new
)
487 ;; Finally, get rid of the old frame.
488 (delete-frame frame-initial-frame t
))
490 ;; Otherwise, we don't need all that rigamarole; just apply
491 ;; the new parameters.
492 (let (newparms allparms tail
)
493 (setq allparms
(append initial-frame-alist
494 window-system-frame-alist
495 default-frame-alist nil
))
496 (if (assq 'height frame-initial-geometry-arguments
)
497 (setq allparms
(assq-delete-all 'height allparms
)))
498 (if (assq 'width frame-initial-geometry-arguments
)
499 (setq allparms
(assq-delete-all 'width allparms
)))
500 (if (assq 'left frame-initial-geometry-arguments
)
501 (setq allparms
(assq-delete-all 'left allparms
)))
502 (if (assq 'top frame-initial-geometry-arguments
)
503 (setq allparms
(assq-delete-all 'top allparms
)))
505 ;; Find just the parms that have changed since we first
506 ;; made this frame. Those are the ones actually set by
507 ;; the init file. For those parms whose values we already knew
508 ;; (such as those spec'd by command line options)
509 ;; it is undesirable to specify the parm again
510 ;; once the user has seen the frame and been able to alter it
514 (setq oldval
(assq (car entry
) frame-initial-frame-alist
))
515 (setq newval
(cdr (assq (car entry
) allparms
)))
516 (or (and oldval
(eq (cdr oldval
) newval
))
518 (cons (cons (car entry
) newval
) newparms
)))))
519 (setq newparms
(nreverse newparms
))
521 (let ((new-bg (assq 'background-color newparms
)))
522 ;; If the `background-color' parameter is changed, apply
523 ;; it first, then make sure that the `background-mode'
524 ;; parameter and other faces are updated, before applying
525 ;; the other parameters.
527 (modify-frame-parameters frame-initial-frame
529 (unless (assq 'background-mode newparms
)
530 (frame-set-background-mode frame-initial-frame
))
531 (face-set-after-frame-default frame-initial-frame
)
532 (setq newparms
(delq new-bg newparms
)))
533 (modify-frame-parameters frame-initial-frame newparms
)))))
535 ;; Restore the original buffer.
536 (set-buffer old-buffer
)
538 ;; Make sure the initial frame can be GC'd if it is ever deleted.
539 ;; Make sure frame-notice-user-settings does nothing if called twice.
540 (setq frame-notice-user-settings nil
)
541 (setq frame-initial-frame nil
)))
543 (defun make-initial-minibuffer-frame (display)
544 (let ((parms (append minibuffer-frame-alist
'((minibuffer . only
)))))
546 (make-frame-on-display display parms
)
547 (make-frame parms
))))
549 ;;;; Creation of additional frames, and other frame miscellanea
551 (defun modify-all-frames-parameters (alist)
552 "Modify all current and future frames' parameters according to ALIST.
553 This changes `default-frame-alist' and possibly `initial-frame-alist'.
554 Furthermore, this function removes all parameters in ALIST from
555 `window-system-default-frame-alist'.
556 See help of `modify-frame-parameters' for more information."
557 (dolist (frame (frame-list))
558 (modify-frame-parameters frame alist
))
560 (dolist (pair alist
) ;; conses to add/replace
561 ;; initial-frame-alist needs setting only when
562 ;; frame-notice-user-settings is true.
563 (and frame-notice-user-settings
564 (setq initial-frame-alist
565 (assq-delete-all (car pair
) initial-frame-alist
)))
566 (setq default-frame-alist
567 (assq-delete-all (car pair
) default-frame-alist
))
568 ;; Remove any similar settings from the window-system specific
569 ;; parameters---they would override default-frame-alist.
570 (dolist (w window-system-default-frame-alist
)
571 (setcdr w
(assq-delete-all (car pair
) (cdr w
)))))
573 (and frame-notice-user-settings
574 (setq initial-frame-alist
(append initial-frame-alist alist
)))
575 (setq default-frame-alist
(append default-frame-alist alist
)))
577 (defun get-other-frame ()
578 "Return some frame other than the current frame.
579 Create one if necessary. Note that the minibuffer frame, if separate,
580 is not considered (see `next-frame')."
581 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
583 (next-frame (selected-frame)))))
586 (defun next-multiframe-window ()
587 "Select the next window, regardless of which frame it is on."
589 (select-window (next-window (selected-window)
590 (> (minibuffer-depth) 0)
592 (select-frame-set-input-focus (selected-frame)))
594 (defun previous-multiframe-window ()
595 "Select the previous window, regardless of which frame it is on."
597 (select-window (previous-window (selected-window)
598 (> (minibuffer-depth) 0)
600 (select-frame-set-input-focus (selected-frame)))
602 (declare-function x-initialize-window-system
"term/x-win" ())
603 (declare-function ns-initialize-window-system
"term/ns-win" ())
604 (defvar x-display-name
) ; term/x-win
606 (defun make-frame-on-display (display &optional parameters
)
607 "Make a frame on display DISPLAY.
608 The optional argument PARAMETERS specifies additional frame parameters."
609 (interactive "sMake frame on display: ")
610 (cond ((featurep 'ns
)
611 (when (and (boundp 'ns-initialized
) (not ns-initialized
))
612 (setq x-display-name display
)
613 (ns-initialize-window-system))
614 (make-frame `((window-system . ns
)
615 (display .
,display
) .
,parameters
)))
616 ((eq system-type
'windows-nt
)
617 ;; On Windows, ignore DISPLAY.
618 (make-frame parameters
))
620 (unless (string-match-p "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display
)
621 (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
622 (when (and (boundp 'x-initialized
) (not x-initialized
))
623 (setq x-display-name display
)
624 (x-initialize-window-system))
625 (make-frame `((window-system . x
)
626 (display .
,display
) .
,parameters
)))))
628 (declare-function x-close-connection
"xfns.c" (terminal))
630 (defun close-display-connection (display)
631 "Close the connection to a display, deleting all its associated frames.
632 For DISPLAY, specify either a frame or a display name (a string).
633 If DISPLAY is nil, that stands for the selected frame's display."
636 (let* ((default (frame-parameter nil
'display
))
637 (display (completing-read
638 (format "Close display (default %s): " default
)
640 (mapcar (lambda (frame)
641 (frame-parameter frame
'display
))
645 (if (zerop (length display
)) default display
))))
646 (let ((frames (delq nil
647 (mapcar (lambda (frame)
649 (frame-parameter frame
'display
))
652 (if (and (consp frames
)
653 (not (y-or-n-p (if (cdr frames
)
654 (format "Delete %s frames? " (length frames
))
655 (format "Delete %s ? " (car frames
))))))
657 (mapc 'delete-frame frames
)
658 (x-close-connection display
))))
660 (defun make-frame-command ()
661 "Make a new frame, on the same terminal as the selected frame.
662 If the terminal is a text-only terminal, this also selects the
665 (if (display-graphic-p)
667 (select-frame (make-frame))))
669 (defvar before-make-frame-hook nil
670 "Functions to run before a frame is created.")
672 (defvar after-make-frame-functions nil
673 "Functions to run after a frame is created.
674 The functions are run with one arg, the newly created frame.")
676 (defvar after-setting-font-hook nil
677 "Functions to run after a frame's font has been changed.")
679 ;; Alias, kept temporarily.
680 (define-obsolete-function-alias 'new-frame
'make-frame
"22.1")
682 (defvar frame-inherited-parameters
'()
683 ;; FIXME: Shouldn't we add `font' here as well?
684 "Parameters `make-frame' copies from the `selected-frame' to the new frame.")
686 (defun make-frame (&optional parameters
)
687 "Return a newly created frame displaying the current buffer.
688 Optional argument PARAMETERS is an alist of frame parameters for
689 the new frame. Each element of PARAMETERS should have the
690 form (NAME . VALUE), for example:
692 (name . STRING) The frame should be named STRING.
694 (width . NUMBER) The frame should be NUMBER characters in width.
695 (height . NUMBER) The frame should be NUMBER text lines high.
697 You cannot specify either `width' or `height', you must specify
700 (minibuffer . t) The frame should have a minibuffer.
701 (minibuffer . nil) The frame should have no minibuffer.
702 (minibuffer . only) The frame should contain only a minibuffer.
703 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
705 (window-system . nil) The frame should be displayed on a terminal device.
706 (window-system . x) The frame should be displayed in an X window.
708 (terminal . TERMINAL) The frame should use the terminal object TERMINAL.
710 In addition, any parameter specified in `default-frame-alist',
711 but not present in PARAMETERS, is applied.
713 Before creating the frame (via `frame-creation-function-alist'),
714 this function runs the hook `before-make-frame-hook'. After
715 creating the frame, it runs the hook `after-make-frame-functions'
716 with one arg, the newly created frame.
718 On graphical displays, this function does not itself make the new
719 frame the selected frame. However, the window system may select
720 the new frame according to its own rules."
723 ((assq 'terminal parameters
)
724 (let ((type (terminal-live-p (cdr (assq 'terminal parameters
)))))
727 ((eq type nil
) (error "Terminal %s does not exist"
728 (cdr (assq 'terminal parameters
))))
730 ((assq 'window-system parameters
)
731 (cdr (assq 'window-system parameters
)))
733 (frame-creation-function (cdr (assq w frame-creation-function-alist
)))
734 (oldframe (selected-frame))
737 (unless frame-creation-function
738 (error "Don't know how to create a frame on window system %s" w
))
739 ;; Add parameters from `window-system-default-frame-alist'.
740 (dolist (p (cdr (assq w window-system-default-frame-alist
)))
741 (unless (assq (car p
) params
)
743 ;; Add parameters from `default-frame-alist'.
744 (dolist (p default-frame-alist
)
745 (unless (assq (car p
) params
)
747 ;; Now make the frame.
748 (run-hooks 'before-make-frame-hook
)
749 (setq frame
(funcall frame-creation-function params
))
750 (normal-erase-is-backspace-setup-frame frame
)
751 ;; Inherit the original frame's parameters.
752 (dolist (param frame-inherited-parameters
)
753 (unless (assq param parameters
) ;Overridden by explicit parameters.
754 (let ((val (frame-parameter oldframe param
)))
755 (when val
(set-frame-parameter frame param val
)))))
756 (run-hook-with-args 'after-make-frame-functions frame
)
759 (defun filtered-frame-list (predicate)
760 "Return a list of all live frames which satisfy PREDICATE."
761 (let* ((frames (frame-list))
763 (while (consp frames
)
764 (unless (funcall predicate
(car frames
))
766 (setq frames
(cdr frames
)))
769 (defun minibuffer-frame-list ()
770 "Return a list of all frames with their own minibuffers."
773 (eq frame
(window-frame (minibuffer-window frame
))))))
775 ;; Used to be called `terminal-id' in termdev.el.
776 (defun get-device-terminal (device)
777 "Return the terminal corresponding to DEVICE.
778 DEVICE can be a terminal, a frame, nil (meaning the selected frame's terminal),
779 the name of an X display device (HOST.SERVER.SCREEN) or a tty device file."
781 ((or (null device
) (framep device
))
782 (frame-terminal device
))
784 (let ((f (car (filtered-frame-list
786 (or (equal (frame-parameter frame
'display
) device
)
787 (equal (frame-parameter frame
'tty
) device
)))))))
788 (or f
(error "Display %s does not exist" device
))
790 ((terminal-live-p device
) device
)
792 (error "Invalid argument %s in `get-device-terminal'" device
))))
794 (defun frames-on-display-list (&optional device
)
795 "Return a list of all frames on DEVICE.
797 DEVICE should be a terminal, a frame,
798 or a name of an X display or tty (a string of the form
801 If DEVICE is omitted or nil, it defaults to the selected
802 frame's terminal device."
803 (let* ((terminal (get-device-terminal device
))
804 (func #'(lambda (frame)
805 (eq (frame-terminal frame
) terminal
))))
806 (filtered-frame-list func
)))
808 (defun framep-on-display (&optional terminal
)
809 "Return the type of frames on TERMINAL.
810 TERMINAL may be a terminal id, a display name or a frame. If it
811 is a frame, its type is returned. If TERMINAL is omitted or nil,
812 it defaults to the selected frame's terminal device. All frames
813 on a given display are of the same type."
814 (or (terminal-live-p terminal
)
816 (framep (car (frames-on-display-list terminal
)))))
818 (defun frame-remove-geometry-params (param-list)
819 "Return the parameter list PARAM-LIST, but with geometry specs removed.
820 This deletes all bindings in PARAM-LIST for `top', `left', `width',
821 `height', `user-size' and `user-position' parameters.
822 Emacs uses this to avoid overriding explicit moves and resizings from
823 the user during startup."
824 (setq param-list
(cons nil param-list
))
825 (let ((tail param-list
))
826 (while (consp (cdr tail
))
827 (if (and (consp (car (cdr tail
)))
828 (memq (car (car (cdr tail
)))
829 '(height width top left user-position user-size
)))
831 (setq frame-initial-geometry-arguments
832 (cons (car (cdr tail
)) frame-initial-geometry-arguments
))
833 (setcdr tail
(cdr (cdr tail
))))
834 (setq tail
(cdr tail
)))))
835 (setq frame-initial-geometry-arguments
836 (nreverse frame-initial-geometry-arguments
))
839 (declare-function x-focus-frame
"xfns.c" (frame))
841 (defun select-frame-set-input-focus (frame)
842 "Select FRAME, raise it, and set input focus, if possible.
843 If `mouse-autoselect-window' is non-nil, also move mouse pointer
844 to FRAME's selected window. Otherwise, if `focus-follows-mouse'
845 is non-nil, move mouse cursor to FRAME."
848 ;; Ensure, if possible, that FRAME gets input focus.
849 (when (memq (window-system frame
) '(x w32 ns
))
850 (x-focus-frame frame
))
851 ;; Move mouse cursor if necessary.
853 (mouse-autoselect-window
854 (let ((edges (window-inside-edges (frame-selected-window frame
))))
855 ;; Move mouse cursor into FRAME's selected window to avoid that
856 ;; Emacs mouse-autoselects another window.
857 (set-mouse-position frame
(nth 2 edges
) (nth 1 edges
))))
859 ;; Move mouse cursor into FRAME to avoid that another frame gets
860 ;; selected by the window manager.
861 (set-mouse-position frame
(1- (frame-width frame
)) 0))))
863 (defun other-frame (arg)
864 "Select the ARGth different visible frame on current display, and raise it.
865 All frames are arranged in a cyclic order.
866 This command selects the frame ARG steps away in that order.
867 A negative ARG moves in the opposite order.
869 To make this command work properly, you must tell Emacs
870 how the system (or the window manager) generally handles
871 focus-switching between windows. If moving the mouse onto a window
872 selects it (gives it focus), set `focus-follows-mouse' to t.
873 Otherwise, that variable should be nil."
875 (let ((frame (selected-frame)))
877 (setq frame
(next-frame frame
))
878 (while (not (eq (frame-visible-p frame
) t
))
879 (setq frame
(next-frame frame
)))
882 (setq frame
(previous-frame frame
))
883 (while (not (eq (frame-visible-p frame
) t
))
884 (setq frame
(previous-frame frame
)))
886 (select-frame-set-input-focus frame
)))
888 (defun iconify-or-deiconify-frame ()
889 "Iconify the selected frame, or deiconify if it's currently an icon."
891 (if (eq (cdr (assq 'visibility
(frame-parameters))) t
)
893 (make-frame-visible)))
895 (defun suspend-frame ()
896 "Do whatever is right to suspend the current frame.
897 Calls `suspend-emacs' if invoked from the controlling tty device,
898 `suspend-tty' from a secondary tty device, and
899 `iconify-or-deiconify-frame' from an X frame."
901 (let ((type (framep (selected-frame))))
903 ((memq type
'(x ns w32
)) (iconify-or-deiconify-frame))
905 (if (controlling-tty-p)
908 (t (suspend-emacs)))))
910 (defun make-frame-names-alist ()
911 ;; Only consider the frames on the same display.
912 (let* ((current-frame (selected-frame))
915 (cons (frame-parameter current-frame
'name
) current-frame
) nil
))
916 (frame (next-frame nil
0)))
917 (while (not (eq frame current-frame
))
919 (push (cons (frame-parameter frame
'name
) frame
) falist
)
920 (setq frame
(next-frame frame
0))))
923 (defvar frame-name-history nil
)
924 (defun select-frame-by-name (name)
925 "Select the frame on the current terminal whose name is NAME and raise it.
926 If there is no frame by that name, signal an error."
928 (let* ((frame-names-alist (make-frame-names-alist))
929 (default (car (car frame-names-alist
)))
930 (input (completing-read
931 (format "Select Frame (default %s): " default
)
932 frame-names-alist nil t nil
'frame-name-history
)))
933 (if (= (length input
) 0)
936 (let* ((frame-names-alist (make-frame-names-alist))
937 (frame (cdr (assoc name frame-names-alist
))))
939 (select-frame-set-input-focus frame
)
940 (error "There is no frame named `%s'" name
))))
942 ;;;; Frame configurations
944 (defun current-frame-configuration ()
945 "Return a list describing the positions and states of all frames.
946 Its car is `frame-configuration'.
947 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
949 FRAME is a frame object,
950 ALIST is an association list specifying some of FRAME's parameters, and
951 WINDOW-CONFIG is a window configuration object for FRAME."
952 (cons 'frame-configuration
953 (mapcar (lambda (frame)
955 (frame-parameters frame
)
956 (current-window-configuration frame
)))
959 (defun set-frame-configuration (configuration &optional nodelete
)
960 "Restore the frames to the state described by CONFIGURATION.
961 Each frame listed in CONFIGURATION has its position, size, window
962 configuration, and other parameters set as specified in CONFIGURATION.
963 However, this function does not restore deleted frames.
965 Ordinarily, this function deletes all existing frames not
966 listed in CONFIGURATION. But if optional second argument NODELETE
967 is given and non-nil, the unwanted frames are iconified instead."
968 (or (frame-configuration-p configuration
)
969 (signal 'wrong-type-argument
970 (list 'frame-configuration-p configuration
)))
971 (let ((config-alist (cdr configuration
))
973 (dolist (frame (frame-list))
974 (let ((parameters (assq frame config-alist
)))
977 (modify-frame-parameters
979 ;; Since we can't set a frame's minibuffer status,
980 ;; we might as well omit the parameter altogether.
981 (let* ((parms (nth 1 parameters
))
982 (mini (assq 'minibuffer parms
))
983 (name (assq 'name parms
))
984 (explicit-name (cdr (assq 'explicit-name parms
))))
985 (when mini
(setq parms
(delq mini parms
)))
986 ;; Leave name in iff it was set explicitly.
987 ;; This should fix the behavior reported in
988 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg01632.html
989 (when (and name
(not explicit-name
))
990 (setq parms
(delq name parms
)))
992 (set-window-configuration (nth 2 parameters
)))
993 (setq frames-to-delete
(cons frame frames-to-delete
)))))
995 ;; Note: making frames invisible here was tried
996 ;; but led to some strange behavior--each time the frame
997 ;; was made visible again, the window manager asked afresh
998 ;; for where to put it.
1003 ;;;; Convenience functions for accessing and interactively changing
1004 ;;;; frame parameters.
1006 (defun frame-height (&optional frame
)
1007 "Return number of lines available for display on FRAME.
1008 If FRAME is omitted, describe the currently selected frame.
1009 Exactly what is included in the return value depends on the
1010 window-system and toolkit in use - see `frame-pixel-height' for
1011 more details. The lines are in units of the default font height.
1013 The result is roughly related to the frame pixel height via
1014 height in pixels = height in lines * `frame-char-height'.
1015 However, this is only approximate, and is complicated e.g. by the
1016 fact that individual window lines and menu bar lines can have
1017 differing font heights."
1018 (cdr (assq 'height
(frame-parameters frame
))))
1020 (defun frame-width (&optional frame
)
1021 "Return number of columns available for display on FRAME.
1022 If FRAME is omitted, describe the currently selected frame."
1023 (cdr (assq 'width
(frame-parameters frame
))))
1025 (declare-function x-list-fonts
"xfaces.c"
1026 (pattern &optional face frame maximum width
))
1028 (define-obsolete-function-alias 'set-default-font
'set-frame-font
"23.1")
1029 (defun set-frame-font (font-name &optional keep-size
)
1030 "Set the font of the selected frame to FONT-NAME.
1031 When called interactively, prompt for the name of the font to use.
1032 To get the frame's current default font, use `frame-parameters'.
1034 The default behavior is to keep the numbers of lines and columns in
1035 the frame, thus may change its pixel size. If optional KEEP-SIZE is
1036 non-nil (interactively, prefix argument) the current frame size (in
1037 pixels) is kept by adjusting the numbers of the lines and columns."
1039 (let* ((completion-ignore-case t
)
1040 (font (completing-read "Font name: "
1041 ;; x-list-fonts will fail with an error
1042 ;; if this frame doesn't support fonts.
1043 (x-list-fonts "*" nil
(selected-frame))
1045 (frame-parameter nil
'font
))))
1046 (list font current-prefix-arg
)))
1049 (setq fht
(* (frame-parameter nil
'height
) (frame-char-height))
1050 fwd
(* (frame-parameter nil
'width
) (frame-char-width))))
1051 (modify-frame-parameters (selected-frame)
1052 (list (cons 'font font-name
)))
1054 (modify-frame-parameters
1056 (list (cons 'height
(round fht
(frame-char-height)))
1057 (cons 'width
(round fwd
(frame-char-width)))))))
1058 (run-hooks 'after-setting-font-hook
'after-setting-font-hooks
))
1060 (defun set-frame-parameter (frame parameter value
)
1061 "Set frame parameter PARAMETER to VALUE on FRAME.
1062 If FRAME is nil, it defaults to the selected frame.
1063 See `modify-frame-parameters'."
1064 (modify-frame-parameters frame
(list (cons parameter value
))))
1066 (defun set-background-color (color-name)
1067 "Set the background color of the selected frame to COLOR-NAME.
1068 When called interactively, prompt for the name of the color to use.
1069 To get the frame's current background color, use `frame-parameters'."
1070 (interactive (list (read-color "Background color: ")))
1071 (modify-frame-parameters (selected-frame)
1072 (list (cons 'background-color color-name
)))
1074 (face-set-after-frame-default (selected-frame))))
1076 (defun set-foreground-color (color-name)
1077 "Set the foreground color of the selected frame to COLOR-NAME.
1078 When called interactively, prompt for the name of the color to use.
1079 To get the frame's current foreground color, use `frame-parameters'."
1080 (interactive (list (read-color "Foreground color: ")))
1081 (modify-frame-parameters (selected-frame)
1082 (list (cons 'foreground-color color-name
)))
1084 (face-set-after-frame-default (selected-frame))))
1086 (defun set-cursor-color (color-name)
1087 "Set the text cursor color of the selected frame to COLOR-NAME.
1088 When called interactively, prompt for the name of the color to use.
1089 To get the frame's current cursor color, use `frame-parameters'."
1090 (interactive (list (read-color "Cursor color: ")))
1091 (modify-frame-parameters (selected-frame)
1092 (list (cons 'cursor-color color-name
))))
1094 (defun set-mouse-color (color-name)
1095 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
1096 When called interactively, prompt for the name of the color to use.
1097 To get the frame's current mouse color, use `frame-parameters'."
1098 (interactive (list (read-color "Mouse color: ")))
1099 (modify-frame-parameters (selected-frame)
1100 (list (cons 'mouse-color
1102 (cdr (assq 'mouse-color
1103 (frame-parameters))))))))
1105 (defun set-border-color (color-name)
1106 "Set the color of the border of the selected frame to COLOR-NAME.
1107 When called interactively, prompt for the name of the color to use.
1108 To get the frame's current border color, use `frame-parameters'."
1109 (interactive (list (read-color "Border color: ")))
1110 (modify-frame-parameters (selected-frame)
1111 (list (cons 'border-color color-name
))))
1113 (define-minor-mode auto-raise-mode
1114 "Toggle whether or not the selected frame should auto-raise.
1115 With ARG, turn auto-raise mode on if and only if ARG is positive.
1116 Note that this controls Emacs's own auto-raise feature.
1117 Some window managers allow you to enable auto-raise for certain windows.
1118 You can use that for Emacs windows if you wish, but if you do,
1119 that is beyond the control of Emacs and this command has no effect on it."
1120 :variable
(frame-parameter nil
'auto-raise
)
1121 (if (frame-parameter nil
'auto-raise
)
1124 (define-minor-mode auto-lower-mode
1125 "Toggle whether or not the selected frame should auto-lower.
1126 With ARG, turn auto-lower mode on if and only if ARG is positive.
1127 Note that this controls Emacs's own auto-lower feature.
1128 Some window managers allow you to enable auto-lower for certain windows.
1129 You can use that for Emacs windows if you wish, but if you do,
1130 that is beyond the control of Emacs and this command has no effect on it."
1131 :variable
(frame-parameter nil
'auto-lower
))
1133 (defun set-frame-name (name)
1134 "Set the name of the selected frame to NAME.
1135 When called interactively, prompt for the name of the frame.
1136 The frame name is displayed on the modeline if the terminal displays only
1137 one frame, otherwise the name is displayed on the frame's caption bar."
1138 (interactive "sFrame name: ")
1139 (modify-frame-parameters (selected-frame)
1140 (list (cons 'name name
))))
1142 (defun frame-current-scroll-bars (&optional frame
)
1143 "Return the current scroll-bar settings in frame FRAME.
1144 Value is a cons (VERTICAL . HORIZ0NTAL) where VERTICAL specifies the
1145 current location of the vertical scroll-bars (left, right, or nil),
1146 and HORIZONTAL specifies the current location of the horizontal scroll
1147 bars (top, bottom, or nil)."
1148 (let ((vert (frame-parameter frame
'vertical-scroll-bars
))
1150 (unless (memq vert
'(left right nil
))
1151 (setq vert default-frame-scroll-bars
))
1154 ;;;; Frame/display capabilities.
1155 (defun selected-terminal ()
1156 "Return the terminal that is now selected."
1157 (frame-terminal (selected-frame)))
1159 (declare-function msdos-mouse-p
"dosfns.c")
1161 (defun display-mouse-p (&optional display
)
1162 "Return non-nil if DISPLAY has a mouse available.
1163 DISPLAY can be a display name, a frame, or nil (meaning the selected
1165 (let ((frame-type (framep-on-display display
)))
1167 ((eq frame-type
'pc
)
1169 ((eq system-type
'windows-nt
)
1171 (> w32-num-mouse-buttons
0)))
1172 ((memq frame-type
'(x ns
))
1173 t
) ;; We assume X and NeXTstep *always* have a pointing device
1175 (or (and (featurep 'xt-mouse
)
1177 ;; t-mouse is distributed with the GPM package. It doesn't have
1179 (featurep 't-mouse
))))))
1181 (defun display-popup-menus-p (&optional display
)
1182 "Return non-nil if popup menus are supported on DISPLAY.
1183 DISPLAY can be a display name, a frame, or nil (meaning the selected
1185 Support for popup menus requires that the mouse be available."
1187 (let ((frame-type (framep-on-display display
)))
1188 (memq frame-type
'(x w32 pc ns
)))
1189 (display-mouse-p display
)))
1191 (defun display-graphic-p (&optional display
)
1192 "Return non-nil if DISPLAY is a graphic display.
1193 Graphical displays are those which are capable of displaying several
1194 frames and several different fonts at once. This is true for displays
1195 that use a window system such as X, and false for text-only terminals.
1196 DISPLAY can be a display name, a frame, or nil (meaning the selected
1198 (not (null (memq (framep-on-display display
) '(x w32 ns
)))))
1200 (defun display-images-p (&optional display
)
1201 "Return non-nil if DISPLAY can display images.
1203 DISPLAY can be a display name, a frame, or nil (meaning the selected
1205 (and (display-graphic-p display
)
1206 (fboundp 'image-mask-p
)
1207 (fboundp 'image-size
)))
1209 (defalias 'display-multi-frame-p
'display-graphic-p
)
1210 (defalias 'display-multi-font-p
'display-graphic-p
)
1212 (defun display-selections-p (&optional display
)
1213 "Return non-nil if DISPLAY supports selections.
1214 A selection is a way to transfer text or other data between programs
1215 via special system buffers called `selection' or `clipboard'.
1216 DISPLAY can be a display name, a frame, or nil (meaning the selected
1218 (let ((frame-type (framep-on-display display
)))
1220 ((eq frame-type
'pc
)
1221 ;; MS-DOG frames support selections when Emacs runs inside
1222 ;; the Windows' DOS Box.
1224 (not (null dos-windows-version
))))
1225 ((memq frame-type
'(x w32 ns
))
1230 (declare-function x-display-screens
"xfns.c" (&optional terminal
))
1232 (defun display-screens (&optional display
)
1233 "Return the number of screens associated with DISPLAY."
1234 (let ((frame-type (framep-on-display display
)))
1236 ((memq frame-type
'(x w32 ns
))
1237 (x-display-screens display
))
1241 (declare-function x-display-pixel-height
"xfns.c" (&optional terminal
))
1243 (defun display-pixel-height (&optional display
)
1244 "Return the height of DISPLAY's screen in pixels.
1245 For character terminals, each character counts as a single pixel."
1246 (let ((frame-type (framep-on-display display
)))
1248 ((memq frame-type
'(x w32 ns
))
1249 (x-display-pixel-height display
))
1251 (frame-height (if (framep display
) display
(selected-frame)))))))
1253 (declare-function x-display-pixel-width
"xfns.c" (&optional terminal
))
1255 (defun display-pixel-width (&optional display
)
1256 "Return the width 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-width display
))
1263 (frame-width (if (framep display
) display
(selected-frame)))))))
1265 (defcustom display-mm-dimensions-alist nil
1266 "Alist for specifying screen dimensions in millimeters.
1267 The dimensions will be used for `display-mm-height' and
1268 `display-mm-width' if defined for the respective display.
1270 Each element of the alist has the form (display . (width . height)),
1271 e.g. (\":0.0\" . (287 . 215)).
1273 If `display' equals t, it specifies dimensions for all graphical
1274 displays not explicitely specified."
1276 :type
'(alist :key-type
(choice (string :tag
"Display name")
1277 (const :tag
"Default" t
))
1278 :value-type
(cons :tag
"Dimensions"
1279 (integer :tag
"Width")
1280 (integer :tag
"Height")))
1283 (declare-function x-display-mm-height
"xfns.c" (&optional terminal
))
1285 (defun display-mm-height (&optional display
)
1286 "Return the height of DISPLAY's screen in millimeters.
1287 System values can be overridden by `display-mm-dimensions-alist'.
1288 If the information is unavailable, value is nil."
1289 (and (memq (framep-on-display display
) '(x w32 ns
))
1290 (or (cddr (assoc (or display
(frame-parameter nil
'display
))
1291 display-mm-dimensions-alist
))
1292 (cddr (assoc t display-mm-dimensions-alist
))
1293 (x-display-mm-height display
))))
1295 (declare-function x-display-mm-width
"xfns.c" (&optional terminal
))
1297 (defun display-mm-width (&optional display
)
1298 "Return the width 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 (cadr (assoc (or display
(frame-parameter nil
'display
))
1303 display-mm-dimensions-alist
))
1304 (cadr (assoc t display-mm-dimensions-alist
))
1305 (x-display-mm-width display
))))
1307 (declare-function x-display-backing-store
"xfns.c" (&optional terminal
))
1309 (defun display-backing-store (&optional display
)
1310 "Return the backing store capability of DISPLAY's screen.
1311 The value may be `always', `when-mapped', `not-useful', or nil if
1312 the question is inapplicable to a certain kind of display."
1313 (let ((frame-type (framep-on-display display
)))
1315 ((memq frame-type
'(x w32 ns
))
1316 (x-display-backing-store display
))
1320 (declare-function x-display-save-under
"xfns.c" (&optional terminal
))
1322 (defun display-save-under (&optional display
)
1323 "Return non-nil if DISPLAY's screen supports the SaveUnder feature."
1324 (let ((frame-type (framep-on-display display
)))
1326 ((memq frame-type
'(x w32 ns
))
1327 (x-display-save-under display
))
1331 (declare-function x-display-planes
"xfns.c" (&optional terminal
))
1333 (defun display-planes (&optional display
)
1334 "Return the number of planes supported by DISPLAY."
1335 (let ((frame-type (framep-on-display display
)))
1337 ((memq frame-type
'(x w32 ns
))
1338 (x-display-planes display
))
1339 ((eq frame-type
'pc
)
1342 (truncate (log (length (tty-color-alist)) 2))))))
1344 (declare-function x-display-color-cells
"xfns.c" (&optional terminal
))
1346 (defun display-color-cells (&optional display
)
1347 "Return the number of color cells supported by DISPLAY."
1348 (let ((frame-type (framep-on-display display
)))
1350 ((memq frame-type
'(x w32 ns
))
1351 (x-display-color-cells display
))
1352 ((eq frame-type
'pc
)
1355 (tty-display-color-cells display
)))))
1357 (declare-function x-display-visual-class
"xfns.c" (&optional terminal
))
1359 (defun display-visual-class (&optional display
)
1360 "Return the visual class of DISPLAY.
1361 The value is one of the symbols `static-gray', `gray-scale',
1362 `static-color', `pseudo-color', `true-color', or `direct-color'."
1363 (let ((frame-type (framep-on-display display
)))
1365 ((memq frame-type
'(x w32 ns
))
1366 (x-display-visual-class display
))
1367 ((and (memq frame-type
'(pc t
))
1368 (tty-display-color-p display
))
1374 ;;;; Frame geometry values
1376 (defun frame-geom-value-cons (type value
&optional frame
)
1377 "Return equivalent geometry value for FRAME as a cons with car `+'.
1378 A geometry value equivalent to VALUE for FRAME is returned,
1379 where the value is a cons with car `+', not numeric.
1380 TYPE is the car of the original geometry spec (TYPE . VALUE).
1381 It is `top' or `left', depending on which edge VALUE is related to.
1382 VALUE is the cdr of a frame geometry spec: (left/top . VALUE).
1383 If VALUE is a number, then it is converted to a cons value, perhaps
1384 relative to the opposite frame edge from that in the original spec.
1385 FRAME defaults to the selected frame.
1387 Examples (measures in pixels) -
1388 Assuming display height/width=1024, frame height/width=600:
1389 300 inside display edge: 300 => (+ 300)
1391 300 inside opposite display edge: (- 300) => (+ 124)
1393 300 beyond display edge
1394 (= 724 inside opposite display edge): (+ -300) => (+ -300)
1395 300 beyond display edge
1396 (= 724 inside opposite display edge): (- -300) => (+ 724)
1398 In the 3rd, 4th, and 6th examples, the returned value is relative to
1399 the opposite frame edge from the edge indicated in the input spec."
1400 (cond ((and (consp value
) (eq '+ (car value
))) ; e.g. (+ 300), (+ -300)
1402 ((natnump value
) (list '+ value
)) ; e.g. 300 => (+ 300)
1403 (t ; e.g. -300, (- 300), (- -300)
1404 (list '+ (- (if (eq 'left type
) ; => (+ 124), (+ 124), (+ 724)
1405 (x-display-pixel-width)
1406 (x-display-pixel-height))
1407 (if (integerp value
) (- value
) (cadr value
))
1409 (frame-pixel-width frame
)
1410 (frame-pixel-height frame
)))))))
1412 (defun frame-geom-spec-cons (spec &optional frame
)
1413 "Return equivalent geometry spec for FRAME as a cons with car `+'.
1414 A geometry specification equivalent to SPEC for FRAME is returned,
1415 where the value is a cons with car `+', not numeric.
1416 SPEC is a frame geometry spec: (left . VALUE) or (top . VALUE).
1417 If VALUE is a number, then it is converted to a cons value, perhaps
1418 relative to the opposite frame edge from that in the original spec.
1419 FRAME defaults to the selected frame.
1421 Examples (measures in pixels) -
1422 Assuming display height=1024, frame height=600:
1423 top 300 below display top: (top . 300) => (top + 300)
1424 (top + 300) => (top + 300)
1425 bottom 300 above display bottom: (top - 300) => (top + 124)
1426 (top . -300) => (top + 124)
1427 top 300 above display top
1428 (= bottom 724 above display bottom): (top + -300) => (top + -300)
1429 bottom 300 below display bottom
1430 (= top 724 below display top): (top - -300) => (top + 724)
1432 In the 3rd, 4th, and 6th examples, the returned value is relative to
1433 the opposite frame edge from the edge indicated in the input spec."
1434 (cons (car spec
) (frame-geom-value-cons (car spec
) (cdr spec
))))
1437 (defun delete-other-frames (&optional frame
)
1438 "Delete all frames except FRAME.
1439 If FRAME uses another frame's minibuffer, the minibuffer frame is
1440 left untouched. FRAME nil or omitted means use the selected frame."
1443 (setq frame
(selected-frame)))
1444 (let* ((mini-frame (window-frame (minibuffer-window frame
)))
1445 (frames (delq mini-frame
(delq frame
(frame-list)))))
1446 ;; Only consider frames on the same terminal.
1447 (dolist (frame (prog1 frames
(setq frames nil
)))
1448 (if (eq (frame-terminal) (frame-terminal frame
))
1449 (push frame frames
)))
1450 ;; Delete mon-minibuffer-only frames first, because `delete-frame'
1451 ;; signals an error when trying to delete a mini-frame that's
1452 ;; still in use by another frame.
1453 (dolist (frame frames
)
1454 (unless (eq (frame-parameter frame
'minibuffer
) 'only
)
1455 (delete-frame frame
)))
1456 ;; Delete minibuffer-only frames.
1457 (dolist (frame frames
)
1458 (when (eq (frame-parameter frame
'minibuffer
) 'only
)
1459 (delete-frame frame
)))))
1461 ;; miscellaneous obsolescence declarations
1462 (define-obsolete-variable-alias 'delete-frame-hook
1463 'delete-frame-functions
"22.1")
1466 ;; Highlighting trailing whitespace.
1468 (make-variable-buffer-local 'show-trailing-whitespace
)
1473 (defgroup scrolling nil
1474 "Scrolling windows."
1478 (defvaralias 'automatic-hscrolling
'auto-hscroll-mode
)
1483 (defgroup cursor nil
1484 "Displaying text cursors."
1488 (defcustom blink-cursor-delay
0.5
1489 "Seconds of idle time after which cursor starts to blink."
1493 (defcustom blink-cursor-interval
0.5
1494 "Length of cursor blink interval in seconds."
1498 (defvar blink-cursor-idle-timer nil
1499 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
1500 The function `blink-cursor-start' is called when the timer fires.")
1502 (defvar blink-cursor-timer nil
1503 "Timer started from `blink-cursor-start'.
1504 This timer calls `blink-cursor-timer-function' every
1505 `blink-cursor-interval' seconds.")
1507 (defun blink-cursor-start ()
1508 "Timer function called from the timer `blink-cursor-idle-timer'.
1509 This starts the timer `blink-cursor-timer', which makes the cursor blink
1510 if appropriate. It also arranges to cancel that timer when the next
1511 command starts, by installing a pre-command hook."
1512 (when (null blink-cursor-timer
)
1513 ;; Set up the timer first, so that if this signals an error,
1514 ;; blink-cursor-end is not added to pre-command-hook.
1515 (setq blink-cursor-timer
1516 (run-with-timer blink-cursor-interval blink-cursor-interval
1517 'blink-cursor-timer-function
))
1518 (add-hook 'pre-command-hook
'blink-cursor-end
)
1519 (internal-show-cursor nil nil
)))
1521 (defun blink-cursor-timer-function ()
1522 "Timer function of timer `blink-cursor-timer'."
1523 (internal-show-cursor nil
(not (internal-show-cursor-p))))
1525 (defun blink-cursor-end ()
1526 "Stop cursor blinking.
1527 This is installed as a pre-command hook by `blink-cursor-start'.
1528 When run, it cancels the timer `blink-cursor-timer' and removes
1529 itself as a pre-command hook."
1530 (remove-hook 'pre-command-hook
'blink-cursor-end
)
1531 (internal-show-cursor nil t
)
1532 (when blink-cursor-timer
1533 (cancel-timer blink-cursor-timer
)
1534 (setq blink-cursor-timer nil
)))
1536 (define-minor-mode blink-cursor-mode
1537 "Toggle blinking cursor mode.
1538 With a numeric argument, turn blinking cursor mode on if ARG is positive,
1539 otherwise turn it off. When blinking cursor mode is enabled, the
1540 cursor of the selected window blinks.
1542 Note that this command is effective only when Emacs
1543 displays through a window system, because then Emacs does its own
1544 cursor display. On a text-only terminal, this is not implemented."
1545 :init-value
(not (or noninteractive
1547 (eq system-type
'ms-dos
)
1548 (not (memq window-system
'(x w32
)))))
1549 :initialize
'custom-initialize-delay
1552 (if blink-cursor-idle-timer
(cancel-timer blink-cursor-idle-timer
))
1553 (setq blink-cursor-idle-timer nil
)
1555 (when blink-cursor-mode
1557 ;;(internal-show-cursor nil nil)
1558 (setq blink-cursor-idle-timer
1559 (run-with-idle-timer blink-cursor-delay
1561 'blink-cursor-start
))))
1563 (define-obsolete-variable-alias 'blink-cursor
'blink-cursor-mode
"22.1")
1568 (define-key ctl-x-5-map
"2" 'make-frame-command
)
1569 (define-key ctl-x-5-map
"1" 'delete-other-frames
)
1570 (define-key ctl-x-5-map
"0" 'delete-frame
)
1571 (define-key ctl-x-5-map
"o" 'other-frame
)
1575 ;;; frame.el ends here