gnus-html.el: Doc fix for gnus-html-image-url-blocked-p.
[emacs.git] / lisp / frame.el
blob8f65cc7f1e56f3cb83a718526bf098bec2710310
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.
6 ;; Maintainer: FSF
7 ;; Keywords: internal
8 ;; Package: emacs
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;;; Code:
28 (eval-when-compile (require 'cl))
30 (defvar frame-creation-function-alist
31 (list (cons nil
32 (if (fboundp 'tty-create-frame-with-faces)
33 'tty-create-frame-with-faces
34 (lambda (parameters)
35 (error "Can't create multiple frames without a window system")))))
36 "Alist of window-system dependent functions to call to create a new frame.
37 The window system startup file should add its frame creation
38 function to this list, which should take an alist of parameters
39 as its argument.")
41 (defvar window-system-default-frame-alist nil
42 "Alist of window-system dependent default frame parameters.
43 Parameters specified here supersede the values given in
44 `default-frame-alist'.")
46 ;; The initial value given here used to ask for a minibuffer.
47 ;; But that's not necessary, because the default is to have one.
48 ;; By not specifying it here, we let an X resource specify it.
49 (defcustom initial-frame-alist nil
50 "Alist of parameters for the initial X window frame.
51 You can set this in your init file; for example,
53 (setq initial-frame-alist
54 '((top . 1) (left . 1) (width . 80) (height . 55)))
56 Parameters specified here supersede the values given in
57 `default-frame-alist'.
59 If the value calls for a frame without a minibuffer, and you have
60 not created a minibuffer frame on your own, a minibuffer frame is
61 created according to `minibuffer-frame-alist'.
63 You can specify geometry-related options for just the initial
64 frame by setting this variable in your init file; however, they
65 won't take effect until Emacs reads your init file, which happens
66 after creating the initial frame. If you want the initial frame
67 to have the proper geometry as soon as it appears, you need to
68 use this three-step process:
69 * Specify X resources to give the geometry you want.
70 * Set `default-frame-alist' to override these options so that they
71 don't affect subsequent frames.
72 * Set `initial-frame-alist' in a way that matches the X resources,
73 to override what you put in `default-frame-alist'."
74 :type '(repeat (cons :format "%v"
75 (symbol :tag "Parameter")
76 (sexp :tag "Value")))
77 :group 'frames)
79 (defcustom minibuffer-frame-alist '((width . 80) (height . 2))
80 "Alist of parameters for the initial minibuffer frame.
81 This is the minibuffer frame created if `initial-frame-alist'
82 calls for a frame without a minibuffer. The parameters specified
83 here supersede those given in `default-frame-alist', for the
84 initial minibuffer frame.
86 You can set this in your init file; for example,
88 (setq minibuffer-frame-alist
89 '((top . 1) (left . 1) (width . 80) (height . 2)))
91 It is not necessary to include (minibuffer . only); that is
92 appended when the minibuffer frame is created."
93 :type '(repeat (cons :format "%v"
94 (symbol :tag "Parameter")
95 (sexp :tag "Value")))
96 :group 'frames)
98 (defcustom pop-up-frame-alist nil
99 "Alist of parameters for automatically generated new frames.
100 You can set this in your init file; for example,
102 (setq pop-up-frame-alist '((width . 80) (height . 20)))
104 If non-nil, the value you specify here is used by the default
105 `pop-up-frame-function' for the creation of new frames.
107 Since `pop-up-frame-function' is used by `display-buffer' for
108 making new frames, any value specified here by default affects
109 the automatic generation of new frames via `display-buffer' and
110 all functions based on it. The behavior of `make-frame' is not
111 affected by this variable."
112 :type '(repeat (cons :format "%v"
113 (symbol :tag "Parameter")
114 (sexp :tag "Value")))
115 :group 'frames)
117 (defcustom pop-up-frame-function
118 (lambda () (make-frame pop-up-frame-alist))
119 "Function used by `display-buffer' for creating a new frame.
120 This function is called with no arguments and should return a new
121 frame. The default value calls `make-frame' with the argument
122 `pop-up-frame-alist'."
123 :type 'function
124 :group 'frames)
126 (defcustom special-display-frame-alist
127 '((height . 14) (width . 80) (unsplittable . t))
128 "Alist of parameters for special frames.
129 Special frames are used for buffers whose names are listed in
130 `special-display-buffer-names' and for buffers whose names match
131 one of the regular expressions in `special-display-regexps'.
133 This variable can be set in your init file, like this:
135 (setq special-display-frame-alist '((width . 80) (height . 20)))
137 These supersede the values given in `default-frame-alist'."
138 :type '(repeat (cons :format "%v"
139 (symbol :tag "Parameter")
140 (sexp :tag "Value")))
141 :group 'frames)
143 (defun special-display-popup-frame (buffer &optional args)
144 "Display BUFFER and return the window chosen.
145 If BUFFER is already displayed in a visible or iconified frame,
146 raise that frame. Otherwise, display BUFFER in a new frame.
148 Optional argument ARGS is a list specifying additional
149 information.
151 If ARGS is an alist, use it as a list of frame parameters. If
152 these parameters contain \(same-window . t), display BUFFER in
153 the selected window. If they contain \(same-frame . t), display
154 BUFFER in a window of the selected frame.
156 If ARGS is a list whose car is a symbol, use (car ARGS) as a
157 function to do the work. Pass it BUFFER as first argument,
158 and (cdr ARGS) as second."
159 (if (and args (symbolp (car args)))
160 (apply (car args) buffer (cdr args))
161 (let ((window (get-buffer-window buffer 0)))
163 ;; If we have a window already, make it visible.
164 (when window
165 (let ((frame (window-frame window)))
166 (make-frame-visible frame)
167 (raise-frame frame)
168 window))
169 ;; Reuse the current window if the user requested it.
170 (when (cdr (assq 'same-window args))
171 (condition-case nil
172 (progn (switch-to-buffer buffer) (selected-window))
173 (error nil)))
174 ;; Stay on the same frame if requested.
175 (when (or (cdr (assq 'same-frame args)) (cdr (assq 'same-window args)))
176 (let* ((pop-up-windows t)
177 pop-up-frames
178 special-display-buffer-names special-display-regexps)
179 (display-buffer buffer)))
180 ;; If no window yet, make one in a new frame.
181 (let ((frame
182 (with-current-buffer buffer
183 (make-frame (append args special-display-frame-alist)))))
184 (set-window-buffer (frame-selected-window frame) buffer)
185 (set-window-dedicated-p (frame-selected-window frame) t)
186 (frame-selected-window frame))))))
188 (defun handle-delete-frame (event)
189 "Handle delete-frame events from the X server."
190 (interactive "e")
191 (let ((frame (posn-window (event-start event)))
192 (i 0)
193 (tail (frame-list)))
194 (while tail
195 (and (frame-visible-p (car tail))
196 (not (eq (car tail) frame))
197 (setq i (1+ i)))
198 (setq tail (cdr tail)))
199 (if (> i 0)
200 (delete-frame frame t)
201 ;; Gildea@x.org says it is ok to ask questions before terminating.
202 (save-buffers-kill-emacs))))
204 ;;;; Arrangement of frames at startup
206 ;; 1) Load the window system startup file from the lisp library and read the
207 ;; high-priority arguments (-q and the like). The window system startup
208 ;; file should create any frames specified in the window system defaults.
210 ;; 2) If no frames have been opened, we open an initial text frame.
212 ;; 3) Once the init file is done, we apply any newly set parameters
213 ;; in initial-frame-alist to the frame.
215 ;; These are now called explicitly at the proper times,
216 ;; since that is easier to understand.
217 ;; Actually using hooks within Emacs is bad for future maintenance. --rms.
218 ;; (add-hook 'before-init-hook 'frame-initialize)
219 ;; (add-hook 'window-setup-hook 'frame-notice-user-settings)
221 ;; If we create the initial frame, this is it.
222 (defvar frame-initial-frame nil)
224 ;; Record the parameters used in frame-initialize to make the initial frame.
225 (defvar frame-initial-frame-alist)
227 (defvar frame-initial-geometry-arguments nil)
229 ;; startup.el calls this function before loading the user's init
230 ;; file - if there is no frame with a minibuffer open now, create
231 ;; one to display messages while loading the init file.
232 (defun frame-initialize ()
233 "Create an initial frame if necessary."
234 ;; Are we actually running under a window system at all?
235 (if (and initial-window-system
236 (not noninteractive)
237 (not (eq initial-window-system 'pc)))
238 (progn
239 ;; If there is no frame with a minibuffer besides the terminal
240 ;; frame, then we need to create the opening frame. Make sure
241 ;; it has a minibuffer, but let initial-frame-alist omit the
242 ;; minibuffer spec.
243 (or (delq terminal-frame (minibuffer-frame-list))
244 (progn
245 (setq frame-initial-frame-alist
246 (append initial-frame-alist default-frame-alist nil))
247 (or (assq 'horizontal-scroll-bars frame-initial-frame-alist)
248 (setq frame-initial-frame-alist
249 (cons '(horizontal-scroll-bars . t)
250 frame-initial-frame-alist)))
251 (setq frame-initial-frame-alist
252 (cons (cons 'window-system initial-window-system)
253 frame-initial-frame-alist))
254 (setq default-minibuffer-frame
255 (setq frame-initial-frame
256 (make-frame frame-initial-frame-alist)))
257 ;; Delete any specifications for window geometry parameters
258 ;; so that we won't reapply them in frame-notice-user-settings.
259 ;; It would be wrong to reapply them then,
260 ;; because that would override explicit user resizing.
261 (setq initial-frame-alist
262 (frame-remove-geometry-params initial-frame-alist))))
263 ;; Copy the environment of the Emacs process into the new frame.
264 (set-frame-parameter frame-initial-frame 'environment
265 (frame-parameter terminal-frame 'environment))
266 ;; At this point, we know that we have a frame open, so we
267 ;; can delete the terminal frame.
268 (delete-frame terminal-frame)
269 (setq terminal-frame nil))))
271 (defvar frame-notice-user-settings t
272 "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
274 (declare-function tool-bar-mode "tool-bar" (&optional arg))
276 ;; startup.el calls this function after loading the user's init
277 ;; file. Now default-frame-alist and initial-frame-alist contain
278 ;; information to which we must react; do what needs to be done.
279 (defun frame-notice-user-settings ()
280 "Act on user's init file settings of frame parameters.
281 React to settings of `initial-frame-alist',
282 `window-system-default-frame-alist' and `default-frame-alist'
283 there (in decreasing order of priority)."
284 ;; Creating and deleting frames may shift the selected frame around,
285 ;; and thus the current buffer. Protect against that. We don't
286 ;; want to use save-excursion here, because that may also try to set
287 ;; the buffer of the selected window, which fails when the selected
288 ;; window is the minibuffer.
289 (let ((old-buffer (current-buffer))
290 (window-system-frame-alist
291 (cdr (assq initial-window-system
292 window-system-default-frame-alist))))
294 (when (and frame-notice-user-settings
295 (null frame-initial-frame))
296 ;; This case happens when we don't have a window system, and
297 ;; also for MS-DOS frames.
298 (let ((parms (frame-parameters frame-initial-frame)))
299 ;; Don't change the frame names.
300 (setq parms (delq (assq 'name parms) parms))
301 ;; Can't modify the minibuffer parameter, so don't try.
302 (setq parms (delq (assq 'minibuffer parms) parms))
303 (modify-frame-parameters nil
304 (if (null initial-window-system)
305 (append initial-frame-alist
306 window-system-frame-alist
307 default-frame-alist
308 parms
309 nil)
310 ;; initial-frame-alist and
311 ;; default-frame-alist were already
312 ;; applied in pc-win.el.
313 parms))
314 (if (null initial-window-system) ;; MS-DOS does this differently in pc-win.el
315 (let ((newparms (frame-parameters))
316 (frame (selected-frame)))
317 (tty-handle-reverse-video frame newparms)
318 ;; If we changed the background color, we need to update
319 ;; the background-mode parameter, and maybe some faces,
320 ;; too.
321 (when (assq 'background-color newparms)
322 (unless (or (assq 'background-mode initial-frame-alist)
323 (assq 'background-mode default-frame-alist))
324 (frame-set-background-mode frame))
325 (face-set-after-frame-default frame))))))
327 ;; If the initial frame is still around, apply initial-frame-alist
328 ;; and default-frame-alist to it.
329 (when (frame-live-p frame-initial-frame)
331 ;; When tool-bar has been switched off, correct the frame size
332 ;; by the lines added in x-create-frame for the tool-bar and
333 ;; switch `tool-bar-mode' off.
334 (when (display-graphic-p)
335 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
336 (assq 'tool-bar-lines window-system-frame-alist)
337 (assq 'tool-bar-lines default-frame-alist))))
338 (when (and tool-bar-originally-present
339 (or (null tool-bar-lines)
340 (null (cdr tool-bar-lines))
341 (eq 0 (cdr tool-bar-lines))))
342 (let* ((char-height (frame-char-height frame-initial-frame))
343 (image-height tool-bar-images-pixel-height)
344 (margin (cond ((and (consp tool-bar-button-margin)
345 (integerp (cdr tool-bar-button-margin))
346 (> tool-bar-button-margin 0))
347 (cdr tool-bar-button-margin))
348 ((and (integerp tool-bar-button-margin)
349 (> tool-bar-button-margin 0))
350 tool-bar-button-margin)
351 (t 0)))
352 (relief (if (and (integerp tool-bar-button-relief)
353 (> tool-bar-button-relief 0))
354 tool-bar-button-relief 3))
355 (lines (/ (+ image-height
356 (* 2 margin)
357 (* 2 relief)
358 (1- char-height))
359 char-height))
360 (height (frame-parameter frame-initial-frame 'height))
361 (newparms (list (cons 'height (- height lines))))
362 (initial-top (cdr (assq 'top
363 frame-initial-geometry-arguments)))
364 (top (frame-parameter frame-initial-frame 'top)))
365 (when (and (consp initial-top) (eq '- (car initial-top)))
366 (let ((adjusted-top
367 (cond ((and (consp top)
368 (eq '+ (car top)))
369 (list '+
370 (+ (cadr top)
371 (* lines char-height))))
372 ((and (consp top)
373 (eq '- (car top)))
374 (list '-
375 (- (cadr top)
376 (* lines char-height))))
377 (t (+ top (* lines char-height))))))
378 (setq newparms
379 (append newparms
380 `((top . ,adjusted-top))
381 nil))))
382 (modify-frame-parameters frame-initial-frame newparms)
383 (tool-bar-mode -1)))))
385 ;; The initial frame we create above always has a minibuffer.
386 ;; If the user wants to remove it, or make it a minibuffer-only
387 ;; frame, then we'll have to delete the current frame and make a
388 ;; new one; you can't remove or add a root window to/from an
389 ;; existing frame.
391 ;; NOTE: default-frame-alist was nil when we created the
392 ;; existing frame. We need to explicitly include
393 ;; default-frame-alist in the parameters of the screen we
394 ;; create here, so that its new value, gleaned from the user's
395 ;; .emacs file, will be applied to the existing screen.
396 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
397 (assq 'minibuffer window-system-frame-alist)
398 (assq 'minibuffer default-frame-alist)
399 '(minibuffer . t)))
401 ;; Create the new frame.
402 (let (parms new)
403 ;; If the frame isn't visible yet, wait till it is.
404 ;; If the user has to position the window,
405 ;; Emacs doesn't know its real position until
406 ;; the frame is seen to be visible.
407 (while (not (cdr (assq 'visibility
408 (frame-parameters frame-initial-frame))))
409 (sleep-for 1))
410 (setq parms (frame-parameters frame-initial-frame))
412 ;; Get rid of `name' unless it was specified explicitly before.
413 (or (assq 'name frame-initial-frame-alist)
414 (setq parms (delq (assq 'name parms) parms)))
415 ;; An explicit parent-id is a request to XEmbed the frame.
416 (or (assq 'parent-id frame-initial-frame-alist)
417 (setq parms (delq (assq 'parent-id parms) parms)))
419 (setq parms (append initial-frame-alist
420 window-system-frame-alist
421 default-frame-alist
422 parms
423 nil))
425 ;; Get rid of `reverse', because that was handled
426 ;; when we first made the frame.
427 (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
429 (if (assq 'height frame-initial-geometry-arguments)
430 (setq parms (assq-delete-all 'height parms)))
431 (if (assq 'width frame-initial-geometry-arguments)
432 (setq parms (assq-delete-all 'width parms)))
433 (if (assq 'left frame-initial-geometry-arguments)
434 (setq parms (assq-delete-all 'left parms)))
435 (if (assq 'top frame-initial-geometry-arguments)
436 (setq parms (assq-delete-all 'top parms)))
437 (setq new
438 (make-frame
439 ;; Use the geometry args that created the existing
440 ;; frame, rather than the parms we get for it.
441 (append frame-initial-geometry-arguments
442 '((user-size . t) (user-position . t))
443 parms)))
444 ;; The initial frame, which we are about to delete, may be
445 ;; the only frame with a minibuffer. If it is, create a
446 ;; new one.
447 (or (delq frame-initial-frame (minibuffer-frame-list))
448 (make-initial-minibuffer-frame nil))
450 ;; If the initial frame is serving as a surrogate
451 ;; minibuffer frame for any frames, we need to wean them
452 ;; onto a new frame. The default-minibuffer-frame
453 ;; variable must be handled similarly.
454 (let ((users-of-initial
455 (filtered-frame-list
456 (lambda (frame)
457 (and (not (eq frame frame-initial-frame))
458 (eq (window-frame
459 (minibuffer-window frame))
460 frame-initial-frame))))))
461 (if (or users-of-initial
462 (eq default-minibuffer-frame frame-initial-frame))
464 ;; Choose an appropriate frame. Prefer frames which
465 ;; are only minibuffers.
466 (let* ((new-surrogate
467 (car
468 (or (filtered-frame-list
469 (lambda (frame)
470 (eq (cdr (assq 'minibuffer
471 (frame-parameters frame)))
472 'only)))
473 (minibuffer-frame-list))))
474 (new-minibuffer (minibuffer-window new-surrogate)))
476 (if (eq default-minibuffer-frame frame-initial-frame)
477 (setq default-minibuffer-frame new-surrogate))
479 ;; Wean the frames using frame-initial-frame as
480 ;; their minibuffer frame.
481 (dolist (frame users-of-initial)
482 (modify-frame-parameters
483 frame (list (cons 'minibuffer new-minibuffer)))))))
485 ;; Redirect events enqueued at this frame to the new frame.
486 ;; Is this a good idea?
487 (redirect-frame-focus frame-initial-frame new)
489 ;; Finally, get rid of the old frame.
490 (delete-frame frame-initial-frame t))
492 ;; Otherwise, we don't need all that rigamarole; just apply
493 ;; the new parameters.
494 (let (newparms allparms tail)
495 (setq allparms (append initial-frame-alist
496 window-system-frame-alist
497 default-frame-alist nil))
498 (if (assq 'height frame-initial-geometry-arguments)
499 (setq allparms (assq-delete-all 'height allparms)))
500 (if (assq 'width frame-initial-geometry-arguments)
501 (setq allparms (assq-delete-all 'width allparms)))
502 (if (assq 'left frame-initial-geometry-arguments)
503 (setq allparms (assq-delete-all 'left allparms)))
504 (if (assq 'top frame-initial-geometry-arguments)
505 (setq allparms (assq-delete-all 'top allparms)))
506 (setq tail allparms)
507 ;; Find just the parms that have changed since we first
508 ;; made this frame. Those are the ones actually set by
509 ;; the init file. For those parms whose values we already knew
510 ;; (such as those spec'd by command line options)
511 ;; it is undesirable to specify the parm again
512 ;; once the user has seen the frame and been able to alter it
513 ;; manually.
514 (while tail
515 (let (newval oldval)
516 (setq oldval (assq (car (car tail))
517 frame-initial-frame-alist))
518 (setq newval (cdr (assq (car (car tail)) allparms)))
519 (or (and oldval (eq (cdr oldval) newval))
520 (setq newparms
521 (cons (cons (car (car tail)) newval) newparms))))
522 (setq tail (cdr tail)))
523 (setq newparms (nreverse newparms))
524 (modify-frame-parameters frame-initial-frame
525 newparms)
526 ;; If we changed the background color,
527 ;; we need to update the background-mode parameter
528 ;; and maybe some faces too.
529 (when (assq 'background-color newparms)
530 (unless (assq 'background-mode newparms)
531 (frame-set-background-mode frame-initial-frame))
532 (face-set-after-frame-default frame-initial-frame)))))
534 ;; Restore the original buffer.
535 (set-buffer old-buffer)
537 ;; Make sure the initial frame can be GC'd if it is ever deleted.
538 ;; Make sure frame-notice-user-settings does nothing if called twice.
539 (setq frame-notice-user-settings nil)
540 (setq frame-initial-frame nil)))
542 (defun make-initial-minibuffer-frame (display)
543 (let ((parms (append minibuffer-frame-alist '((minibuffer . only)))))
544 (if display
545 (make-frame-on-display display parms)
546 (make-frame parms))))
548 ;;;; Creation of additional frames, and other frame miscellanea
550 (defun modify-all-frames-parameters (alist)
551 "Modify all current and future frames' parameters according to ALIST.
552 This changes `default-frame-alist' and possibly `initial-frame-alist'.
553 Furthermore, this function removes all parameters in ALIST from
554 `window-system-default-frame-alist'.
555 See help of `modify-frame-parameters' for more information."
556 (dolist (frame (frame-list))
557 (modify-frame-parameters frame alist))
559 (dolist (pair alist) ;; conses to add/replace
560 ;; initial-frame-alist needs setting only when
561 ;; frame-notice-user-settings is true.
562 (and frame-notice-user-settings
563 (setq initial-frame-alist
564 (assq-delete-all (car pair) initial-frame-alist)))
565 (setq default-frame-alist
566 (assq-delete-all (car pair) default-frame-alist))
567 ;; Remove any similar settings from the window-system specific
568 ;; parameters---they would override default-frame-alist.
569 (dolist (w window-system-default-frame-alist)
570 (setcdr w (assq-delete-all (car pair) (cdr w)))))
572 (and frame-notice-user-settings
573 (setq initial-frame-alist (append initial-frame-alist alist)))
574 (setq default-frame-alist (append default-frame-alist alist)))
576 (defun get-other-frame ()
577 "Return some frame other than the current frame.
578 Create one if necessary. Note that the minibuffer frame, if separate,
579 is not considered (see `next-frame')."
580 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
581 (make-frame)
582 (next-frame (selected-frame)))))
585 (defun next-multiframe-window ()
586 "Select the next window, regardless of which frame it is on."
587 (interactive)
588 (select-window (next-window (selected-window)
589 (> (minibuffer-depth) 0)
591 (select-frame-set-input-focus (selected-frame)))
593 (defun previous-multiframe-window ()
594 "Select the previous window, regardless of which frame it is on."
595 (interactive)
596 (select-window (previous-window (selected-window)
597 (> (minibuffer-depth) 0)
599 (select-frame-set-input-focus (selected-frame)))
601 (declare-function x-initialize-window-system "term/x-win" ())
602 (declare-function ns-initialize-window-system "term/ns-win" ())
603 (defvar x-display-name) ; term/x-win
605 (defun make-frame-on-display (display &optional parameters)
606 "Make a frame on display DISPLAY.
607 The optional argument PARAMETERS specifies additional frame parameters."
608 (interactive "sMake frame on display: ")
609 (cond ((featurep 'ns)
610 (when (and (boundp 'ns-initialized) (not ns-initialized))
611 (setq x-display-name display)
612 (ns-initialize-window-system))
613 (make-frame `((window-system . ns)
614 (display . ,display) . ,parameters)))
615 ((eq system-type 'windows-nt)
616 ;; On Windows, ignore DISPLAY.
617 (make-frame parameters))
619 (unless (string-match-p "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display)
620 (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
621 (when (and (boundp 'x-initialized) (not x-initialized))
622 (setq x-display-name display)
623 (x-initialize-window-system))
624 (make-frame `((window-system . x)
625 (display . ,display) . ,parameters)))))
627 (declare-function x-close-connection "xfns.c" (terminal))
629 (defun close-display-connection (display)
630 "Close the connection to a display, deleting all its associated frames.
631 For DISPLAY, specify either a frame or a display name (a string).
632 If DISPLAY is nil, that stands for the selected frame's display."
633 (interactive
634 (list
635 (let* ((default (frame-parameter nil 'display))
636 (display (completing-read
637 (format "Close display (default %s): " default)
638 (delete-dups
639 (mapcar (lambda (frame)
640 (frame-parameter frame 'display))
641 (frame-list)))
642 nil t nil nil
643 default)))
644 (if (zerop (length display)) default display))))
645 (let ((frames (delq nil
646 (mapcar (lambda (frame)
647 (if (equal display
648 (frame-parameter frame 'display))
649 frame))
650 (frame-list)))))
651 (if (and (consp frames)
652 (not (y-or-n-p (if (cdr frames)
653 (format "Delete %s frames? " (length frames))
654 (format "Delete %s ? " (car frames))))))
655 (error "Abort!")
656 (mapc 'delete-frame frames)
657 (x-close-connection display))))
659 (defun make-frame-command ()
660 "Make a new frame, on the same terminal as the selected frame.
661 If the terminal is a text-only terminal, this also selects the
662 new frame."
663 (interactive)
664 (if (display-graphic-p)
665 (make-frame)
666 (select-frame (make-frame))))
668 (defvar before-make-frame-hook nil
669 "Functions to run before a frame is created.")
671 (defvar after-make-frame-functions nil
672 "Functions to run after a frame is created.
673 The functions are run with one arg, the newly created frame.")
675 (defvar after-setting-font-hook nil
676 "Functions to run after a frame's font has been changed.")
678 ;; Alias, kept temporarily.
679 (define-obsolete-function-alias 'new-frame 'make-frame "22.1")
681 (defvar frame-inherited-parameters '()
682 ;; FIXME: Shouldn't we add `font' here as well?
683 "Parameters `make-frame' copies from the `selected-frame' to the new frame.")
685 (defun make-frame (&optional parameters)
686 "Return a newly created frame displaying the current buffer.
687 Optional argument PARAMETERS is an alist of frame parameters for
688 the new frame. Each element of PARAMETERS should have the
689 form (NAME . VALUE), for example:
691 (name . STRING) The frame should be named STRING.
693 (width . NUMBER) The frame should be NUMBER characters in width.
694 (height . NUMBER) The frame should be NUMBER text lines high.
696 You cannot specify either `width' or `height', you must specify
697 neither or both.
699 (minibuffer . t) The frame should have a minibuffer.
700 (minibuffer . nil) The frame should have no minibuffer.
701 (minibuffer . only) The frame should contain only a minibuffer.
702 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
704 (window-system . nil) The frame should be displayed on a terminal device.
705 (window-system . x) The frame should be displayed in an X window.
707 (terminal . TERMINAL) The frame should use the terminal object TERMINAL.
709 In addition, any parameter specified in `default-frame-alist',
710 but not present in PARAMETERS, is applied.
712 Before creating the frame (via `frame-creation-function-alist'),
713 this function runs the hook `before-make-frame-hook'. After
714 creating the frame, it runs the hook `after-make-frame-functions'
715 with one arg, the newly created frame.
717 On graphical displays, this function does not itself make the new
718 frame the selected frame. However, the window system may select
719 the new frame according to its own rules."
720 (interactive)
721 (let* ((w (cond
722 ((assq 'terminal parameters)
723 (let ((type (terminal-live-p (cdr (assq 'terminal parameters)))))
724 (cond
725 ((eq type t) nil)
726 ((eq type nil) (error "Terminal %s does not exist"
727 (cdr (assq 'terminal parameters))))
728 (t type))))
729 ((assq 'window-system parameters)
730 (cdr (assq 'window-system parameters)))
731 (t window-system)))
732 (frame-creation-function (cdr (assq w frame-creation-function-alist)))
733 (oldframe (selected-frame))
734 (params parameters)
735 frame)
736 (unless frame-creation-function
737 (error "Don't know how to create a frame on window system %s" w))
738 ;; Add parameters from `window-system-default-frame-alist'.
739 (dolist (p (cdr (assq w window-system-default-frame-alist)))
740 (unless (assq (car p) params)
741 (push p params)))
742 ;; Add parameters from `default-frame-alist'.
743 (dolist (p default-frame-alist)
744 (unless (assq (car p) params)
745 (push p params)))
746 ;; Now make the frame.
747 (run-hooks 'before-make-frame-hook)
748 (setq frame (funcall frame-creation-function params))
749 (normal-erase-is-backspace-setup-frame frame)
750 ;; Inherit the original frame's parameters.
751 (dolist (param frame-inherited-parameters)
752 (unless (assq param parameters) ;Overridden by explicit parameters.
753 (let ((val (frame-parameter oldframe param)))
754 (when val (set-frame-parameter frame param val)))))
755 (run-hook-with-args 'after-make-frame-functions frame)
756 frame))
758 (defun filtered-frame-list (predicate)
759 "Return a list of all live frames which satisfy PREDICATE."
760 (let* ((frames (frame-list))
761 (list frames))
762 (while (consp frames)
763 (unless (funcall predicate (car frames))
764 (setcar frames nil))
765 (setq frames (cdr frames)))
766 (delq nil list)))
768 (defun minibuffer-frame-list ()
769 "Return a list of all frames with their own minibuffers."
770 (filtered-frame-list
771 (lambda (frame)
772 (eq frame (window-frame (minibuffer-window frame))))))
774 ;; Used to be called `terminal-id' in termdev.el.
775 (defun get-device-terminal (device)
776 "Return the terminal corresponding to DEVICE.
777 DEVICE can be a terminal, a frame, nil (meaning the selected frame's terminal),
778 the name of an X display device (HOST.SERVER.SCREEN) or a tty device file."
779 (cond
780 ((or (null device) (framep device))
781 (frame-terminal device))
782 ((stringp device)
783 (let ((f (car (filtered-frame-list
784 (lambda (frame)
785 (or (equal (frame-parameter frame 'display) device)
786 (equal (frame-parameter frame 'tty) device)))))))
787 (or f (error "Display %s does not exist" device))
788 (frame-terminal f)))
789 ((terminal-live-p device) device)
791 (error "Invalid argument %s in `get-device-terminal'" device))))
793 (defun frames-on-display-list (&optional device)
794 "Return a list of all frames on DEVICE.
796 DEVICE should be a terminal, a frame,
797 or a name of an X display or tty (a string of the form
798 HOST:SERVER.SCREEN).
800 If DEVICE is omitted or nil, it defaults to the selected
801 frame's terminal device."
802 (let* ((terminal (get-device-terminal device))
803 (func #'(lambda (frame)
804 (eq (frame-terminal frame) terminal))))
805 (filtered-frame-list func)))
807 (defun framep-on-display (&optional terminal)
808 "Return the type of frames on TERMINAL.
809 TERMINAL may be a terminal id, a display name or a frame. If it
810 is a frame, its type is returned. If TERMINAL is omitted or nil,
811 it defaults to the selected frame's terminal device. All frames
812 on a given display are of the same type."
813 (or (terminal-live-p terminal)
814 (framep terminal)
815 (framep (car (frames-on-display-list terminal)))))
817 (defun frame-remove-geometry-params (param-list)
818 "Return the parameter list PARAM-LIST, but with geometry specs removed.
819 This deletes all bindings in PARAM-LIST for `top', `left', `width',
820 `height', `user-size' and `user-position' parameters.
821 Emacs uses this to avoid overriding explicit moves and resizings from
822 the user during startup."
823 (setq param-list (cons nil param-list))
824 (let ((tail param-list))
825 (while (consp (cdr tail))
826 (if (and (consp (car (cdr tail)))
827 (memq (car (car (cdr tail)))
828 '(height width top left user-position user-size)))
829 (progn
830 (setq frame-initial-geometry-arguments
831 (cons (car (cdr tail)) frame-initial-geometry-arguments))
832 (setcdr tail (cdr (cdr tail))))
833 (setq tail (cdr tail)))))
834 (setq frame-initial-geometry-arguments
835 (nreverse frame-initial-geometry-arguments))
836 (cdr param-list))
838 (declare-function x-focus-frame "xfns.c" (frame))
840 (defun select-frame-set-input-focus (frame)
841 "Select FRAME, raise it, and set input focus, if possible.
842 If `mouse-autoselect-window' is non-nil, also move mouse pointer
843 to FRAME's selected window. Otherwise, if `focus-follows-mouse'
844 is non-nil, move mouse cursor to FRAME."
845 (select-frame frame)
846 (raise-frame frame)
847 ;; Ensure, if possible, that FRAME gets input focus.
848 (when (memq (window-system frame) '(x w32 ns))
849 (x-focus-frame frame))
850 ;; Move mouse cursor if necessary.
851 (cond
852 (mouse-autoselect-window
853 (let ((edges (window-inside-edges (frame-selected-window frame))))
854 ;; Move mouse cursor into FRAME's selected window to avoid that
855 ;; Emacs mouse-autoselects another window.
856 (set-mouse-position frame (nth 2 edges) (nth 1 edges))))
857 (focus-follows-mouse
858 ;; Move mouse cursor into FRAME to avoid that another frame gets
859 ;; selected by the window manager.
860 (set-mouse-position frame (1- (frame-width frame)) 0))))
862 (defun other-frame (arg)
863 "Select the ARGth different visible frame on current display, and raise it.
864 All frames are arranged in a cyclic order.
865 This command selects the frame ARG steps away in that order.
866 A negative ARG moves in the opposite order.
868 To make this command work properly, you must tell Emacs
869 how the system (or the window manager) generally handles
870 focus-switching between windows. If moving the mouse onto a window
871 selects it (gives it focus), set `focus-follows-mouse' to t.
872 Otherwise, that variable should be nil."
873 (interactive "p")
874 (let ((frame (selected-frame)))
875 (while (> arg 0)
876 (setq frame (next-frame frame))
877 (while (not (eq (frame-visible-p frame) t))
878 (setq frame (next-frame frame)))
879 (setq arg (1- arg)))
880 (while (< arg 0)
881 (setq frame (previous-frame frame))
882 (while (not (eq (frame-visible-p frame) t))
883 (setq frame (previous-frame frame)))
884 (setq arg (1+ arg)))
885 (select-frame-set-input-focus frame)))
887 (defun iconify-or-deiconify-frame ()
888 "Iconify the selected frame, or deiconify if it's currently an icon."
889 (interactive)
890 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
891 (iconify-frame)
892 (make-frame-visible)))
894 (defun suspend-frame ()
895 "Do whatever is right to suspend the current frame.
896 Calls `suspend-emacs' if invoked from the controlling tty device,
897 `suspend-tty' from a secondary tty device, and
898 `iconify-or-deiconify-frame' from an X frame."
899 (interactive)
900 (let ((type (framep (selected-frame))))
901 (cond
902 ((memq type '(x ns w32)) (iconify-or-deiconify-frame))
903 ((eq type t)
904 (if (controlling-tty-p)
905 (suspend-emacs)
906 (suspend-tty)))
907 (t (suspend-emacs)))))
909 (defun make-frame-names-alist ()
910 (let* ((current-frame (selected-frame))
911 (falist
912 (cons
913 (cons (frame-parameter current-frame 'name) current-frame) nil))
914 (frame (next-frame nil t)))
915 (while (not (eq frame current-frame))
916 (progn
917 (setq falist (cons (cons (frame-parameter frame 'name) frame) falist))
918 (setq frame (next-frame frame t))))
919 falist))
921 (defvar frame-name-history nil)
922 (defun select-frame-by-name (name)
923 "Select the frame on the current terminal whose name is NAME and raise it.
924 If there is no frame by that name, signal an error."
925 (interactive
926 (let* ((frame-names-alist (make-frame-names-alist))
927 (default (car (car frame-names-alist)))
928 (input (completing-read
929 (format "Select Frame (default %s): " default)
930 frame-names-alist nil t nil 'frame-name-history)))
931 (if (= (length input) 0)
932 (list default)
933 (list input))))
934 (let* ((frame-names-alist (make-frame-names-alist))
935 (frame (cdr (assoc name frame-names-alist))))
936 (if frame
937 (select-frame-set-input-focus frame)
938 (error "There is no frame named `%s'" name))))
940 ;;;; Frame configurations
942 (defun current-frame-configuration ()
943 "Return a list describing the positions and states of all frames.
944 Its car is `frame-configuration'.
945 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
946 where
947 FRAME is a frame object,
948 ALIST is an association list specifying some of FRAME's parameters, and
949 WINDOW-CONFIG is a window configuration object for FRAME."
950 (cons 'frame-configuration
951 (mapcar (lambda (frame)
952 (list frame
953 (frame-parameters frame)
954 (current-window-configuration frame)))
955 (frame-list))))
957 (defun set-frame-configuration (configuration &optional nodelete)
958 "Restore the frames to the state described by CONFIGURATION.
959 Each frame listed in CONFIGURATION has its position, size, window
960 configuration, and other parameters set as specified in CONFIGURATION.
961 However, this function does not restore deleted frames.
963 Ordinarily, this function deletes all existing frames not
964 listed in CONFIGURATION. But if optional second argument NODELETE
965 is given and non-nil, the unwanted frames are iconified instead."
966 (or (frame-configuration-p configuration)
967 (signal 'wrong-type-argument
968 (list 'frame-configuration-p configuration)))
969 (let ((config-alist (cdr configuration))
970 frames-to-delete)
971 (dolist (frame (frame-list))
972 (let ((parameters (assq frame config-alist)))
973 (if parameters
974 (progn
975 (modify-frame-parameters
976 frame
977 ;; Since we can't set a frame's minibuffer status,
978 ;; we might as well omit the parameter altogether.
979 (let* ((parms (nth 1 parameters))
980 (mini (assq 'minibuffer parms))
981 (name (assq 'name parms))
982 (explicit-name (cdr (assq 'explicit-name parms))))
983 (when mini (setq parms (delq mini parms)))
984 ;; Leave name in iff it was set explicitly.
985 ;; This should fix the behavior reported in
986 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg01632.html
987 (when (and name (not explicit-name))
988 (setq parms (delq name parms)))
989 parms))
990 (set-window-configuration (nth 2 parameters)))
991 (setq frames-to-delete (cons frame frames-to-delete)))))
992 (mapc (if nodelete
993 ;; Note: making frames invisible here was tried
994 ;; but led to some strange behavior--each time the frame
995 ;; was made visible again, the window manager asked afresh
996 ;; for where to put it.
997 'iconify-frame
998 'delete-frame)
999 frames-to-delete)))
1001 ;;;; Convenience functions for accessing and interactively changing
1002 ;;;; frame parameters.
1004 (defun frame-height (&optional frame)
1005 "Return number of lines available for display on FRAME.
1006 If FRAME is omitted, describe the currently selected frame.
1007 Exactly what is included in the return value depends on the
1008 window-system and toolkit in use - see `frame-pixel-height' for
1009 more details. The lines are in units of the default font height.
1011 The result is roughly related to the frame pixel height via
1012 height in pixels = height in lines * `frame-char-height'.
1013 However, this is only approximate, and is complicated e.g. by the
1014 fact that individual window lines and menu bar lines can have
1015 differing font heights."
1016 (cdr (assq 'height (frame-parameters frame))))
1018 (defun frame-width (&optional frame)
1019 "Return number of columns available for display on FRAME.
1020 If FRAME is omitted, describe the currently selected frame."
1021 (cdr (assq 'width (frame-parameters frame))))
1023 (declare-function x-list-fonts "xfaces.c"
1024 (pattern &optional face frame maximum width))
1026 (define-obsolete-function-alias 'set-default-font 'set-frame-font "23.1")
1027 (defun set-frame-font (font-name &optional keep-size)
1028 "Set the font of the selected frame to FONT-NAME.
1029 When called interactively, prompt for the name of the font to use.
1030 To get the frame's current default font, use `frame-parameters'.
1032 The default behavior is to keep the numbers of lines and columns in
1033 the frame, thus may change its pixel size. If optional KEEP-SIZE is
1034 non-nil (interactively, prefix argument) the current frame size (in
1035 pixels) is kept by adjusting the numbers of the lines and columns."
1036 (interactive
1037 (let* ((completion-ignore-case t)
1038 (font (completing-read "Font name: "
1039 ;; x-list-fonts will fail with an error
1040 ;; if this frame doesn't support fonts.
1041 (x-list-fonts "*" nil (selected-frame))
1042 nil nil nil nil
1043 (frame-parameter nil 'font))))
1044 (list font current-prefix-arg)))
1045 (let (fht fwd)
1046 (if keep-size
1047 (setq fht (* (frame-parameter nil 'height) (frame-char-height))
1048 fwd (* (frame-parameter nil 'width) (frame-char-width))))
1049 (modify-frame-parameters (selected-frame)
1050 (list (cons 'font font-name)))
1051 (if keep-size
1052 (modify-frame-parameters
1053 (selected-frame)
1054 (list (cons 'height (round fht (frame-char-height)))
1055 (cons 'width (round fwd (frame-char-width)))))))
1056 (run-hooks 'after-setting-font-hook 'after-setting-font-hooks))
1058 (defun set-frame-parameter (frame parameter value)
1059 "Set frame parameter PARAMETER to VALUE on FRAME.
1060 If FRAME is nil, it defaults to the selected frame.
1061 See `modify-frame-parameters'."
1062 (modify-frame-parameters frame (list (cons parameter value))))
1064 (defun set-background-color (color-name)
1065 "Set the background color of the selected frame to COLOR-NAME.
1066 When called interactively, prompt for the name of the color to use.
1067 To get the frame's current background color, use `frame-parameters'."
1068 (interactive (list (facemenu-read-color "Background color: ")))
1069 (modify-frame-parameters (selected-frame)
1070 (list (cons 'background-color color-name)))
1071 (or window-system
1072 (face-set-after-frame-default (selected-frame))))
1074 (defun set-foreground-color (color-name)
1075 "Set the foreground color of the selected frame to COLOR-NAME.
1076 When called interactively, prompt for the name of the color to use.
1077 To get the frame's current foreground color, use `frame-parameters'."
1078 (interactive (list (facemenu-read-color "Foreground color: ")))
1079 (modify-frame-parameters (selected-frame)
1080 (list (cons 'foreground-color color-name)))
1081 (or window-system
1082 (face-set-after-frame-default (selected-frame))))
1084 (defun set-cursor-color (color-name)
1085 "Set the text cursor color of the selected frame to COLOR-NAME.
1086 When called interactively, prompt for the name of the color to use.
1087 To get the frame's current cursor color, use `frame-parameters'."
1088 (interactive (list (facemenu-read-color "Cursor color: ")))
1089 (modify-frame-parameters (selected-frame)
1090 (list (cons 'cursor-color color-name))))
1092 (defun set-mouse-color (color-name)
1093 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
1094 When called interactively, prompt for the name of the color to use.
1095 To get the frame's current mouse color, use `frame-parameters'."
1096 (interactive (list (facemenu-read-color "Mouse color: ")))
1097 (modify-frame-parameters (selected-frame)
1098 (list (cons 'mouse-color
1099 (or color-name
1100 (cdr (assq 'mouse-color
1101 (frame-parameters))))))))
1103 (defun set-border-color (color-name)
1104 "Set the color of the border of the selected frame to COLOR-NAME.
1105 When called interactively, prompt for the name of the color to use.
1106 To get the frame's current border color, use `frame-parameters'."
1107 (interactive (list (facemenu-read-color "Border color: ")))
1108 (modify-frame-parameters (selected-frame)
1109 (list (cons 'border-color color-name))))
1111 (define-minor-mode auto-raise-mode
1112 "Toggle whether or not the selected frame should auto-raise.
1113 With ARG, turn auto-raise mode on if and only if ARG is positive.
1114 Note that this controls Emacs's own auto-raise feature.
1115 Some window managers allow you to enable auto-raise for certain windows.
1116 You can use that for Emacs windows if you wish, but if you do,
1117 that is beyond the control of Emacs and this command has no effect on it."
1118 :variable (frame-parameter nil 'auto-raise)
1119 (if (frame-parameter nil 'auto-raise)
1120 (raise-frame)))
1122 (define-minor-mode auto-lower-mode
1123 "Toggle whether or not the selected frame should auto-lower.
1124 With ARG, turn auto-lower mode on if and only if ARG is positive.
1125 Note that this controls Emacs's own auto-lower feature.
1126 Some window managers allow you to enable auto-lower for certain windows.
1127 You can use that for Emacs windows if you wish, but if you do,
1128 that is beyond the control of Emacs and this command has no effect on it."
1129 :variable (frame-parameter nil 'auto-lower))
1131 (defun set-frame-name (name)
1132 "Set the name of the selected frame to NAME.
1133 When called interactively, prompt for the name of the frame.
1134 The frame name is displayed on the modeline if the terminal displays only
1135 one frame, otherwise the name is displayed on the frame's caption bar."
1136 (interactive "sFrame name: ")
1137 (modify-frame-parameters (selected-frame)
1138 (list (cons 'name name))))
1140 (defun frame-current-scroll-bars (&optional frame)
1141 "Return the current scroll-bar settings in frame FRAME.
1142 Value is a cons (VERTICAL . HORIZ0NTAL) where VERTICAL specifies the
1143 current location of the vertical scroll-bars (left, right, or nil),
1144 and HORIZONTAL specifies the current location of the horizontal scroll
1145 bars (top, bottom, or nil)."
1146 (let ((vert (frame-parameter frame 'vertical-scroll-bars))
1147 (hor nil))
1148 (unless (memq vert '(left right nil))
1149 (setq vert default-frame-scroll-bars))
1150 (cons vert hor)))
1152 ;;;; Frame/display capabilities.
1153 (defun selected-terminal ()
1154 "Return the terminal that is now selected."
1155 (frame-terminal (selected-frame)))
1157 (declare-function msdos-mouse-p "dosfns.c")
1159 (defun display-mouse-p (&optional display)
1160 "Return non-nil if DISPLAY has a mouse available.
1161 DISPLAY can be a display name, a frame, or nil (meaning the selected
1162 frame's display)."
1163 (let ((frame-type (framep-on-display display)))
1164 (cond
1165 ((eq frame-type 'pc)
1166 (msdos-mouse-p))
1167 ((eq system-type 'windows-nt)
1168 (with-no-warnings
1169 (> w32-num-mouse-buttons 0)))
1170 ((memq frame-type '(x ns))
1171 t) ;; We assume X and NeXTstep *always* have a pointing device
1173 (or (and (featurep 'xt-mouse)
1174 xterm-mouse-mode)
1175 ;; t-mouse is distributed with the GPM package. It doesn't have
1176 ;; a toggle.
1177 (featurep 't-mouse))))))
1179 (defun display-popup-menus-p (&optional display)
1180 "Return non-nil if popup menus are supported on DISPLAY.
1181 DISPLAY can be a display name, a frame, or nil (meaning the selected
1182 frame's display).
1183 Support for popup menus requires that the mouse be available."
1184 (and
1185 (let ((frame-type (framep-on-display display)))
1186 (memq frame-type '(x w32 pc ns)))
1187 (display-mouse-p display)))
1189 (defun display-graphic-p (&optional display)
1190 "Return non-nil if DISPLAY is a graphic display.
1191 Graphical displays are those which are capable of displaying several
1192 frames and several different fonts at once. This is true for displays
1193 that use a window system such as X, and false for text-only terminals.
1194 DISPLAY can be a display name, a frame, or nil (meaning the selected
1195 frame's display)."
1196 (not (null (memq (framep-on-display display) '(x w32 ns)))))
1198 (defun display-images-p (&optional display)
1199 "Return non-nil if DISPLAY can display images.
1201 DISPLAY can be a display name, a frame, or nil (meaning the selected
1202 frame's display)."
1203 (and (display-graphic-p display)
1204 (fboundp 'image-mask-p)
1205 (fboundp 'image-size)))
1207 (defalias 'display-multi-frame-p 'display-graphic-p)
1208 (defalias 'display-multi-font-p 'display-graphic-p)
1210 (defun display-selections-p (&optional display)
1211 "Return non-nil if DISPLAY supports selections.
1212 A selection is a way to transfer text or other data between programs
1213 via special system buffers called `selection' or `cut buffer' or
1214 `clipboard'.
1215 DISPLAY can be a display name, a frame, or nil (meaning the selected
1216 frame's display)."
1217 (let ((frame-type (framep-on-display display)))
1218 (cond
1219 ((eq frame-type 'pc)
1220 ;; MS-DOG frames support selections when Emacs runs inside
1221 ;; the Windows' DOS Box.
1222 (with-no-warnings
1223 (not (null dos-windows-version))))
1224 ((memq frame-type '(x w32 ns))
1225 t) ;; FIXME?
1227 nil))))
1229 (declare-function x-display-screens "xfns.c" (&optional terminal))
1231 (defun display-screens (&optional display)
1232 "Return the number of screens associated with DISPLAY."
1233 (let ((frame-type (framep-on-display display)))
1234 (cond
1235 ((memq frame-type '(x w32 ns))
1236 (x-display-screens display))
1238 1))))
1240 (declare-function x-display-pixel-height "xfns.c" (&optional terminal))
1242 (defun display-pixel-height (&optional display)
1243 "Return the height of DISPLAY's screen in pixels.
1244 For character terminals, each character counts as a single pixel."
1245 (let ((frame-type (framep-on-display display)))
1246 (cond
1247 ((memq frame-type '(x w32 ns))
1248 (x-display-pixel-height display))
1250 (frame-height (if (framep display) display (selected-frame)))))))
1252 (declare-function x-display-pixel-width "xfns.c" (&optional terminal))
1254 (defun display-pixel-width (&optional display)
1255 "Return the width of DISPLAY's screen in pixels.
1256 For character terminals, each character counts as a single pixel."
1257 (let ((frame-type (framep-on-display display)))
1258 (cond
1259 ((memq frame-type '(x w32 ns))
1260 (x-display-pixel-width display))
1262 (frame-width (if (framep display) display (selected-frame)))))))
1264 (defcustom display-mm-dimensions-alist nil
1265 "Alist for specifying screen dimensions in millimeters.
1266 The dimensions will be used for `display-mm-height' and
1267 `display-mm-width' if defined for the respective display.
1269 Each element of the alist has the form (display . (width . height)),
1270 e.g. (\":0.0\" . (287 . 215)).
1272 If `display' equals t, it specifies dimensions for all graphical
1273 displays not explicitely specified."
1274 :version "22.1"
1275 :type '(alist :key-type (choice (string :tag "Display name")
1276 (const :tag "Default" t))
1277 :value-type (cons :tag "Dimensions"
1278 (integer :tag "Width")
1279 (integer :tag "Height")))
1280 :group 'frames)
1282 (declare-function x-display-mm-height "xfns.c" (&optional terminal))
1284 (defun display-mm-height (&optional display)
1285 "Return the height of DISPLAY's screen in millimeters.
1286 System values can be overridden by `display-mm-dimensions-alist'.
1287 If the information is unavailable, value is nil."
1288 (and (memq (framep-on-display display) '(x w32 ns))
1289 (or (cddr (assoc (or display (frame-parameter nil 'display))
1290 display-mm-dimensions-alist))
1291 (cddr (assoc t display-mm-dimensions-alist))
1292 (x-display-mm-height display))))
1294 (declare-function x-display-mm-width "xfns.c" (&optional terminal))
1296 (defun display-mm-width (&optional display)
1297 "Return the width of DISPLAY's screen in millimeters.
1298 System values can be overridden by `display-mm-dimensions-alist'.
1299 If the information is unavailable, value is nil."
1300 (and (memq (framep-on-display display) '(x w32 ns))
1301 (or (cadr (assoc (or display (frame-parameter nil 'display))
1302 display-mm-dimensions-alist))
1303 (cadr (assoc t display-mm-dimensions-alist))
1304 (x-display-mm-width display))))
1306 (declare-function x-display-backing-store "xfns.c" (&optional terminal))
1308 (defun display-backing-store (&optional display)
1309 "Return the backing store capability of DISPLAY's screen.
1310 The value may be `always', `when-mapped', `not-useful', or nil if
1311 the question is inapplicable to a certain kind of display."
1312 (let ((frame-type (framep-on-display display)))
1313 (cond
1314 ((memq frame-type '(x w32 ns))
1315 (x-display-backing-store display))
1317 'not-useful))))
1319 (declare-function x-display-save-under "xfns.c" (&optional terminal))
1321 (defun display-save-under (&optional display)
1322 "Return non-nil if DISPLAY's screen supports the SaveUnder feature."
1323 (let ((frame-type (framep-on-display display)))
1324 (cond
1325 ((memq frame-type '(x w32 ns))
1326 (x-display-save-under display))
1328 'not-useful))))
1330 (declare-function x-display-planes "xfns.c" (&optional terminal))
1332 (defun display-planes (&optional display)
1333 "Return the number of planes supported by DISPLAY."
1334 (let ((frame-type (framep-on-display display)))
1335 (cond
1336 ((memq frame-type '(x w32 ns))
1337 (x-display-planes display))
1338 ((eq frame-type 'pc)
1341 (truncate (log (length (tty-color-alist)) 2))))))
1343 (declare-function x-display-color-cells "xfns.c" (&optional terminal))
1345 (defun display-color-cells (&optional display)
1346 "Return the number of color cells supported by DISPLAY."
1347 (let ((frame-type (framep-on-display display)))
1348 (cond
1349 ((memq frame-type '(x w32 ns))
1350 (x-display-color-cells display))
1351 ((eq frame-type 'pc)
1354 (tty-display-color-cells display)))))
1356 (declare-function x-display-visual-class "xfns.c" (&optional terminal))
1358 (defun display-visual-class (&optional display)
1359 "Return the visual class of DISPLAY.
1360 The value is one of the symbols `static-gray', `gray-scale',
1361 `static-color', `pseudo-color', `true-color', or `direct-color'."
1362 (let ((frame-type (framep-on-display display)))
1363 (cond
1364 ((memq frame-type '(x w32 ns))
1365 (x-display-visual-class display))
1366 ((and (memq frame-type '(pc t))
1367 (tty-display-color-p display))
1368 'static-color)
1370 'static-gray))))
1373 ;;;; Frame geometry values
1375 (defun frame-geom-value-cons (type value &optional frame)
1376 "Return equivalent geometry value for FRAME as a cons with car `+'.
1377 A geometry value equivalent to VALUE for FRAME is returned,
1378 where the value is a cons with car `+', not numeric.
1379 TYPE is the car of the original geometry spec (TYPE . VALUE).
1380 It is `top' or `left', depending on which edge VALUE is related to.
1381 VALUE is the cdr of a frame geometry spec: (left/top . VALUE).
1382 If VALUE is a number, then it is converted to a cons value, perhaps
1383 relative to the opposite frame edge from that in the original spec.
1384 FRAME defaults to the selected frame.
1386 Examples (measures in pixels) -
1387 Assuming display height/width=1024, frame height/width=600:
1388 300 inside display edge: 300 => (+ 300)
1389 (+ 300) => (+ 300)
1390 300 inside opposite display edge: (- 300) => (+ 124)
1391 -300 => (+ 124)
1392 300 beyond display edge
1393 (= 724 inside opposite display edge): (+ -300) => (+ -300)
1394 300 beyond display edge
1395 (= 724 inside opposite display edge): (- -300) => (+ 724)
1397 In the 3rd, 4th, and 6th examples, the returned value is relative to
1398 the opposite frame edge from the edge indicated in the input spec."
1399 (cond ((and (consp value) (eq '+ (car value))) ; e.g. (+ 300), (+ -300)
1400 value)
1401 ((natnump value) (list '+ value)) ; e.g. 300 => (+ 300)
1402 (t ; e.g. -300, (- 300), (- -300)
1403 (list '+ (- (if (eq 'left type) ; => (+ 124), (+ 124), (+ 724)
1404 (x-display-pixel-width)
1405 (x-display-pixel-height))
1406 (if (integerp value) (- value) (cadr value))
1407 (if (eq 'left type)
1408 (frame-pixel-width frame)
1409 (frame-pixel-height frame)))))))
1411 (defun frame-geom-spec-cons (spec &optional frame)
1412 "Return equivalent geometry spec for FRAME as a cons with car `+'.
1413 A geometry specification equivalent to SPEC for FRAME is returned,
1414 where the value is a cons with car `+', not numeric.
1415 SPEC is a frame geometry spec: (left . VALUE) or (top . VALUE).
1416 If VALUE is a number, then it is converted to a cons value, perhaps
1417 relative to the opposite frame edge from that in the original spec.
1418 FRAME defaults to the selected frame.
1420 Examples (measures in pixels) -
1421 Assuming display height=1024, frame height=600:
1422 top 300 below display top: (top . 300) => (top + 300)
1423 (top + 300) => (top + 300)
1424 bottom 300 above display bottom: (top - 300) => (top + 124)
1425 (top . -300) => (top + 124)
1426 top 300 above display top
1427 (= bottom 724 above display bottom): (top + -300) => (top + -300)
1428 bottom 300 below display bottom
1429 (= top 724 below display top): (top - -300) => (top + 724)
1431 In the 3rd, 4th, and 6th examples, the returned value is relative to
1432 the opposite frame edge from the edge indicated in the input spec."
1433 (cons (car spec) (frame-geom-value-cons (car spec) (cdr spec))))
1436 (defun delete-other-frames (&optional frame)
1437 "Delete all frames except FRAME.
1438 If FRAME uses another frame's minibuffer, the minibuffer frame is
1439 left untouched. FRAME nil or omitted means use the selected frame."
1440 (interactive)
1441 (unless frame
1442 (setq frame (selected-frame)))
1443 (let* ((mini-frame (window-frame (minibuffer-window frame)))
1444 (frames (delq mini-frame (delq frame (frame-list)))))
1445 ;; Only consider frames on the same terminal.
1446 (dolist (frame (prog1 frames (setq frames nil)))
1447 (if (eq (frame-terminal) (frame-terminal frame))
1448 (push frame frames)))
1449 ;; Delete mon-minibuffer-only frames first, because `delete-frame'
1450 ;; signals an error when trying to delete a mini-frame that's
1451 ;; still in use by another frame.
1452 (dolist (frame frames)
1453 (unless (eq (frame-parameter frame 'minibuffer) 'only)
1454 (delete-frame frame)))
1455 ;; Delete minibuffer-only frames.
1456 (dolist (frame frames)
1457 (when (eq (frame-parameter frame 'minibuffer) 'only)
1458 (delete-frame frame)))))
1460 ;; miscellaneous obsolescence declarations
1461 (define-obsolete-variable-alias 'delete-frame-hook
1462 'delete-frame-functions "22.1")
1465 ;; Highlighting trailing whitespace.
1467 (make-variable-buffer-local 'show-trailing-whitespace)
1469 (defcustom show-trailing-whitespace nil
1470 "Non-nil means highlight trailing whitespace.
1471 This is done in the face `trailing-whitespace'."
1472 :type 'boolean
1473 :safe 'booleanp
1474 :group 'whitespace-faces)
1478 ;; Scrolling
1480 (defgroup scrolling nil
1481 "Scrolling windows."
1482 :version "21.1"
1483 :group 'frames)
1485 (defcustom auto-hscroll-mode t
1486 "Allow or disallow automatic scrolling windows horizontally.
1487 If non-nil, windows are automatically scrolled horizontally to make
1488 point visible."
1489 :version "21.1"
1490 :type 'boolean
1491 :group 'scrolling)
1492 (defvaralias 'automatic-hscrolling 'auto-hscroll-mode)
1495 ;; Blinking cursor
1497 (defgroup cursor nil
1498 "Displaying text cursors."
1499 :version "21.1"
1500 :group 'frames)
1502 (defcustom blink-cursor-delay 0.5
1503 "Seconds of idle time after which cursor starts to blink."
1504 :type 'number
1505 :group 'cursor)
1507 (defcustom blink-cursor-interval 0.5
1508 "Length of cursor blink interval in seconds."
1509 :type 'number
1510 :group 'cursor)
1512 (defvar blink-cursor-idle-timer nil
1513 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
1514 The function `blink-cursor-start' is called when the timer fires.")
1516 (defvar blink-cursor-timer nil
1517 "Timer started from `blink-cursor-start'.
1518 This timer calls `blink-cursor-timer-function' every
1519 `blink-cursor-interval' seconds.")
1521 (defun blink-cursor-start ()
1522 "Timer function called from the timer `blink-cursor-idle-timer'.
1523 This starts the timer `blink-cursor-timer', which makes the cursor blink
1524 if appropriate. It also arranges to cancel that timer when the next
1525 command starts, by installing a pre-command hook."
1526 (when (null blink-cursor-timer)
1527 ;; Set up the timer first, so that if this signals an error,
1528 ;; blink-cursor-end is not added to pre-command-hook.
1529 (setq blink-cursor-timer
1530 (run-with-timer blink-cursor-interval blink-cursor-interval
1531 'blink-cursor-timer-function))
1532 (add-hook 'pre-command-hook 'blink-cursor-end)
1533 (internal-show-cursor nil nil)))
1535 (defun blink-cursor-timer-function ()
1536 "Timer function of timer `blink-cursor-timer'."
1537 (internal-show-cursor nil (not (internal-show-cursor-p))))
1539 (defun blink-cursor-end ()
1540 "Stop cursor blinking.
1541 This is installed as a pre-command hook by `blink-cursor-start'.
1542 When run, it cancels the timer `blink-cursor-timer' and removes
1543 itself as a pre-command hook."
1544 (remove-hook 'pre-command-hook 'blink-cursor-end)
1545 (internal-show-cursor nil t)
1546 (when blink-cursor-timer
1547 (cancel-timer blink-cursor-timer)
1548 (setq blink-cursor-timer nil)))
1550 (define-minor-mode blink-cursor-mode
1551 "Toggle blinking cursor mode.
1552 With a numeric argument, turn blinking cursor mode on if ARG is positive,
1553 otherwise turn it off. When blinking cursor mode is enabled, the
1554 cursor of the selected window blinks.
1556 Note that this command is effective only when Emacs
1557 displays through a window system, because then Emacs does its own
1558 cursor display. On a text-only terminal, this is not implemented."
1559 :init-value (not (or noninteractive
1560 no-blinking-cursor
1561 (eq system-type 'ms-dos)
1562 (not (memq window-system '(x w32)))))
1563 :initialize 'custom-initialize-delay
1564 :group 'cursor
1565 :global t
1566 (if blink-cursor-idle-timer (cancel-timer blink-cursor-idle-timer))
1567 (setq blink-cursor-idle-timer nil)
1568 (blink-cursor-end)
1569 (when blink-cursor-mode
1570 ;; Hide the cursor.
1571 ;;(internal-show-cursor nil nil)
1572 (setq blink-cursor-idle-timer
1573 (run-with-idle-timer blink-cursor-delay
1574 blink-cursor-delay
1575 'blink-cursor-start))))
1577 (define-obsolete-variable-alias 'blink-cursor 'blink-cursor-mode "22.1")
1579 ;; Hourglass pointer
1581 (defcustom display-hourglass t
1582 "Non-nil means show an hourglass pointer, when Emacs is busy.
1583 This feature only works when on a window system that can change
1584 cursor shapes."
1585 :type 'boolean
1586 :group 'cursor)
1588 (defcustom hourglass-delay 1
1589 "Seconds to wait before displaying an hourglass pointer when Emacs is busy."
1590 :type 'number
1591 :group 'cursor)
1594 (defcustom cursor-in-non-selected-windows t
1595 "Non-nil means show a hollow box cursor in non-selected windows.
1596 If nil, don't show a cursor except in the selected window.
1597 If t, display a cursor related to the usual cursor type
1598 \(a solid box becomes hollow, a bar becomes a narrower bar).
1599 You can also specify the cursor type as in the `cursor-type' variable.
1600 Use Custom to set this variable to get the display updated."
1601 :tag "Cursor In Non-selected Windows"
1602 :type 'boolean
1603 :group 'cursor
1604 :set #'(lambda (symbol value)
1605 (set-default symbol value)
1606 (force-mode-line-update t)))
1609 ;;;; Key bindings
1611 (define-key ctl-x-5-map "2" 'make-frame-command)
1612 (define-key ctl-x-5-map "1" 'delete-other-frames)
1613 (define-key ctl-x-5-map "0" 'delete-frame)
1614 (define-key ctl-x-5-map "o" 'other-frame)
1616 (provide 'frame)
1618 ;; arch-tag: 82979c70-b8f2-4306-b2ad-ddbd6b328b56
1619 ;;; frame.el ends here