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 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 (eval-when-compile (require 'cl
))
29 (defvar frame-creation-function-alist
31 (if (fboundp 'tty-create-frame-with-faces
)
32 'tty-create-frame-with-faces
34 (error "Can't create multiple frames without a window system")))))
35 "Alist of window-system dependent functions to call to create a new frame.
36 The window system startup file should add its frame creation
37 function to this list, which should take an alist of parameters
40 (defvar window-system-default-frame-alist nil
41 "Alist of window-system dependent default frame parameters.
42 Parameters specified here supersede the values given in
43 `default-frame-alist'.")
45 ;; The initial value given here used to ask for a minibuffer.
46 ;; But that's not necessary, because the default is to have one.
47 ;; By not specifying it here, we let an X resource specify it.
48 (defcustom initial-frame-alist nil
49 "Alist of parameters for the initial X window frame.
50 You can set this in your init file; for example,
52 (setq initial-frame-alist
53 '((top . 1) (left . 1) (width . 80) (height . 55)))
55 Parameters specified here supersede the values given in
56 `default-frame-alist'.
58 If the value calls for a frame without a minibuffer, and you have
59 not created a minibuffer frame on your own, a minibuffer frame is
60 created according to `minibuffer-frame-alist'.
62 You can specify geometry-related options for just the initial
63 frame by setting this variable in your init file; however, they
64 won't take effect until Emacs reads your init file, which happens
65 after creating the initial frame. If you want the initial frame
66 to have the proper geometry as soon as it appears, you need to
67 use this three-step process:
68 * Specify X resources to give the geometry you want.
69 * Set `default-frame-alist' to override these options so that they
70 don't affect subsequent frames.
71 * Set `initial-frame-alist' in a way that matches the X resources,
72 to override what you put in `default-frame-alist'."
73 :type
'(repeat (cons :format
"%v"
74 (symbol :tag
"Parameter")
78 (defcustom minibuffer-frame-alist
'((width .
80) (height .
2))
79 "Alist of parameters for the initial minibuffer frame.
80 This is the minibuffer frame created if `initial-frame-alist'
81 calls for a frame without a minibuffer. The parameters specified
82 here supersede those given in `default-frame-alist', for the
83 initial minibuffer frame.
85 You can set this in your init file; for example,
87 (setq minibuffer-frame-alist
88 '((top . 1) (left . 1) (width . 80) (height . 2)))
90 It is not necessary to include (minibuffer . only); that is
91 appended when the minibuffer frame is created."
92 :type
'(repeat (cons :format
"%v"
93 (symbol :tag
"Parameter")
97 (defcustom pop-up-frame-alist nil
98 "Alist of parameters for automatically generated new frames.
99 You can set this in your init file; for example,
101 (setq pop-up-frame-alist '((width . 80) (height . 20)))
103 If non-nil, the value you specify here is used by the default
104 `pop-up-frame-function' for the creation of new frames.
106 Since `pop-up-frame-function' is used by `display-buffer' for
107 making new frames, any value specified here by default affects
108 the automatic generation of new frames via `display-buffer' and
109 all functions based on it. The behavior of `make-frame' is not
110 affected by this variable."
111 :type
'(repeat (cons :format
"%v"
112 (symbol :tag
"Parameter")
113 (sexp :tag
"Value")))
116 (defcustom pop-up-frame-function
117 (lambda () (make-frame pop-up-frame-alist
))
118 "Function used by `display-buffer' for creating a new frame.
119 This function is called with no arguments and should return a new
120 frame. The default value calls `make-frame' with the argument
121 `pop-up-frame-alist'."
125 (defcustom special-display-frame-alist
126 '((height .
14) (width .
80) (unsplittable . t
))
127 "Alist of parameters for special frames.
128 Special frames are used for buffers whose names are listed in
129 `special-display-buffer-names' and for buffers whose names match
130 one of the regular expressions in `special-display-regexps'.
132 This variable can be set in your init file, like this:
134 (setq special-display-frame-alist '((width . 80) (height . 20)))
136 These supersede the values given in `default-frame-alist'."
137 :type
'(repeat (cons :format
"%v"
138 (symbol :tag
"Parameter")
139 (sexp :tag
"Value")))
142 (defun special-display-popup-frame (buffer &optional args
)
143 "Display BUFFER and return the window chosen.
144 If BUFFER is already displayed in a visible or iconified frame,
145 raise that frame. Otherwise, display BUFFER in a new frame.
147 Optional argument ARGS is a list specifying additional
150 If ARGS is an alist, use it as a list of frame parameters. If
151 these parameters contain \(same-window . t), display BUFFER in
152 the selected window. If they contain \(same-frame . t), display
153 BUFFER in a window of the selected frame.
155 If ARGS is a list whose car is a symbol, use (car ARGS) as a
156 function to do the work. Pass it BUFFER as first argument,
157 and (cdr ARGS) as second."
158 (if (and args
(symbolp (car args
)))
159 (apply (car args
) buffer
(cdr args
))
160 (let ((window (get-buffer-window buffer
0)))
162 ;; If we have a window already, make it visible.
164 (let ((frame (window-frame window
)))
165 (make-frame-visible frame
)
168 ;; Reuse the current window if the user requested it.
169 (when (cdr (assq 'same-window args
))
171 (progn (switch-to-buffer buffer
) (selected-window))
173 ;; Stay on the same frame if requested.
174 (when (or (cdr (assq 'same-frame args
)) (cdr (assq 'same-window args
)))
175 (let* ((pop-up-windows t
)
177 special-display-buffer-names special-display-regexps
)
178 (display-buffer buffer
)))
179 ;; If no window yet, make one in a new frame.
181 (with-current-buffer buffer
182 (make-frame (append args special-display-frame-alist
)))))
183 (set-window-buffer (frame-selected-window frame
) buffer
)
184 (set-window-dedicated-p (frame-selected-window frame
) t
)
185 (frame-selected-window frame
))))))
187 (defun handle-delete-frame (event)
188 "Handle delete-frame events from the X server."
190 (let ((frame (posn-window (event-start event
)))
194 (and (frame-visible-p (car tail
))
195 (not (eq (car tail
) frame
))
197 (setq tail
(cdr tail
)))
199 (delete-frame frame t
)
200 ;; Gildea@x.org says it is ok to ask questions before terminating.
201 (save-buffers-kill-emacs))))
203 ;;;; Arrangement of frames at startup
205 ;; 1) Load the window system startup file from the lisp library and read the
206 ;; high-priority arguments (-q and the like). The window system startup
207 ;; file should create any frames specified in the window system defaults.
209 ;; 2) If no frames have been opened, we open an initial text frame.
211 ;; 3) Once the init file is done, we apply any newly set parameters
212 ;; in initial-frame-alist to the frame.
214 ;; These are now called explicitly at the proper times,
215 ;; since that is easier to understand.
216 ;; Actually using hooks within Emacs is bad for future maintenance. --rms.
217 ;; (add-hook 'before-init-hook 'frame-initialize)
218 ;; (add-hook 'window-setup-hook 'frame-notice-user-settings)
220 ;; If we create the initial frame, this is it.
221 (defvar frame-initial-frame nil
)
223 ;; Record the parameters used in frame-initialize to make the initial frame.
224 (defvar frame-initial-frame-alist
)
226 (defvar frame-initial-geometry-arguments nil
)
228 ;; startup.el calls this function before loading the user's init
229 ;; file - if there is no frame with a minibuffer open now, create
230 ;; one to display messages while loading the init file.
231 (defun frame-initialize ()
232 "Create an initial frame if necessary."
233 ;; Are we actually running under a window system at all?
234 (if (and initial-window-system
236 (not (eq initial-window-system
'pc
)))
238 ;; If there is no frame with a minibuffer besides the terminal
239 ;; frame, then we need to create the opening frame. Make sure
240 ;; it has a minibuffer, but let initial-frame-alist omit the
242 (or (delq terminal-frame
(minibuffer-frame-list))
244 (setq frame-initial-frame-alist
245 (append initial-frame-alist default-frame-alist nil
))
246 (or (assq 'horizontal-scroll-bars frame-initial-frame-alist
)
247 (setq frame-initial-frame-alist
248 (cons '(horizontal-scroll-bars . t
)
249 frame-initial-frame-alist
)))
250 (setq frame-initial-frame-alist
251 (cons (cons 'window-system initial-window-system
)
252 frame-initial-frame-alist
))
253 (setq default-minibuffer-frame
254 (setq frame-initial-frame
255 (make-frame frame-initial-frame-alist
)))
256 ;; Delete any specifications for window geometry parameters
257 ;; so that we won't reapply them in frame-notice-user-settings.
258 ;; It would be wrong to reapply them then,
259 ;; because that would override explicit user resizing.
260 (setq initial-frame-alist
261 (frame-remove-geometry-params initial-frame-alist
))))
262 ;; Copy the environment of the Emacs process into the new frame.
263 (set-frame-parameter frame-initial-frame
'environment
264 (frame-parameter terminal-frame
'environment
))
265 ;; At this point, we know that we have a frame open, so we
266 ;; can delete the terminal frame.
267 (delete-frame terminal-frame
)
268 (setq terminal-frame nil
))))
270 (defvar frame-notice-user-settings t
271 "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
273 (declare-function tool-bar-mode
"tool-bar" (&optional arg
))
275 ;; startup.el calls this function after loading the user's init
276 ;; file. Now default-frame-alist and initial-frame-alist contain
277 ;; information to which we must react; do what needs to be done.
278 (defun frame-notice-user-settings ()
279 "Act on user's init file settings of frame parameters.
280 React to settings of `initial-frame-alist',
281 `window-system-default-frame-alist' and `default-frame-alist'
282 there (in decreasing order of priority)."
283 ;; Creating and deleting frames may shift the selected frame around,
284 ;; and thus the current buffer. Protect against that. We don't
285 ;; want to use save-excursion here, because that may also try to set
286 ;; the buffer of the selected window, which fails when the selected
287 ;; window is the minibuffer.
288 (let ((old-buffer (current-buffer))
289 (window-system-frame-alist
290 (cdr (assq initial-window-system
291 window-system-default-frame-alist
))))
293 (when (and frame-notice-user-settings
294 (null frame-initial-frame
))
295 ;; This case happens when we don't have a window system, and
296 ;; also for MS-DOS frames.
297 (let ((parms (frame-parameters frame-initial-frame
)))
298 ;; Don't change the frame names.
299 (setq parms
(delq (assq 'name parms
) parms
))
300 ;; Can't modify the minibuffer parameter, so don't try.
301 (setq parms
(delq (assq 'minibuffer parms
) parms
))
302 (modify-frame-parameters nil
303 (if (null initial-window-system
)
304 (append initial-frame-alist
305 window-system-frame-alist
309 ;; initial-frame-alist and
310 ;; default-frame-alist were already
311 ;; applied in pc-win.el.
313 (if (null initial-window-system
) ;; MS-DOS does this differently in pc-win.el
314 (let ((newparms (frame-parameters))
315 (frame (selected-frame)))
316 (tty-handle-reverse-video frame newparms
)
317 ;; If we changed the background color, we need to update
318 ;; the background-mode parameter, and maybe some faces,
320 (when (assq 'background-color newparms
)
321 (unless (or (assq 'background-mode initial-frame-alist
)
322 (assq 'background-mode default-frame-alist
))
323 (frame-set-background-mode frame
))
324 (face-set-after-frame-default frame
))))))
326 ;; If the initial frame is still around, apply initial-frame-alist
327 ;; and default-frame-alist to it.
328 (when (frame-live-p frame-initial-frame
)
330 ;; When tool-bar has been switched off, correct the frame size
331 ;; by the lines added in x-create-frame for the tool-bar and
332 ;; switch `tool-bar-mode' off.
333 (when (display-graphic-p)
334 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist
)
335 (assq 'tool-bar-lines window-system-frame-alist
)
336 (assq 'tool-bar-lines default-frame-alist
))))
337 (when (and tool-bar-originally-present
338 (or (null tool-bar-lines
)
339 (null (cdr tool-bar-lines
))
340 (eq 0 (cdr tool-bar-lines
))))
341 (let* ((char-height (frame-char-height frame-initial-frame
))
342 (image-height tool-bar-images-pixel-height
)
343 (margin (cond ((and (consp tool-bar-button-margin
)
344 (integerp (cdr tool-bar-button-margin
))
345 (> tool-bar-button-margin
0))
346 (cdr tool-bar-button-margin
))
347 ((and (integerp tool-bar-button-margin
)
348 (> tool-bar-button-margin
0))
349 tool-bar-button-margin
)
351 (relief (if (and (integerp tool-bar-button-relief
)
352 (> tool-bar-button-relief
0))
353 tool-bar-button-relief
3))
354 (lines (/ (+ image-height
359 (height (frame-parameter frame-initial-frame
'height
))
360 (newparms (list (cons 'height
(- height lines
))))
361 (initial-top (cdr (assq 'top
362 frame-initial-geometry-arguments
)))
363 (top (frame-parameter frame-initial-frame
'top
)))
364 (when (and (consp initial-top
) (eq '-
(car initial-top
)))
366 (cond ((and (consp top
)
370 (* lines char-height
))))
375 (* lines char-height
))))
376 (t (+ top
(* lines char-height
))))))
379 `((top .
,adjusted-top
))
381 (modify-frame-parameters frame-initial-frame newparms
)
382 (tool-bar-mode -
1)))))
384 ;; The initial frame we create above always has a minibuffer.
385 ;; If the user wants to remove it, or make it a minibuffer-only
386 ;; frame, then we'll have to delete the current frame and make a
387 ;; new one; you can't remove or add a root window to/from an
390 ;; NOTE: default-frame-alist was nil when we created the
391 ;; existing frame. We need to explicitly include
392 ;; default-frame-alist in the parameters of the screen we
393 ;; create here, so that its new value, gleaned from the user's
394 ;; .emacs file, will be applied to the existing screen.
395 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist
)
396 (assq 'minibuffer window-system-frame-alist
)
397 (assq 'minibuffer default-frame-alist
)
400 ;; Create the new frame.
402 ;; If the frame isn't visible yet, wait till it is.
403 ;; If the user has to position the window,
404 ;; Emacs doesn't know its real position until
405 ;; the frame is seen to be visible.
406 (while (not (cdr (assq 'visibility
407 (frame-parameters frame-initial-frame
))))
409 (setq parms
(frame-parameters frame-initial-frame
))
411 ;; Get rid of `name' unless it was specified explicitly before.
412 (or (assq 'name frame-initial-frame-alist
)
413 (setq parms
(delq (assq 'name parms
) parms
)))
414 ;; An explicit parent-id is a request to XEmbed the frame.
415 (or (assq 'parent-id frame-initial-frame-alist
)
416 (setq parms
(delq (assq 'parent-id parms
) parms
)))
418 (setq parms
(append initial-frame-alist
419 window-system-frame-alist
424 ;; Get rid of `reverse', because that was handled
425 ;; when we first made the frame.
426 (setq parms
(cons '(reverse) (delq (assq 'reverse parms
) parms
)))
428 (if (assq 'height frame-initial-geometry-arguments
)
429 (setq parms
(assq-delete-all 'height parms
)))
430 (if (assq 'width frame-initial-geometry-arguments
)
431 (setq parms
(assq-delete-all 'width parms
)))
432 (if (assq 'left frame-initial-geometry-arguments
)
433 (setq parms
(assq-delete-all 'left parms
)))
434 (if (assq 'top frame-initial-geometry-arguments
)
435 (setq parms
(assq-delete-all 'top parms
)))
438 ;; Use the geometry args that created the existing
439 ;; frame, rather than the parms we get for it.
440 (append frame-initial-geometry-arguments
441 '((user-size . t
) (user-position . t
))
443 ;; The initial frame, which we are about to delete, may be
444 ;; the only frame with a minibuffer. If it is, create a
446 (or (delq frame-initial-frame
(minibuffer-frame-list))
447 (make-initial-minibuffer-frame nil
))
449 ;; If the initial frame is serving as a surrogate
450 ;; minibuffer frame for any frames, we need to wean them
451 ;; onto a new frame. The default-minibuffer-frame
452 ;; variable must be handled similarly.
453 (let ((users-of-initial
456 (and (not (eq frame frame-initial-frame
))
458 (minibuffer-window frame
))
459 frame-initial-frame
))))))
460 (if (or users-of-initial
461 (eq default-minibuffer-frame frame-initial-frame
))
463 ;; Choose an appropriate frame. Prefer frames which
464 ;; are only minibuffers.
465 (let* ((new-surrogate
467 (or (filtered-frame-list
469 (eq (cdr (assq 'minibuffer
470 (frame-parameters frame
)))
472 (minibuffer-frame-list))))
473 (new-minibuffer (minibuffer-window new-surrogate
)))
475 (if (eq default-minibuffer-frame frame-initial-frame
)
476 (setq default-minibuffer-frame new-surrogate
))
478 ;; Wean the frames using frame-initial-frame as
479 ;; their minibuffer frame.
480 (dolist (frame users-of-initial
)
481 (modify-frame-parameters
482 frame
(list (cons 'minibuffer new-minibuffer
)))))))
484 ;; Redirect events enqueued at this frame to the new frame.
485 ;; Is this a good idea?
486 (redirect-frame-focus frame-initial-frame new
)
488 ;; Finally, get rid of the old frame.
489 (delete-frame frame-initial-frame t
))
491 ;; Otherwise, we don't need all that rigamarole; just apply
492 ;; the new parameters.
493 (let (newparms allparms tail
)
494 (setq allparms
(append initial-frame-alist
495 window-system-frame-alist
496 default-frame-alist nil
))
497 (if (assq 'height frame-initial-geometry-arguments
)
498 (setq allparms
(assq-delete-all 'height allparms
)))
499 (if (assq 'width frame-initial-geometry-arguments
)
500 (setq allparms
(assq-delete-all 'width allparms
)))
501 (if (assq 'left frame-initial-geometry-arguments
)
502 (setq allparms
(assq-delete-all 'left allparms
)))
503 (if (assq 'top frame-initial-geometry-arguments
)
504 (setq allparms
(assq-delete-all 'top allparms
)))
506 ;; Find just the parms that have changed since we first
507 ;; made this frame. Those are the ones actually set by
508 ;; the init file. For those parms whose values we already knew
509 ;; (such as those spec'd by command line options)
510 ;; it is undesirable to specify the parm again
511 ;; once the user has seen the frame and been able to alter it
515 (setq oldval
(assq (car (car tail
))
516 frame-initial-frame-alist
))
517 (setq newval
(cdr (assq (car (car tail
)) allparms
)))
518 (or (and oldval
(eq (cdr oldval
) newval
))
520 (cons (cons (car (car tail
)) newval
) newparms
))))
521 (setq tail
(cdr tail
)))
522 (setq newparms
(nreverse newparms
))
523 (modify-frame-parameters frame-initial-frame
525 ;; If we changed the background color,
526 ;; we need to update the background-mode parameter
527 ;; and maybe some faces too.
528 (when (assq 'background-color newparms
)
529 (unless (assq 'background-mode newparms
)
530 (frame-set-background-mode frame-initial-frame
))
531 (face-set-after-frame-default frame-initial-frame
)))))
533 ;; Restore the original buffer.
534 (set-buffer old-buffer
)
536 ;; Make sure the initial frame can be GC'd if it is ever deleted.
537 ;; Make sure frame-notice-user-settings does nothing if called twice.
538 (setq frame-notice-user-settings nil
)
539 (setq frame-initial-frame nil
)))
541 (defun make-initial-minibuffer-frame (display)
542 (let ((parms (append minibuffer-frame-alist
'((minibuffer . only
)))))
544 (make-frame-on-display display parms
)
545 (make-frame parms
))))
547 ;;;; Creation of additional frames, and other frame miscellanea
549 (defun modify-all-frames-parameters (alist)
550 "Modify all current and future frames' parameters according to ALIST.
551 This changes `default-frame-alist' and possibly `initial-frame-alist'.
552 Furthermore, this function removes all parameters in ALIST from
553 `window-system-default-frame-alist'.
554 See help of `modify-frame-parameters' for more information."
555 (dolist (frame (frame-list))
556 (modify-frame-parameters frame alist
))
558 (dolist (pair alist
) ;; conses to add/replace
559 ;; initial-frame-alist needs setting only when
560 ;; frame-notice-user-settings is true.
561 (and frame-notice-user-settings
562 (setq initial-frame-alist
563 (assq-delete-all (car pair
) initial-frame-alist
)))
564 (setq default-frame-alist
565 (assq-delete-all (car pair
) default-frame-alist
))
566 ;; Remove any similar settings from the window-system specific
567 ;; parameters---they would override default-frame-alist.
568 (dolist (w window-system-default-frame-alist
)
569 (setcdr w
(assq-delete-all (car pair
) (cdr w
)))))
571 (and frame-notice-user-settings
572 (setq initial-frame-alist
(append initial-frame-alist alist
)))
573 (setq default-frame-alist
(append default-frame-alist alist
)))
575 (defun get-other-frame ()
576 "Return some frame other than the current frame.
577 Create one if necessary. Note that the minibuffer frame, if separate,
578 is not considered (see `next-frame')."
579 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
581 (next-frame (selected-frame)))))
584 (defun next-multiframe-window ()
585 "Select the next window, regardless of which frame it is on."
587 (select-window (next-window (selected-window)
588 (> (minibuffer-depth) 0)
590 (select-frame-set-input-focus (selected-frame)))
592 (defun previous-multiframe-window ()
593 "Select the previous window, regardless of which frame it is on."
595 (select-window (previous-window (selected-window)
596 (> (minibuffer-depth) 0)
598 (select-frame-set-input-focus (selected-frame)))
600 (declare-function x-initialize-window-system
"term/x-win" ())
601 (declare-function ns-initialize-window-system
"term/ns-win" ())
602 (defvar x-display-name
) ; term/x-win
604 (defun make-frame-on-display (display &optional parameters
)
605 "Make a frame on display DISPLAY.
606 The optional argument PARAMETERS specifies additional frame parameters."
607 (interactive "sMake frame on display: ")
608 (cond ((featurep 'ns
)
609 (when (and (boundp 'ns-initialized
) (not ns-initialized
))
610 (setq x-display-name display
)
611 (ns-initialize-window-system))
612 (make-frame `((window-system . ns
)
613 (display .
,display
) .
,parameters
)))
614 ((eq system-type
'windows-nt
)
615 ;; On Windows, ignore DISPLAY.
616 (make-frame parameters
))
618 (unless (string-match-p "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display
)
619 (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
620 (when (and (boundp 'x-initialized
) (not x-initialized
))
621 (setq x-display-name display
)
622 (x-initialize-window-system))
623 (make-frame `((window-system . x
)
624 (display .
,display
) .
,parameters
)))))
626 (declare-function x-close-connection
"xfns.c" (terminal))
628 (defun close-display-connection (display)
629 "Close the connection to a display, deleting all its associated frames.
630 For DISPLAY, specify either a frame or a display name (a string).
631 If DISPLAY is nil, that stands for the selected frame's display."
634 (let* ((default (frame-parameter nil
'display
))
635 (display (completing-read
636 (format "Close display (default %s): " default
)
638 (mapcar (lambda (frame)
639 (frame-parameter frame
'display
))
643 (if (zerop (length display
)) default display
))))
644 (let ((frames (delq nil
645 (mapcar (lambda (frame)
647 (frame-parameter frame
'display
))
650 (if (and (consp frames
)
651 (not (y-or-n-p (if (cdr frames
)
652 (format "Delete %s frames? " (length frames
))
653 (format "Delete %s ? " (car frames
))))))
655 (mapc 'delete-frame frames
)
656 (x-close-connection display
))))
658 (defun make-frame-command ()
659 "Make a new frame, on the same terminal as the selected frame.
660 If the terminal is a text-only terminal, this also selects the
663 (if (display-graphic-p)
665 (select-frame (make-frame))))
667 (defvar before-make-frame-hook nil
668 "Functions to run before a frame is created.")
670 (defvar after-make-frame-functions nil
671 "Functions to run after a frame is created.
672 The functions are run with one arg, the newly created frame.")
674 (defvar after-setting-font-hook nil
675 "Functions to run after a frame's font has been changed.")
677 ;; Alias, kept temporarily.
678 (define-obsolete-function-alias 'new-frame
'make-frame
"22.1")
680 (defvar frame-inherited-parameters
'()
681 ;; FIXME: Shouldn't we add `font' here as well?
682 "Parameters `make-frame' copies from the `selected-frame' to the new frame.")
684 (defun make-frame (&optional parameters
)
685 "Return a newly created frame displaying the current buffer.
686 Optional argument PARAMETERS is an alist of frame parameters for
687 the new frame. Each element of PARAMETERS should have the
688 form (NAME . VALUE), for example:
690 (name . STRING) The frame should be named STRING.
692 (width . NUMBER) The frame should be NUMBER characters in width.
693 (height . NUMBER) The frame should be NUMBER text lines high.
695 You cannot specify either `width' or `height', you must specify
698 (minibuffer . t) The frame should have a minibuffer.
699 (minibuffer . nil) The frame should have no minibuffer.
700 (minibuffer . only) The frame should contain only a minibuffer.
701 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
703 (window-system . nil) The frame should be displayed on a terminal device.
704 (window-system . x) The frame should be displayed in an X window.
706 (terminal . TERMINAL) The frame should use the terminal object TERMINAL.
708 In addition, any parameter specified in `default-frame-alist',
709 but not present in PARAMETERS, is applied.
711 Before creating the frame (via `frame-creation-function-alist'),
712 this function runs the hook `before-make-frame-hook'. After
713 creating the frame, it runs the hook `after-make-frame-functions'
714 with one arg, the newly created frame.
716 On graphical displays, this function does not itself make the new
717 frame the selected frame. However, the window system may select
718 the new frame according to its own rules."
721 ((assq 'terminal parameters
)
722 (let ((type (terminal-live-p (cdr (assq 'terminal parameters
)))))
725 ((eq type nil
) (error "Terminal %s does not exist"
726 (cdr (assq 'terminal parameters
))))
728 ((assq 'window-system parameters
)
729 (cdr (assq 'window-system parameters
)))
731 (frame-creation-function (cdr (assq w frame-creation-function-alist
)))
732 (oldframe (selected-frame))
735 (unless frame-creation-function
736 (error "Don't know how to create a frame on window system %s" w
))
737 ;; Add parameters from `window-system-default-frame-alist'.
738 (dolist (p (cdr (assq w window-system-default-frame-alist
)))
739 (unless (assq (car p
) params
)
741 ;; Add parameters from `default-frame-alist'.
742 (dolist (p default-frame-alist
)
743 (unless (assq (car p
) params
)
745 ;; Now make the frame.
746 (run-hooks 'before-make-frame-hook
)
747 (setq frame
(funcall frame-creation-function params
))
748 (normal-erase-is-backspace-setup-frame frame
)
749 ;; Inherit the original frame's parameters.
750 (dolist (param frame-inherited-parameters
)
751 (unless (assq param parameters
) ;Overridden by explicit parameters.
752 (let ((val (frame-parameter oldframe param
)))
753 (when val
(set-frame-parameter frame param val
)))))
754 (run-hook-with-args 'after-make-frame-functions frame
)
757 (defun filtered-frame-list (predicate)
758 "Return a list of all live frames which satisfy PREDICATE."
759 (let* ((frames (frame-list))
761 (while (consp frames
)
762 (unless (funcall predicate
(car frames
))
764 (setq frames
(cdr frames
)))
767 (defun minibuffer-frame-list ()
768 "Return a list of all frames with their own minibuffers."
771 (eq frame
(window-frame (minibuffer-window frame
))))))
773 ;; Used to be called `terminal-id' in termdev.el.
774 (defun get-device-terminal (device)
775 "Return the terminal corresponding to DEVICE.
776 DEVICE can be a terminal, a frame, nil (meaning the selected frame's terminal),
777 the name of an X display device (HOST.SERVER.SCREEN) or a tty device file."
779 ((or (null device
) (framep device
))
780 (frame-terminal device
))
782 (let ((f (car (filtered-frame-list
784 (or (equal (frame-parameter frame
'display
) device
)
785 (equal (frame-parameter frame
'tty
) device
)))))))
786 (or f
(error "Display %s does not exist" device
))
788 ((terminal-live-p device
) device
)
790 (error "Invalid argument %s in `get-device-terminal'" device
))))
792 (defun frames-on-display-list (&optional device
)
793 "Return a list of all frames on DEVICE.
795 DEVICE should be a terminal, a frame,
796 or a name of an X display or tty (a string of the form
799 If DEVICE is omitted or nil, it defaults to the selected
800 frame's terminal device."
801 (let* ((terminal (get-device-terminal device
))
802 (func #'(lambda (frame)
803 (eq (frame-terminal frame
) terminal
))))
804 (filtered-frame-list func
)))
806 (defun framep-on-display (&optional terminal
)
807 "Return the type of frames on TERMINAL.
808 TERMINAL may be a terminal id, a display name or a frame. If it
809 is a frame, its type is returned. If TERMINAL is omitted or nil,
810 it defaults to the selected frame's terminal device. All frames
811 on a given display are of the same type."
812 (or (terminal-live-p terminal
)
814 (framep (car (frames-on-display-list terminal
)))))
816 (defun frame-remove-geometry-params (param-list)
817 "Return the parameter list PARAM-LIST, but with geometry specs removed.
818 This deletes all bindings in PARAM-LIST for `top', `left', `width',
819 `height', `user-size' and `user-position' parameters.
820 Emacs uses this to avoid overriding explicit moves and resizings from
821 the user during startup."
822 (setq param-list
(cons nil param-list
))
823 (let ((tail param-list
))
824 (while (consp (cdr tail
))
825 (if (and (consp (car (cdr tail
)))
826 (memq (car (car (cdr tail
)))
827 '(height width top left user-position user-size
)))
829 (setq frame-initial-geometry-arguments
830 (cons (car (cdr tail
)) frame-initial-geometry-arguments
))
831 (setcdr tail
(cdr (cdr tail
))))
832 (setq tail
(cdr tail
)))))
833 (setq frame-initial-geometry-arguments
834 (nreverse frame-initial-geometry-arguments
))
837 (declare-function x-focus-frame
"xfns.c" (frame))
839 (defun select-frame-set-input-focus (frame)
840 "Select FRAME, raise it, and set input focus, if possible.
841 If `mouse-autoselect-window' is non-nil, also move mouse pointer
842 to FRAME's selected window. Otherwise, if `focus-follows-mouse'
843 is non-nil, move mouse cursor to FRAME."
846 ;; Ensure, if possible, that FRAME gets input focus.
847 (when (memq (window-system frame
) '(x w32 ns
))
848 (x-focus-frame frame
))
849 ;; Move mouse cursor if necessary.
851 (mouse-autoselect-window
852 (let ((edges (window-inside-edges (frame-selected-window frame
))))
853 ;; Move mouse cursor into FRAME's selected window to avoid that
854 ;; Emacs mouse-autoselects another window.
855 (set-mouse-position frame
(nth 2 edges
) (nth 1 edges
))))
857 ;; Move mouse cursor into FRAME to avoid that another frame gets
858 ;; selected by the window manager.
859 (set-mouse-position frame
(1- (frame-width frame
)) 0))))
861 (defun other-frame (arg)
862 "Select the ARGth different visible frame on current display, and raise it.
863 All frames are arranged in a cyclic order.
864 This command selects the frame ARG steps away in that order.
865 A negative ARG moves in the opposite order.
867 To make this command work properly, you must tell Emacs
868 how the system (or the window manager) generally handles
869 focus-switching between windows. If moving the mouse onto a window
870 selects it (gives it focus), set `focus-follows-mouse' to t.
871 Otherwise, that variable should be nil."
873 (let ((frame (selected-frame)))
875 (setq frame
(next-frame frame
))
876 (while (not (eq (frame-visible-p frame
) t
))
877 (setq frame
(next-frame frame
)))
880 (setq frame
(previous-frame frame
))
881 (while (not (eq (frame-visible-p frame
) t
))
882 (setq frame
(previous-frame frame
)))
884 (select-frame-set-input-focus frame
)))
886 (defun iconify-or-deiconify-frame ()
887 "Iconify the selected frame, or deiconify if it's currently an icon."
889 (if (eq (cdr (assq 'visibility
(frame-parameters))) t
)
891 (make-frame-visible)))
893 (defun suspend-frame ()
894 "Do whatever is right to suspend the current frame.
895 Calls `suspend-emacs' if invoked from the controlling tty device,
896 `suspend-tty' from a secondary tty device, and
897 `iconify-or-deiconify-frame' from an X frame."
899 (let ((type (framep (selected-frame))))
901 ((memq type
'(x ns w32
)) (iconify-or-deiconify-frame))
903 (if (controlling-tty-p)
906 (t (suspend-emacs)))))
908 (defun make-frame-names-alist ()
909 (let* ((current-frame (selected-frame))
912 (cons (frame-parameter current-frame
'name
) current-frame
) nil
))
913 (frame (next-frame nil t
)))
914 (while (not (eq frame current-frame
))
916 (setq falist
(cons (cons (frame-parameter frame
'name
) frame
) falist
))
917 (setq frame
(next-frame frame t
))))
920 (defvar frame-name-history nil
)
921 (defun select-frame-by-name (name)
922 "Select the frame on the current terminal whose name is NAME and raise it.
923 If there is no frame by that name, signal an error."
925 (let* ((frame-names-alist (make-frame-names-alist))
926 (default (car (car frame-names-alist
)))
927 (input (completing-read
928 (format "Select Frame (default %s): " default
)
929 frame-names-alist nil t nil
'frame-name-history
)))
930 (if (= (length input
) 0)
933 (let* ((frame-names-alist (make-frame-names-alist))
934 (frame (cdr (assoc name frame-names-alist
))))
936 (select-frame-set-input-focus frame
)
937 (error "There is no frame named `%s'" name
))))
939 ;;;; Frame configurations
941 (defun current-frame-configuration ()
942 "Return a list describing the positions and states of all frames.
943 Its car is `frame-configuration'.
944 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
946 FRAME is a frame object,
947 ALIST is an association list specifying some of FRAME's parameters, and
948 WINDOW-CONFIG is a window configuration object for FRAME."
949 (cons 'frame-configuration
950 (mapcar (lambda (frame)
952 (frame-parameters frame
)
953 (current-window-configuration frame
)))
956 (defun set-frame-configuration (configuration &optional nodelete
)
957 "Restore the frames to the state described by CONFIGURATION.
958 Each frame listed in CONFIGURATION has its position, size, window
959 configuration, and other parameters set as specified in CONFIGURATION.
960 However, this function does not restore deleted frames.
962 Ordinarily, this function deletes all existing frames not
963 listed in CONFIGURATION. But if optional second argument NODELETE
964 is given and non-nil, the unwanted frames are iconified instead."
965 (or (frame-configuration-p configuration
)
966 (signal 'wrong-type-argument
967 (list 'frame-configuration-p configuration
)))
968 (let ((config-alist (cdr configuration
))
970 (dolist (frame (frame-list))
971 (let ((parameters (assq frame config-alist
)))
974 (modify-frame-parameters
976 ;; Since we can't set a frame's minibuffer status,
977 ;; we might as well omit the parameter altogether.
978 (let* ((parms (nth 1 parameters
))
979 (mini (assq 'minibuffer parms
))
980 (name (assq 'name parms
))
981 (explicit-name (cdr (assq 'explicit-name parms
))))
982 (when mini
(setq parms
(delq mini parms
)))
983 ;; Leave name in iff it was set explicitly.
984 ;; This should fix the behavior reported in
985 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg01632.html
986 (when (and name
(not explicit-name
))
987 (setq parms
(delq name parms
)))
989 (set-window-configuration (nth 2 parameters
)))
990 (setq frames-to-delete
(cons frame frames-to-delete
)))))
992 ;; Note: making frames invisible here was tried
993 ;; but led to some strange behavior--each time the frame
994 ;; was made visible again, the window manager asked afresh
995 ;; for where to put it.
1000 ;;;; Convenience functions for accessing and interactively changing
1001 ;;;; frame parameters.
1003 (defun frame-height (&optional frame
)
1004 "Return number of lines available for display on FRAME.
1005 If FRAME is omitted, describe the currently selected frame.
1006 Exactly what is included in the return value depends on the
1007 window-system and toolkit in use - see `frame-pixel-height' for
1008 more details. The lines are in units of the default font height.
1010 The result is roughly related to the frame pixel height via
1011 height in pixels = height in lines * `frame-char-height'.
1012 However, this is only approximate, and is complicated e.g. by the
1013 fact that individual window lines and menu bar lines can have
1014 differing font heights."
1015 (cdr (assq 'height
(frame-parameters frame
))))
1017 (defun frame-width (&optional frame
)
1018 "Return number of columns available for display on FRAME.
1019 If FRAME is omitted, describe the currently selected frame."
1020 (cdr (assq 'width
(frame-parameters frame
))))
1022 (declare-function x-list-fonts
"xfaces.c"
1023 (pattern &optional face frame maximum width
))
1025 (define-obsolete-function-alias 'set-default-font
'set-frame-font
"23.1")
1026 (defun set-frame-font (font-name &optional keep-size
)
1027 "Set the font of the selected frame to FONT-NAME.
1028 When called interactively, prompt for the name of the font to use.
1029 To get the frame's current default font, use `frame-parameters'.
1031 The default behavior is to keep the numbers of lines and columns in
1032 the frame, thus may change its pixel size. If optional KEEP-SIZE is
1033 non-nil (interactively, prefix argument) the current frame size (in
1034 pixels) is kept by adjusting the numbers of the lines and columns."
1036 (let* ((completion-ignore-case t
)
1037 (font (completing-read "Font name: "
1038 ;; x-list-fonts will fail with an error
1039 ;; if this frame doesn't support fonts.
1040 (x-list-fonts "*" nil
(selected-frame))
1042 (frame-parameter nil
'font
))))
1043 (list font current-prefix-arg
)))
1046 (setq fht
(* (frame-parameter nil
'height
) (frame-char-height))
1047 fwd
(* (frame-parameter nil
'width
) (frame-char-width))))
1048 (modify-frame-parameters (selected-frame)
1049 (list (cons 'font font-name
)))
1051 (modify-frame-parameters
1053 (list (cons 'height
(round fht
(frame-char-height)))
1054 (cons 'width
(round fwd
(frame-char-width)))))))
1055 (run-hooks 'after-setting-font-hook
'after-setting-font-hooks
))
1057 (defun set-frame-parameter (frame parameter value
)
1058 "Set frame parameter PARAMETER to VALUE on FRAME.
1059 If FRAME is nil, it defaults to the selected frame.
1060 See `modify-frame-parameters'."
1061 (modify-frame-parameters frame
(list (cons parameter value
))))
1063 (defun set-background-color (color-name)
1064 "Set the background color of the selected frame to COLOR-NAME.
1065 When called interactively, prompt for the name of the color to use.
1066 To get the frame's current background color, use `frame-parameters'."
1067 (interactive (list (facemenu-read-color "Background color: ")))
1068 (modify-frame-parameters (selected-frame)
1069 (list (cons 'background-color color-name
)))
1071 (face-set-after-frame-default (selected-frame))))
1073 (defun set-foreground-color (color-name)
1074 "Set the foreground color of the selected frame to COLOR-NAME.
1075 When called interactively, prompt for the name of the color to use.
1076 To get the frame's current foreground color, use `frame-parameters'."
1077 (interactive (list (facemenu-read-color "Foreground color: ")))
1078 (modify-frame-parameters (selected-frame)
1079 (list (cons 'foreground-color color-name
)))
1081 (face-set-after-frame-default (selected-frame))))
1083 (defun set-cursor-color (color-name)
1084 "Set the text cursor color of the selected frame to COLOR-NAME.
1085 When called interactively, prompt for the name of the color to use.
1086 To get the frame's current cursor color, use `frame-parameters'."
1087 (interactive (list (facemenu-read-color "Cursor color: ")))
1088 (modify-frame-parameters (selected-frame)
1089 (list (cons 'cursor-color color-name
))))
1091 (defun set-mouse-color (color-name)
1092 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
1093 When called interactively, prompt for the name of the color to use.
1094 To get the frame's current mouse color, use `frame-parameters'."
1095 (interactive (list (facemenu-read-color "Mouse color: ")))
1096 (modify-frame-parameters (selected-frame)
1097 (list (cons 'mouse-color
1099 (cdr (assq 'mouse-color
1100 (frame-parameters))))))))
1102 (defun set-border-color (color-name)
1103 "Set the color of the border of the selected frame to COLOR-NAME.
1104 When called interactively, prompt for the name of the color to use.
1105 To get the frame's current border color, use `frame-parameters'."
1106 (interactive (list (facemenu-read-color "Border color: ")))
1107 (modify-frame-parameters (selected-frame)
1108 (list (cons 'border-color color-name
))))
1110 (define-minor-mode auto-raise-mode
1111 "Toggle whether or not the selected frame should auto-raise.
1112 With ARG, turn auto-raise mode on if and only if ARG is positive.
1113 Note that this controls Emacs's own auto-raise feature.
1114 Some window managers allow you to enable auto-raise for certain windows.
1115 You can use that for Emacs windows if you wish, but if you do,
1116 that is beyond the control of Emacs and this command has no effect on it."
1117 :variable
(frame-parameter nil
'auto-raise
)
1118 (if (frame-parameter nil
'auto-raise
)
1121 (define-minor-mode auto-lower-mode
1122 "Toggle whether or not the selected frame should auto-lower.
1123 With ARG, turn auto-lower mode on if and only if ARG is positive.
1124 Note that this controls Emacs's own auto-lower feature.
1125 Some window managers allow you to enable auto-lower for certain windows.
1126 You can use that for Emacs windows if you wish, but if you do,
1127 that is beyond the control of Emacs and this command has no effect on it."
1128 :variable
(frame-parameter nil
'auto-lower
))
1130 (defun set-frame-name (name)
1131 "Set the name of the selected frame to NAME.
1132 When called interactively, prompt for the name of the frame.
1133 The frame name is displayed on the modeline if the terminal displays only
1134 one frame, otherwise the name is displayed on the frame's caption bar."
1135 (interactive "sFrame name: ")
1136 (modify-frame-parameters (selected-frame)
1137 (list (cons 'name name
))))
1139 (defun frame-current-scroll-bars (&optional frame
)
1140 "Return the current scroll-bar settings in frame FRAME.
1141 Value is a cons (VERTICAL . HORIZ0NTAL) where VERTICAL specifies the
1142 current location of the vertical scroll-bars (left, right, or nil),
1143 and HORIZONTAL specifies the current location of the horizontal scroll
1144 bars (top, bottom, or nil)."
1145 (let ((vert (frame-parameter frame
'vertical-scroll-bars
))
1147 (unless (memq vert
'(left right nil
))
1148 (setq vert default-frame-scroll-bars
))
1151 ;;;; Frame/display capabilities.
1152 (defun selected-terminal ()
1153 "Return the terminal that is now selected."
1154 (frame-terminal (selected-frame)))
1156 (declare-function msdos-mouse-p
"dosfns.c")
1158 (defun display-mouse-p (&optional display
)
1159 "Return non-nil if DISPLAY has a mouse available.
1160 DISPLAY can be a display name, a frame, or nil (meaning the selected
1162 (let ((frame-type (framep-on-display display
)))
1164 ((eq frame-type
'pc
)
1166 ((eq system-type
'windows-nt
)
1168 (> w32-num-mouse-buttons
0)))
1169 ((memq frame-type
'(x ns
))
1170 t
) ;; We assume X and NeXTstep *always* have a pointing device
1172 (or (and (featurep 'xt-mouse
)
1174 ;; t-mouse is distributed with the GPM package. It doesn't have
1176 (featurep 't-mouse
))))))
1178 (defun display-popup-menus-p (&optional display
)
1179 "Return non-nil if popup menus are supported on DISPLAY.
1180 DISPLAY can be a display name, a frame, or nil (meaning the selected
1182 Support for popup menus requires that the mouse be available."
1184 (let ((frame-type (framep-on-display display
)))
1185 (memq frame-type
'(x w32 pc ns
)))
1186 (display-mouse-p display
)))
1188 (defun display-graphic-p (&optional display
)
1189 "Return non-nil if DISPLAY is a graphic display.
1190 Graphical displays are those which are capable of displaying several
1191 frames and several different fonts at once. This is true for displays
1192 that use a window system such as X, and false for text-only terminals.
1193 DISPLAY can be a display name, a frame, or nil (meaning the selected
1195 (not (null (memq (framep-on-display display
) '(x w32 ns
)))))
1197 (defun display-images-p (&optional display
)
1198 "Return non-nil if DISPLAY can display images.
1200 DISPLAY can be a display name, a frame, or nil (meaning the selected
1202 (and (display-graphic-p display
)
1203 (fboundp 'image-mask-p
)
1204 (fboundp 'image-size
)))
1206 (defalias 'display-multi-frame-p
'display-graphic-p
)
1207 (defalias 'display-multi-font-p
'display-graphic-p
)
1209 (defun display-selections-p (&optional display
)
1210 "Return non-nil if DISPLAY supports selections.
1211 A selection is a way to transfer text or other data between programs
1212 via special system buffers called `selection' or `cut buffer' or
1214 DISPLAY can be a display name, a frame, or nil (meaning the selected
1216 (let ((frame-type (framep-on-display display
)))
1218 ((eq frame-type
'pc
)
1219 ;; MS-DOG frames support selections when Emacs runs inside
1220 ;; the Windows' DOS Box.
1222 (not (null dos-windows-version
))))
1223 ((memq frame-type
'(x w32 ns
))
1228 (declare-function x-display-screens
"xfns.c" (&optional terminal
))
1230 (defun display-screens (&optional display
)
1231 "Return the number of screens associated with DISPLAY."
1232 (let ((frame-type (framep-on-display display
)))
1234 ((memq frame-type
'(x w32 ns
))
1235 (x-display-screens display
))
1239 (declare-function x-display-pixel-height
"xfns.c" (&optional terminal
))
1241 (defun display-pixel-height (&optional display
)
1242 "Return the height of DISPLAY's screen in pixels.
1243 For character terminals, each character counts as a single pixel."
1244 (let ((frame-type (framep-on-display display
)))
1246 ((memq frame-type
'(x w32 ns
))
1247 (x-display-pixel-height display
))
1249 (frame-height (if (framep display
) display
(selected-frame)))))))
1251 (declare-function x-display-pixel-width
"xfns.c" (&optional terminal
))
1253 (defun display-pixel-width (&optional display
)
1254 "Return the width of DISPLAY's screen in pixels.
1255 For character terminals, each character counts as a single pixel."
1256 (let ((frame-type (framep-on-display display
)))
1258 ((memq frame-type
'(x w32 ns
))
1259 (x-display-pixel-width display
))
1261 (frame-width (if (framep display
) display
(selected-frame)))))))
1263 (defcustom display-mm-dimensions-alist nil
1264 "Alist for specifying screen dimensions in millimeters.
1265 The dimensions will be used for `display-mm-height' and
1266 `display-mm-width' if defined for the respective display.
1268 Each element of the alist has the form (display . (width . height)),
1269 e.g. (\":0.0\" . (287 . 215)).
1271 If `display' equals t, it specifies dimensions for all graphical
1272 displays not explicitely specified."
1274 :type
'(alist :key-type
(choice (string :tag
"Display name")
1275 (const :tag
"Default" t
))
1276 :value-type
(cons :tag
"Dimensions"
1277 (integer :tag
"Width")
1278 (integer :tag
"Height")))
1281 (declare-function x-display-mm-height
"xfns.c" (&optional terminal
))
1283 (defun display-mm-height (&optional display
)
1284 "Return the height of DISPLAY's screen in millimeters.
1285 System values can be overridden by `display-mm-dimensions-alist'.
1286 If the information is unavailable, value is nil."
1287 (and (memq (framep-on-display display
) '(x w32 ns
))
1288 (or (cddr (assoc (or display
(frame-parameter nil
'display
))
1289 display-mm-dimensions-alist
))
1290 (cddr (assoc t display-mm-dimensions-alist
))
1291 (x-display-mm-height display
))))
1293 (declare-function x-display-mm-width
"xfns.c" (&optional terminal
))
1295 (defun display-mm-width (&optional display
)
1296 "Return the width of DISPLAY's screen in millimeters.
1297 System values can be overridden by `display-mm-dimensions-alist'.
1298 If the information is unavailable, value is nil."
1299 (and (memq (framep-on-display display
) '(x w32 ns
))
1300 (or (cadr (assoc (or display
(frame-parameter nil
'display
))
1301 display-mm-dimensions-alist
))
1302 (cadr (assoc t display-mm-dimensions-alist
))
1303 (x-display-mm-width display
))))
1305 (declare-function x-display-backing-store
"xfns.c" (&optional terminal
))
1307 (defun display-backing-store (&optional display
)
1308 "Return the backing store capability of DISPLAY's screen.
1309 The value may be `always', `when-mapped', `not-useful', or nil if
1310 the question is inapplicable to a certain kind of display."
1311 (let ((frame-type (framep-on-display display
)))
1313 ((memq frame-type
'(x w32 ns
))
1314 (x-display-backing-store display
))
1318 (declare-function x-display-save-under
"xfns.c" (&optional terminal
))
1320 (defun display-save-under (&optional display
)
1321 "Return non-nil if DISPLAY's screen supports the SaveUnder feature."
1322 (let ((frame-type (framep-on-display display
)))
1324 ((memq frame-type
'(x w32 ns
))
1325 (x-display-save-under display
))
1329 (declare-function x-display-planes
"xfns.c" (&optional terminal
))
1331 (defun display-planes (&optional display
)
1332 "Return the number of planes supported by DISPLAY."
1333 (let ((frame-type (framep-on-display display
)))
1335 ((memq frame-type
'(x w32 ns
))
1336 (x-display-planes display
))
1337 ((eq frame-type
'pc
)
1340 (truncate (log (length (tty-color-alist)) 2))))))
1342 (declare-function x-display-color-cells
"xfns.c" (&optional terminal
))
1344 (defun display-color-cells (&optional display
)
1345 "Return the number of color cells supported by DISPLAY."
1346 (let ((frame-type (framep-on-display display
)))
1348 ((memq frame-type
'(x w32 ns
))
1349 (x-display-color-cells display
))
1350 ((eq frame-type
'pc
)
1353 (tty-display-color-cells display
)))))
1355 (declare-function x-display-visual-class
"xfns.c" (&optional terminal
))
1357 (defun display-visual-class (&optional display
)
1358 "Return the visual class of DISPLAY.
1359 The value is one of the symbols `static-gray', `gray-scale',
1360 `static-color', `pseudo-color', `true-color', or `direct-color'."
1361 (let ((frame-type (framep-on-display display
)))
1363 ((memq frame-type
'(x w32 ns
))
1364 (x-display-visual-class display
))
1365 ((and (memq frame-type
'(pc t
))
1366 (tty-display-color-p display
))
1372 ;;;; Frame geometry values
1374 (defun frame-geom-value-cons (type value
&optional frame
)
1375 "Return equivalent geometry value for FRAME as a cons with car `+'.
1376 A geometry value equivalent to VALUE for FRAME is returned,
1377 where the value is a cons with car `+', not numeric.
1378 TYPE is the car of the original geometry spec (TYPE . VALUE).
1379 It is `top' or `left', depending on which edge VALUE is related to.
1380 VALUE is the cdr of a frame geometry spec: (left/top . VALUE).
1381 If VALUE is a number, then it is converted to a cons value, perhaps
1382 relative to the opposite frame edge from that in the original spec.
1383 FRAME defaults to the selected frame.
1385 Examples (measures in pixels) -
1386 Assuming display height/width=1024, frame height/width=600:
1387 300 inside display edge: 300 => (+ 300)
1389 300 inside opposite display edge: (- 300) => (+ 124)
1391 300 beyond display edge
1392 (= 724 inside opposite display edge): (+ -300) => (+ -300)
1393 300 beyond display edge
1394 (= 724 inside opposite display edge): (- -300) => (+ 724)
1396 In the 3rd, 4th, and 6th examples, the returned value is relative to
1397 the opposite frame edge from the edge indicated in the input spec."
1398 (cond ((and (consp value
) (eq '+ (car value
))) ; e.g. (+ 300), (+ -300)
1400 ((natnump value
) (list '+ value
)) ; e.g. 300 => (+ 300)
1401 (t ; e.g. -300, (- 300), (- -300)
1402 (list '+ (- (if (eq 'left type
) ; => (+ 124), (+ 124), (+ 724)
1403 (x-display-pixel-width)
1404 (x-display-pixel-height))
1405 (if (integerp value
) (- value
) (cadr value
))
1407 (frame-pixel-width frame
)
1408 (frame-pixel-height frame
)))))))
1410 (defun frame-geom-spec-cons (spec &optional frame
)
1411 "Return equivalent geometry spec for FRAME as a cons with car `+'.
1412 A geometry specification equivalent to SPEC for FRAME is returned,
1413 where the value is a cons with car `+', not numeric.
1414 SPEC is a frame geometry spec: (left . VALUE) or (top . VALUE).
1415 If VALUE is a number, then it is converted to a cons value, perhaps
1416 relative to the opposite frame edge from that in the original spec.
1417 FRAME defaults to the selected frame.
1419 Examples (measures in pixels) -
1420 Assuming display height=1024, frame height=600:
1421 top 300 below display top: (top . 300) => (top + 300)
1422 (top + 300) => (top + 300)
1423 bottom 300 above display bottom: (top - 300) => (top + 124)
1424 (top . -300) => (top + 124)
1425 top 300 above display top
1426 (= bottom 724 above display bottom): (top + -300) => (top + -300)
1427 bottom 300 below display bottom
1428 (= top 724 below display top): (top - -300) => (top + 724)
1430 In the 3rd, 4th, and 6th examples, the returned value is relative to
1431 the opposite frame edge from the edge indicated in the input spec."
1432 (cons (car spec
) (frame-geom-value-cons (car spec
) (cdr spec
))))
1435 (defun delete-other-frames (&optional frame
)
1436 "Delete all frames except FRAME.
1437 If FRAME uses another frame's minibuffer, the minibuffer frame is
1438 left untouched. FRAME nil or omitted means use the selected frame."
1441 (setq frame
(selected-frame)))
1442 (let* ((mini-frame (window-frame (minibuffer-window frame
)))
1443 (frames (delq mini-frame
(delq frame
(frame-list)))))
1444 ;; Only consider frames on the same terminal.
1445 (dolist (frame (prog1 frames
(setq frames nil
)))
1446 (if (eq (frame-terminal) (frame-terminal frame
))
1447 (push frame frames
)))
1448 ;; Delete mon-minibuffer-only frames first, because `delete-frame'
1449 ;; signals an error when trying to delete a mini-frame that's
1450 ;; still in use by another frame.
1451 (dolist (frame frames
)
1452 (unless (eq (frame-parameter frame
'minibuffer
) 'only
)
1453 (delete-frame frame
)))
1454 ;; Delete minibuffer-only frames.
1455 (dolist (frame frames
)
1456 (when (eq (frame-parameter frame
'minibuffer
) 'only
)
1457 (delete-frame frame
)))))
1459 ;; miscellaneous obsolescence declarations
1460 (define-obsolete-variable-alias 'delete-frame-hook
1461 'delete-frame-functions
"22.1")
1464 ;; Highlighting trailing whitespace.
1466 (make-variable-buffer-local 'show-trailing-whitespace
)
1468 (defcustom show-trailing-whitespace nil
1469 "Non-nil means highlight trailing whitespace.
1470 This is done in the face `trailing-whitespace'."
1473 :group
'whitespace-faces
)
1479 (defgroup scrolling nil
1480 "Scrolling windows."
1484 (defcustom auto-hscroll-mode t
1485 "Allow or disallow automatic scrolling windows horizontally.
1486 If non-nil, windows are automatically scrolled horizontally to make
1491 (defvaralias 'automatic-hscrolling
'auto-hscroll-mode
)
1496 (defgroup cursor nil
1497 "Displaying text cursors."
1501 (defcustom blink-cursor-delay
0.5
1502 "Seconds of idle time after which cursor starts to blink."
1506 (defcustom blink-cursor-interval
0.5
1507 "Length of cursor blink interval in seconds."
1511 (defvar blink-cursor-idle-timer nil
1512 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
1513 The function `blink-cursor-start' is called when the timer fires.")
1515 (defvar blink-cursor-timer nil
1516 "Timer started from `blink-cursor-start'.
1517 This timer calls `blink-cursor-timer-function' every
1518 `blink-cursor-interval' seconds.")
1520 (defun blink-cursor-start ()
1521 "Timer function called from the timer `blink-cursor-idle-timer'.
1522 This starts the timer `blink-cursor-timer', which makes the cursor blink
1523 if appropriate. It also arranges to cancel that timer when the next
1524 command starts, by installing a pre-command hook."
1525 (when (null blink-cursor-timer
)
1526 ;; Set up the timer first, so that if this signals an error,
1527 ;; blink-cursor-end is not added to pre-command-hook.
1528 (setq blink-cursor-timer
1529 (run-with-timer blink-cursor-interval blink-cursor-interval
1530 'blink-cursor-timer-function
))
1531 (add-hook 'pre-command-hook
'blink-cursor-end
)
1532 (internal-show-cursor nil nil
)))
1534 (defun blink-cursor-timer-function ()
1535 "Timer function of timer `blink-cursor-timer'."
1536 (internal-show-cursor nil
(not (internal-show-cursor-p))))
1538 (defun blink-cursor-end ()
1539 "Stop cursor blinking.
1540 This is installed as a pre-command hook by `blink-cursor-start'.
1541 When run, it cancels the timer `blink-cursor-timer' and removes
1542 itself as a pre-command hook."
1543 (remove-hook 'pre-command-hook
'blink-cursor-end
)
1544 (internal-show-cursor nil t
)
1545 (when blink-cursor-timer
1546 (cancel-timer blink-cursor-timer
)
1547 (setq blink-cursor-timer nil
)))
1549 (define-minor-mode blink-cursor-mode
1550 "Toggle blinking cursor mode.
1551 With a numeric argument, turn blinking cursor mode on if ARG is positive,
1552 otherwise turn it off. When blinking cursor mode is enabled, the
1553 cursor of the selected window blinks.
1555 Note that this command is effective only when Emacs
1556 displays through a window system, because then Emacs does its own
1557 cursor display. On a text-only terminal, this is not implemented."
1558 :init-value
(not (or noninteractive
1560 (eq system-type
'ms-dos
)
1561 (not (memq window-system
'(x w32
)))))
1562 :initialize
'custom-initialize-delay
1565 (if blink-cursor-idle-timer
(cancel-timer blink-cursor-idle-timer
))
1566 (setq blink-cursor-idle-timer nil
)
1568 (when blink-cursor-mode
1570 ;;(internal-show-cursor nil nil)
1571 (setq blink-cursor-idle-timer
1572 (run-with-idle-timer blink-cursor-delay
1574 'blink-cursor-start
))))
1576 (define-obsolete-variable-alias 'blink-cursor
'blink-cursor-mode
"22.1")
1578 ;; Hourglass pointer
1580 (defcustom display-hourglass t
1581 "Non-nil means show an hourglass pointer, when Emacs is busy.
1582 This feature only works when on a window system that can change
1587 (defcustom hourglass-delay
1
1588 "Seconds to wait before displaying an hourglass pointer when Emacs is busy."
1593 (defcustom cursor-in-non-selected-windows t
1594 "Non-nil means show a hollow box cursor in non-selected windows.
1595 If nil, don't show a cursor except in the selected window.
1596 If t, display a cursor related to the usual cursor type
1597 \(a solid box becomes hollow, a bar becomes a narrower bar).
1598 You can also specify the cursor type as in the `cursor-type' variable.
1599 Use Custom to set this variable to get the display updated."
1600 :tag
"Cursor In Non-selected Windows"
1603 :set
#'(lambda (symbol value
)
1604 (set-default symbol value
)
1605 (force-mode-line-update t
)))
1610 (define-key ctl-x-5-map
"2" 'make-frame-command
)
1611 (define-key ctl-x-5-map
"1" 'delete-other-frames
)
1612 (define-key ctl-x-5-map
"0" 'delete-frame
)
1613 (define-key ctl-x-5-map
"o" 'other-frame
)
1617 ;; arch-tag: 82979c70-b8f2-4306-b2ad-ddbd6b328b56
1618 ;;; frame.el ends here