1 ;;; frame.el --- multi-frame management independent of window systems.
3 ;; Copyright (C) 1993, 1994, 1996, 1997, 2000, 2001
4 ;; 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 2, or (at your option)
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; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 (defvar frame-creation-function nil
29 "Window-system dependent function to call to create a new frame.
30 The window system startup file should set this to its frame creation
31 function, which should take an alist of parameters as its argument.")
33 ;;; The initial value given here for used to ask for a minibuffer.
34 ;;; But that's not necessary, because the default is to have one.
35 ;;; By not specifying it here, we let an X resource specify it.
36 (defcustom initial-frame-alist nil
37 "*Alist of frame parameters for creating the initial X window frame.
38 You can set this in your `.emacs' file; for example,
39 (setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55)))
40 Parameters specified here supersede the values given in `default-frame-alist'.
42 If the value calls for a frame without a minibuffer, and you have not created
43 a minibuffer frame on your own, one is created according to
44 `minibuffer-frame-alist'.
46 You can specify geometry-related options for just the initial frame
47 by setting this variable in your `.emacs' file; however, they won't
48 take effect until Emacs reads `.emacs', which happens after first creating
49 the frame. If you want the frame to have the proper geometry as soon
50 as it appears, you need to use this three-step process:
51 * Specify X resources to give the geometry you want.
52 * Set `default-frame-alist' to override these options so that they
53 don't affect subsequent frames.
54 * Set `initial-frame-alist' in a way that matches the X resources,
55 to override what you put in `default-frame-alist'."
56 :type
'(repeat (cons :format
"%v"
57 (symbol :tag
"Parameter")
61 (defcustom minibuffer-frame-alist
'((width .
80) (height .
2))
62 "*Alist of frame parameters for initially creating a minibuffer frame.
63 You can set this in your `.emacs' file; for example,
64 (setq minibuffer-frame-alist
65 '((top . 1) (left . 1) (width . 80) (height . 2)))
66 Parameters specified here supersede the values given in
67 `default-frame-alist', for a minibuffer frame."
68 :type
'(repeat (cons :format
"%v"
69 (symbol :tag
"Parameter")
73 (defcustom pop-up-frame-alist nil
74 "*Alist of frame parameters used when creating pop-up frames.
75 Pop-up frames are used for completions, help, and the like.
76 This variable can be set in your init file, like this:
77 (setq pop-up-frame-alist '((width . 80) (height . 20)))
78 These supersede the values given in `default-frame-alist',
80 :type
'(repeat (cons :format
"%v"
81 (symbol :tag
"Parameter")
85 (setq pop-up-frame-function
87 (make-frame pop-up-frame-alist
))))
89 (defcustom special-display-frame-alist
90 '((height .
14) (width .
80) (unsplittable . t
))
91 "*Alist of frame parameters used when creating special frames.
92 Special frames are used for buffers whose names are in
93 `special-display-buffer-names' and for buffers whose names match
94 one of the regular expressions in `special-display-regexps'.
95 This variable can be set in your init file, like this:
96 (setq special-display-frame-alist '((width . 80) (height . 20)))
97 These supersede the values given in `default-frame-alist'."
98 :type
'(repeat (cons :format
"%v"
99 (symbol :tag
"Parameter")
100 (sexp :tag
"Value")))
103 (defun special-display-popup-frame (buffer &optional args
)
104 "Display BUFFER in its own frame, reusing an existing window if any.
105 Return the window chosen.
106 Currently we do not insist on selecting the window within its frame.
107 If ARGS is an alist, use it as a list of frame parameter specs.
108 If ARGS is a list whose car is a symbol,
109 use (car ARGS) as a function to do the work.
110 Pass it BUFFER as first arg, and (cdr ARGS) gives the rest of the args."
111 (if (and args
(symbolp (car args
)))
112 (apply (car args
) buffer
(cdr args
))
113 (let ((window (get-buffer-window buffer t
)))
115 ;; If we have a window already, make it visible.
116 (let ((frame (window-frame window
)))
117 (make-frame-visible frame
)
120 ;; If no window yet, make one in a new frame.
121 (let ((frame (make-frame (append args special-display-frame-alist
))))
122 (set-window-buffer (frame-selected-window frame
) buffer
)
123 (set-window-dedicated-p (frame-selected-window frame
) t
)
124 (frame-selected-window frame
))))))
126 (defun handle-delete-frame (event)
127 "Handle delete-frame events from the X server."
129 (let ((frame (posn-window (event-start event
)))
133 (and (frame-visible-p (car tail
))
134 (not (eq (car tail
) frame
))
136 (setq tail
(cdr tail
)))
138 (delete-frame frame t
)
139 ;; Gildea@x.org says it is ok to ask questions before terminating.
140 (save-buffers-kill-emacs))))
142 ;;;; Arrangement of frames at startup
144 ;;; 1) Load the window system startup file from the lisp library and read the
145 ;;; high-priority arguments (-q and the like). The window system startup
146 ;;; file should create any frames specified in the window system defaults.
148 ;;; 2) If no frames have been opened, we open an initial text frame.
150 ;;; 3) Once the init file is done, we apply any newly set parameters
151 ;;; in initial-frame-alist to the frame.
153 ;; These are now called explicitly at the proper times,
154 ;; since that is easier to understand.
155 ;; Actually using hooks within Emacs is bad for future maintenance. --rms.
156 ;; (add-hook 'before-init-hook 'frame-initialize)
157 ;; (add-hook 'window-setup-hook 'frame-notice-user-settings)
159 ;;; If we create the initial frame, this is it.
160 (defvar frame-initial-frame nil
)
162 ;; Record the parameters used in frame-initialize to make the initial frame.
163 (defvar frame-initial-frame-alist
)
165 (defvar frame-initial-geometry-arguments nil
)
167 ;;; startup.el calls this function before loading the user's init
168 ;;; file - if there is no frame with a minibuffer open now, create
169 ;;; one to display messages while loading the init file.
170 (defun frame-initialize ()
171 "Create an initial frame if necessary."
172 ;; Are we actually running under a window system at all?
173 (if (and window-system
(not noninteractive
) (not (eq window-system
'pc
)))
175 ;; Turn on special-display processing only if there's a window system.
176 (setq special-display-function
'special-display-popup-frame
)
178 ;; If there is no frame with a minibuffer besides the terminal
179 ;; frame, then we need to create the opening frame. Make sure
180 ;; it has a minibuffer, but let initial-frame-alist omit the
182 (or (delq terminal-frame
(minibuffer-frame-list))
184 (setq frame-initial-frame-alist
185 (append initial-frame-alist default-frame-alist nil
))
186 (or (assq 'horizontal-scroll-bars frame-initial-frame-alist
)
187 (setq frame-initial-frame-alist
188 (cons '(horizontal-scroll-bars . t
)
189 frame-initial-frame-alist
)))
190 (setq default-minibuffer-frame
191 (setq frame-initial-frame
192 (make-frame frame-initial-frame-alist
)))
193 ;; Delete any specifications for window geometry parameters
194 ;; so that we won't reapply them in frame-notice-user-settings.
195 ;; It would be wrong to reapply them then,
196 ;; because that would override explicit user resizing.
197 (setq initial-frame-alist
198 (frame-remove-geometry-params initial-frame-alist
))))
199 ;; At this point, we know that we have a frame open, so we
200 ;; can delete the terminal frame.
201 (delete-frame terminal-frame
)
202 (setq terminal-frame nil
))
204 ;; No, we're not running a window system. Use make-terminal-frame if
205 ;; we support that feature, otherwise arrange to cause errors.
206 (or (eq window-system
'pc
)
207 (setq frame-creation-function
208 (if (fboundp 'tty-create-frame-with-faces
)
209 'tty-create-frame-with-faces
213 "Can't create multiple frames without a window system"))))))))
215 (defvar frame-notice-user-settings t
216 "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
218 ;;; startup.el calls this function after loading the user's init
219 ;;; file. Now default-frame-alist and initial-frame-alist contain
220 ;;; information to which we must react; do what needs to be done.
221 (defun frame-notice-user-settings ()
222 "Act on user's init file settings of frame parameters.
223 React to settings of `default-frame-alist', `initial-frame-alist' there."
224 ;; Make menu-bar-mode and default-frame-alist consistent.
225 (when (boundp 'menu-bar-mode
)
226 (let ((default (assq 'menu-bar-lines default-frame-alist
)))
228 (setq menu-bar-mode
(not (eq (cdr default
) 0)))
229 (setq default-frame-alist
230 (cons (cons 'menu-bar-lines
(if menu-bar-mode
1 0))
231 default-frame-alist
)))))
233 ;; Make tool-bar-mode and default-frame-alist consistent. Don't do
234 ;; it in batch mode since that would leave a tool-bar-lines
235 ;; parameter in default-frame-alist in a dumped Emacs, which is not
237 (when (and (boundp 'tool-bar-mode
)
238 (not noninteractive
))
239 (let ((default (assq 'tool-bar-lines default-frame-alist
)))
241 (setq tool-bar-mode
(not (eq (cdr default
) 0)))
242 (setq default-frame-alist
243 (cons (cons 'tool-bar-lines
(if tool-bar-mode
1 0))
244 default-frame-alist
)))))
246 ;; Creating and deleting frames may shift the selected frame around,
247 ;; and thus the current buffer. Protect against that. We don't
248 ;; want to use save-excursion here, because that may also try to set
249 ;; the buffer of the selected window, which fails when the selected
250 ;; window is the minibuffer.
251 (let ((old-buffer (current-buffer)))
253 (when (and frame-notice-user-settings
254 (null frame-initial-frame
))
255 ;; This case happens when we don't have a window system, and
256 ;; also for MS-DOS frames.
257 (let ((parms (frame-parameters frame-initial-frame
)))
258 ;; Don't change the frame names.
259 (setq parms
(delq (assq 'name parms
) parms
))
260 ;; Can't modify the minibuffer parameter, so don't try.
261 (setq parms
(delq (assq 'minibuffer parms
) parms
))
262 (modify-frame-parameters nil
263 (if (null window-system
)
264 (append initial-frame-alist
268 ;; initial-frame-alist and
269 ;; default-frame-alist were already
270 ;; applied in pc-win.el.
272 (if (null window-system
) ;; MS-DOS does this differently in pc-win.el
273 (let ((newparms (frame-parameters))
274 (frame (selected-frame)))
275 (tty-handle-reverse-video frame newparms
)
276 ;; If we changed the background color, we need to update
277 ;; the background-mode parameter, and maybe some faces,
279 (when (assq 'background-color newparms
)
280 (unless (or (assq 'background-mode initial-frame-alist
)
281 (assq 'background-mode default-frame-alist
))
282 (frame-set-background-mode frame
))
283 (face-set-after-frame-default frame
))))))
285 ;; If the initial frame is still around, apply initial-frame-alist
286 ;; and default-frame-alist to it.
287 (when (frame-live-p frame-initial-frame
)
289 ;; When tool-bar has been switched off, correct the frame size
290 ;; by the lines added in x-create-frame for the tool-bar and
291 ;; switch `tool-bar-mode' off.
292 (when (display-graphic-p)
293 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist
)
294 (assq 'tool-bar-lines default-frame-alist
))))
295 (when (and tool-bar-originally-present
296 (or (null tool-bar-lines
)
297 (null (cdr tool-bar-lines
))
298 (eq 0 (cdr tool-bar-lines
))))
299 (let* ((char-height (frame-char-height frame-initial-frame
))
300 (image-height tool-bar-images-pixel-height
)
301 (margin (cond ((and (consp tool-bar-button-margin
)
302 (integerp (cdr tool-bar-button-margin
))
303 (> tool-bar-button-margin
0))
304 (cdr tool-bar-button-margin
))
305 ((and (integerp tool-bar-button-margin
)
306 (> tool-bar-button-margin
0))
307 tool-bar-button-margin
)
309 (relief (if (and (integerp tool-bar-button-relief
)
310 (> tool-bar-button-relief
0))
311 tool-bar-button-relief
3))
312 (lines (/ (+ image-height
317 (height (frame-parameter frame-initial-frame
'height
))
318 (newparms (list (cons 'height
(- height lines
))))
319 (initial-top (cdr (assq 'top
320 frame-initial-geometry-arguments
)))
321 (top (frame-parameter frame-initial-frame
'top
)))
322 (when (and (consp initial-top
) (eq '-
(car initial-top
)))
325 `((top .
,(+ top
(* lines char-height
))))
327 (modify-frame-parameters frame-initial-frame newparms
)
328 (tool-bar-mode -
1)))))
330 ;; The initial frame we create above always has a minibuffer.
331 ;; If the user wants to remove it, or make it a minibuffer-only
332 ;; frame, then we'll have to delete the current frame and make a
333 ;; new one; you can't remove or add a root window to/from an
336 ;; NOTE: default-frame-alist was nil when we created the
337 ;; existing frame. We need to explicitly include
338 ;; default-frame-alist in the parameters of the screen we
339 ;; create here, so that its new value, gleaned from the user's
340 ;; .emacs file, will be applied to the existing screen.
341 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist
)
342 (assq 'minibuffer default-frame-alist
)
345 ;; Create the new frame.
347 ;; If the frame isn't visible yet, wait till it is.
348 ;; If the user has to position the window,
349 ;; Emacs doesn't know its real position until
350 ;; the frame is seen to be visible.
351 (while (not (cdr (assq 'visibility
352 (frame-parameters frame-initial-frame
))))
354 (setq parms
(frame-parameters frame-initial-frame
))
356 ;; Get rid of `name' unless it was specified explicitly before.
357 (or (assq 'name frame-initial-frame-alist
)
358 (setq parms
(delq (assq 'name parms
) parms
)))
360 (setq parms
(append initial-frame-alist
365 ;; Get rid of `reverse', because that was handled
366 ;; when we first made the frame.
367 (setq parms
(cons '(reverse) (delq (assq 'reverse parms
) parms
)))
369 (if (assq 'height frame-initial-geometry-arguments
)
370 (setq parms
(assq-delete-all 'height parms
)))
371 (if (assq 'width frame-initial-geometry-arguments
)
372 (setq parms
(assq-delete-all 'width parms
)))
373 (if (assq 'left frame-initial-geometry-arguments
)
374 (setq parms
(assq-delete-all 'left parms
)))
375 (if (assq 'top frame-initial-geometry-arguments
)
376 (setq parms
(assq-delete-all 'top parms
)))
379 ;; Use the geometry args that created the existing
380 ;; frame, rather than the parms we get for it.
381 (append frame-initial-geometry-arguments
382 '((user-size . t
) (user-position . t
))
384 ;; The initial frame, which we are about to delete, may be
385 ;; the only frame with a minibuffer. If it is, create a
387 (or (delq frame-initial-frame
(minibuffer-frame-list))
388 (make-initial-minibuffer-frame nil
))
390 ;; If the initial frame is serving as a surrogate
391 ;; minibuffer frame for any frames, we need to wean them
392 ;; onto a new frame. The default-minibuffer-frame
393 ;; variable must be handled similarly.
394 (let ((users-of-initial
396 (function (lambda (frame)
397 (and (not (eq frame frame-initial-frame
))
399 (minibuffer-window frame
))
400 frame-initial-frame
)))))))
401 (if (or users-of-initial
402 (eq default-minibuffer-frame frame-initial-frame
))
404 ;; Choose an appropriate frame. Prefer frames which
405 ;; are only minibuffers.
406 (let* ((new-surrogate
408 (or (filtered-frame-list
411 (eq (cdr (assq 'minibuffer
412 (frame-parameters frame
)))
414 (minibuffer-frame-list))))
415 (new-minibuffer (minibuffer-window new-surrogate
)))
417 (if (eq default-minibuffer-frame frame-initial-frame
)
418 (setq default-minibuffer-frame new-surrogate
))
420 ;; Wean the frames using frame-initial-frame as
421 ;; their minibuffer frame.
425 (modify-frame-parameters
426 frame
(list (cons 'minibuffer new-minibuffer
)))))
429 ;; Redirect events enqueued at this frame to the new frame.
430 ;; Is this a good idea?
431 (redirect-frame-focus frame-initial-frame new
)
433 ;; Finally, get rid of the old frame.
434 (delete-frame frame-initial-frame t
))
436 ;; Otherwise, we don't need all that rigamarole; just apply
437 ;; the new parameters.
438 (let (newparms allparms tail
)
439 (setq allparms
(append initial-frame-alist
440 default-frame-alist nil
))
441 (if (assq 'height frame-initial-geometry-arguments
)
442 (setq allparms
(assq-delete-all 'height allparms
)))
443 (if (assq 'width frame-initial-geometry-arguments
)
444 (setq allparms
(assq-delete-all 'width allparms
)))
445 (if (assq 'left frame-initial-geometry-arguments
)
446 (setq allparms
(assq-delete-all 'left allparms
)))
447 (if (assq 'top frame-initial-geometry-arguments
)
448 (setq allparms
(assq-delete-all 'top allparms
)))
450 ;; Find just the parms that have changed since we first
451 ;; made this frame. Those are the ones actually set by
452 ;; the init file. For those parms whose values we already knew
453 ;; (such as those spec'd by command line options)
454 ;; it is undesirable to specify the parm again
455 ;; once the user has seen the frame and been able to alter it
459 (setq oldval
(assq (car (car tail
))
460 frame-initial-frame-alist
))
461 (setq newval
(cdr (assq (car (car tail
)) allparms
)))
462 (or (and oldval
(eq (cdr oldval
) newval
))
464 (cons (cons (car (car tail
)) newval
) newparms
))))
465 (setq tail
(cdr tail
)))
466 (setq newparms
(nreverse newparms
))
467 (modify-frame-parameters frame-initial-frame
469 ;; If we changed the background color,
470 ;; we need to update the background-mode parameter
471 ;; and maybe some faces too.
472 (when (assq 'background-color newparms
)
473 (unless (assq 'background-mode newparms
)
474 (frame-set-background-mode frame-initial-frame
))
475 (face-set-after-frame-default frame-initial-frame
)))))
477 ;; Restore the original buffer.
478 (set-buffer old-buffer
)
480 ;; Make sure the initial frame can be GC'd if it is ever deleted.
481 ;; Make sure frame-notice-user-settings does nothing if called twice.
482 (setq frame-notice-user-settings nil
)
483 (setq frame-initial-frame nil
)))
485 (defun make-initial-minibuffer-frame (display)
486 (let ((parms (append minibuffer-frame-alist
'((minibuffer . only
)))))
488 (make-frame-on-display display parms
)
489 (make-frame parms
))))
491 ;;;; Creation of additional frames, and other frame miscellanea
493 (defun get-other-frame ()
494 "Return some frame other than the current frame.
495 Create one if necessary. Note that the minibuffer frame, if separate,
496 is not considered (see `next-frame')."
497 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
499 (next-frame (selected-frame)))))
502 (defun next-multiframe-window ()
503 "Select the next window, regardless of which frame it is on."
505 (select-window (next-window (selected-window)
506 (> (minibuffer-depth) 0)
509 (defun previous-multiframe-window ()
510 "Select the previous window, regardless of which frame it is on."
512 (select-window (previous-window (selected-window)
513 (> (minibuffer-depth) 0)
516 (defun make-frame-on-display (display &optional parameters
)
517 "Make a frame on display DISPLAY.
518 The optional second argument PARAMETERS specifies additional frame parameters."
519 (interactive "sMake frame on display: ")
520 (or (string-match "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display
)
521 (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
522 (make-frame (cons (cons 'display display
) parameters
)))
524 (defun make-frame-command ()
525 "Make a new frame, and select it if the terminal displays only one frame."
527 (if (and window-system
(not (eq window-system
'pc
)))
529 (select-frame (make-frame))))
531 (defvar before-make-frame-hook nil
532 "Functions to run before a frame is created.")
534 (defvar after-make-frame-functions nil
535 "Functions to run after a frame is created.
536 The functions are run with one arg, the newly created frame.")
538 (defvar after-setting-font-hook nil
539 "Functions to run after a frame's font has been changed.")
541 ;; Alias, kept temporarily.
542 (defalias 'new-frame
'make-frame
)
544 (defun make-frame (&optional parameters
)
545 "Return a newly created frame displaying the current buffer.
546 Optional argument PARAMETERS is an alist of parameters for the new frame.
547 Each element of PARAMETERS should have the form (NAME . VALUE), for example:
549 (name . STRING) The frame should be named STRING.
551 (width . NUMBER) The frame should be NUMBER characters in width.
552 (height . NUMBER) The frame should be NUMBER text lines high.
554 You cannot specify either `width' or `height', you must use neither or both.
556 (minibuffer . t) The frame should have a minibuffer.
557 (minibuffer . nil) The frame should have no minibuffer.
558 (minibuffer . only) The frame should contain only a minibuffer.
559 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
561 Before the frame is created (via `frame-creation-function'), functions on the
562 hook `before-make-frame-hook' are run. After the frame is created, functions
563 on `after-make-frame-functions' are run with one arg, the newly created frame."
565 (run-hooks 'before-make-frame-hook
)
566 (let ((frame (funcall frame-creation-function parameters
)))
567 (run-hook-with-args 'after-make-frame-functions frame
)
570 (defun filtered-frame-list (predicate)
571 "Return a list of all live frames which satisfy PREDICATE."
572 (let* ((frames (frame-list))
574 (while (consp frames
)
575 (unless (funcall predicate
(car frames
))
577 (setq frames
(cdr frames
)))
580 (defun minibuffer-frame-list ()
581 "Return a list of all frames with their own minibuffers."
583 (function (lambda (frame)
584 (eq frame
(window-frame (minibuffer-window frame
)))))))
586 (defun frames-on-display-list (&optional display
)
587 "Return a list of all frames on DISPLAY.
588 DISPLAY is a name of a display, a string of the form HOST:SERVER.SCREEN.
589 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
590 (let* ((display (or display
(frame-parameter nil
'display
)))
591 (func #'(lambda (frame)
592 (eq (frame-parameter frame
'display
) display
))))
593 (filtered-frame-list func
)))
595 (defun framep-on-display (&optional display
)
596 "Return the type of frames on DISPLAY.
597 DISPLAY may be a display name or a frame. If it is a frame, its type is
599 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
600 All frames on a given display are of the same type."
602 (framep (car (frames-on-display-list display
)))))
604 (defun frame-remove-geometry-params (param-list)
605 "Return the parameter list PARAM-LIST, but with geometry specs removed.
606 This deletes all bindings in PARAM-LIST for `top', `left', `width',
607 `height', `user-size' and `user-position' parameters.
608 Emacs uses this to avoid overriding explicit moves and resizings from
609 the user during startup."
610 (setq param-list
(cons nil param-list
))
611 (let ((tail param-list
))
612 (while (consp (cdr tail
))
613 (if (and (consp (car (cdr tail
)))
614 (memq (car (car (cdr tail
)))
615 '(height width top left user-position user-size
)))
617 (setq frame-initial-geometry-arguments
618 (cons (car (cdr tail
)) frame-initial-geometry-arguments
))
619 (setcdr tail
(cdr (cdr tail
))))
620 (setq tail
(cdr tail
)))))
621 (setq frame-initial-geometry-arguments
622 (nreverse frame-initial-geometry-arguments
))
626 (defcustom focus-follows-mouse t
627 "*Non-nil if window system changes focus when you move the mouse."
632 (defun other-frame (arg)
633 "Select the ARG'th different visible frame, and raise it.
634 All frames are arranged in a cyclic order.
635 This command selects the frame ARG steps away in that order.
636 A negative ARG moves in the opposite order."
638 (let ((frame (selected-frame)))
640 (setq frame
(next-frame frame
))
641 (while (not (eq (frame-visible-p frame
) t
))
642 (setq frame
(next-frame frame
)))
645 (setq frame
(previous-frame frame
))
646 (while (not (eq (frame-visible-p frame
) t
))
647 (setq frame
(previous-frame frame
)))
651 ;; Ensure, if possible, that frame gets input focus.
652 (when (eq window-system
'w32
)
653 (w32-focus-frame frame
))
654 (cond (focus-follows-mouse
655 (unless (eq window-system
'w32
)
656 (set-mouse-position (selected-frame) (1- (frame-width)) 0)))
658 (when (eq window-system
'x
)
659 (x-focus-frame frame
))))))
661 (defun make-frame-names-alist ()
662 (let* ((current-frame (selected-frame))
665 (cons (frame-parameter current-frame
'name
) current-frame
) nil
))
666 (frame (next-frame nil t
)))
667 (while (not (eq frame current-frame
))
669 (setq falist
(cons (cons (frame-parameter frame
'name
) frame
) falist
))
670 (setq frame
(next-frame frame t
))))
673 (defvar frame-name-history nil
)
674 (defun select-frame-by-name (name)
675 "Select the frame whose name is NAME and raise it.
676 If there is no frame by that name, signal an error."
678 (let* ((frame-names-alist (make-frame-names-alist))
679 (default (car (car frame-names-alist
)))
680 (input (completing-read
681 (format "Select Frame (default %s): " default
)
682 frame-names-alist nil t nil
'frame-name-history
)))
683 (if (= (length input
) 0)
686 (let* ((frame-names-alist (make-frame-names-alist))
687 (frame (cdr (assoc name frame-names-alist
))))
689 (error "There is no frame named `%s'" name
))
690 (make-frame-visible frame
)
693 ;; Ensure, if possible, that frame gets input focus.
694 (if (eq window-system
'w32
)
695 (w32-focus-frame frame
)
696 (when focus-follows-mouse
697 (set-mouse-position (selected-frame) (1- (frame-width)) 0)))))
699 ;;;; Frame configurations
701 (defun current-frame-configuration ()
702 "Return a list describing the positions and states of all frames.
703 Its car is `frame-configuration'.
704 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
706 FRAME is a frame object,
707 ALIST is an association list specifying some of FRAME's parameters, and
708 WINDOW-CONFIG is a window configuration object for FRAME."
709 (cons 'frame-configuration
713 (frame-parameters frame
)
714 (current-window-configuration frame
))))
717 (defun set-frame-configuration (configuration &optional nodelete
)
718 "Restore the frames to the state described by CONFIGURATION.
719 Each frame listed in CONFIGURATION has its position, size, window
720 configuration, and other parameters set as specified in CONFIGURATION.
721 Ordinarily, this function deletes all existing frames not
722 listed in CONFIGURATION. But if optional second argument NODELETE
723 is given and non-nil, the unwanted frames are iconified instead."
724 (or (frame-configuration-p configuration
)
725 (signal 'wrong-type-argument
726 (list 'frame-configuration-p configuration
)))
727 (let ((config-alist (cdr configuration
))
731 (let ((parameters (assq frame config-alist
)))
734 (modify-frame-parameters
736 ;; Since we can't set a frame's minibuffer status,
737 ;; we might as well omit the parameter altogether.
738 (let* ((parms (nth 1 parameters
))
739 (mini (assq 'minibuffer parms
)))
740 (if mini
(setq parms
(delq mini parms
)))
742 (set-window-configuration (nth 2 parameters
)))
743 (setq frames-to-delete
(cons frame frames-to-delete
))))))
746 ;; Note: making frames invisible here was tried
747 ;; but led to some strange behavior--each time the frame
748 ;; was made visible again, the window manager asked afresh
749 ;; for where to put it.
750 (mapcar 'iconify-frame frames-to-delete
)
751 (mapcar 'delete-frame frames-to-delete
))))
753 ;;;; Convenience functions for accessing and interactively changing
754 ;;;; frame parameters.
756 (defun frame-height (&optional frame
)
757 "Return number of lines available for display on FRAME.
758 If FRAME is omitted, describe the currently selected frame."
759 (cdr (assq 'height
(frame-parameters frame
))))
761 (defun frame-width (&optional frame
)
762 "Return number of columns available for display on FRAME.
763 If FRAME is omitted, describe the currently selected frame."
764 (cdr (assq 'width
(frame-parameters frame
))))
766 (defalias 'set-default-font
'set-frame-font
)
767 (defun set-frame-font (font-name)
768 "Set the font of the selected frame to FONT-NAME.
769 When called interactively, prompt for the name of the font to use.
770 To get the frame's current default font, use `frame-parameters'."
773 (let ((completion-ignore-case t
))
774 (completing-read "Font name: "
776 ;; x-list-fonts will fail with an error
777 ;; if this frame doesn't support fonts.
778 (x-list-fonts "*" nil
(selected-frame)))))))
779 (modify-frame-parameters (selected-frame)
780 (list (cons 'font font-name
)))
781 (run-hooks 'after-setting-font-hook
'after-setting-font-hooks
))
783 (defun set-background-color (color-name)
784 "Set the background color of the selected frame to COLOR-NAME.
785 When called interactively, prompt for the name of the color to use.
786 To get the frame's current background color, use `frame-parameters'."
787 (interactive (list (facemenu-read-color)))
788 (modify-frame-parameters (selected-frame)
789 (list (cons 'background-color color-name
))))
791 (defun set-foreground-color (color-name)
792 "Set the foreground color of the selected frame to COLOR-NAME.
793 When called interactively, prompt for the name of the color to use.
794 To get the frame's current foreground color, use `frame-parameters'."
795 (interactive (list (facemenu-read-color)))
796 (modify-frame-parameters (selected-frame)
797 (list (cons 'foreground-color color-name
))))
799 (defun set-cursor-color (color-name)
800 "Set the text cursor color of the selected frame to COLOR-NAME.
801 When called interactively, prompt for the name of the color to use.
802 To get the frame's current cursor color, use `frame-parameters'."
803 (interactive (list (facemenu-read-color)))
804 (modify-frame-parameters (selected-frame)
805 (list (cons 'cursor-color color-name
))))
807 (defun set-mouse-color (color-name)
808 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
809 When called interactively, prompt for the name of the color to use.
810 To get the frame's current mouse color, use `frame-parameters'."
811 (interactive (list (facemenu-read-color)))
812 (modify-frame-parameters (selected-frame)
813 (list (cons 'mouse-color
815 (cdr (assq 'mouse-color
816 (frame-parameters))))))))
818 (defun set-border-color (color-name)
819 "Set the color of the border of the selected frame to COLOR-NAME.
820 When called interactively, prompt for the name of the color to use.
821 To get the frame's current border color, use `frame-parameters'."
822 (interactive (list (facemenu-read-color)))
823 (modify-frame-parameters (selected-frame)
824 (list (cons 'border-color color-name
))))
826 (defun auto-raise-mode (arg)
827 "Toggle whether or not the selected frame should auto-raise.
828 With arg, turn auto-raise mode on if and only if arg is positive.
829 Note that this controls Emacs's own auto-raise feature.
830 Some window managers allow you to enable auto-raise for certain windows.
831 You can use that for Emacs windows if you wish, but if you do,
832 that is beyond the control of Emacs and this command has no effect on it."
836 (if (cdr (assq 'auto-raise
(frame-parameters (selected-frame))))
839 (raise-frame (selected-frame)))
840 (modify-frame-parameters (selected-frame)
841 (list (cons 'auto-raise
(> arg
0)))))
843 (defun auto-lower-mode (arg)
844 "Toggle whether or not the selected frame should auto-lower.
845 With arg, turn auto-lower mode on if and only if arg is positive.
846 Note that this controls Emacs's own auto-lower feature.
847 Some window managers allow you to enable auto-lower for certain windows.
848 You can use that for Emacs windows if you wish, but if you do,
849 that is beyond the control of Emacs and this command has no effect on it."
853 (if (cdr (assq 'auto-lower
(frame-parameters (selected-frame))))
855 (modify-frame-parameters (selected-frame)
856 (list (cons 'auto-lower
(> arg
0)))))
857 (defun set-frame-name (name)
858 "Set the name of the selected frame to NAME.
859 When called interactively, prompt for the name of the frame.
860 The frame name is displayed on the modeline if the terminal displays only
861 one frame, otherwise the name is displayed on the frame's caption bar."
862 (interactive "sFrame name: ")
863 (modify-frame-parameters (selected-frame)
864 (list (cons 'name name
))))
866 ;;;; Frame/display capabilities.
867 (defun display-mouse-p (&optional display
)
868 "Return non-nil if DISPLAY has a mouse available.
869 DISPLAY can be a display name, a frame, or nil (meaning the selected
871 (let ((frame-type (framep-on-display display
)))
875 ((eq system-type
'windows-nt
)
876 (> w32-num-mouse-buttons
0))
877 ((memq frame-type
'(x mac
))
878 t
) ;; We assume X and Mac *always* have a pointing device
880 (or (and (featurep 'xt-mouse
)
882 ;; t-mouse is distributed with the GPM package. It doesn't have
884 (featurep 't-mouse
))))))
886 (defun display-popup-menus-p (&optional display
)
887 "Return non-nil if popup menus are supported on DISPLAY.
888 DISPLAY can be a display name, a frame, or nil (meaning the selected
890 Support for popup menus requires that the mouse be available."
892 (let ((frame-type (framep-on-display display
)))
893 (memq frame-type
'(x w32 pc mac
)))
894 (display-mouse-p display
)))
896 (defun display-graphic-p (&optional display
)
897 "Return non-nil if DISPLAY is a graphic display.
898 Graphical displays are those which are capable of displaying several
899 frames and several different fonts at once. This is true for displays
900 that use a window system such as X, and false for text-only terminals.
901 DISPLAY can be a display name, a frame, or nil (meaning the selected
903 (not (null (memq (framep-on-display display
) '(x w32 mac
)))))
905 (defalias 'display-multi-frame-p
'display-graphic-p
)
906 (defalias 'display-multi-font-p
'display-graphic-p
)
908 (defun display-selections-p (&optional display
)
909 "Return non-nil if DISPLAY supports selections.
910 A selection is a way to transfer text or other data between programs
911 via special system buffers called `selection' or `cut buffer' or
913 DISPLAY can be a display name, a frame, or nil (meaning the selected
915 (let ((frame-type (framep-on-display display
)))
918 ;; MS-DOG frames support selections when Emacs runs inside
919 ;; the Windows' DOS Box.
920 (not (null dos-windows-version
)))
921 ((memq frame-type
'(x w32 mac
))
926 (defun display-screens (&optional display
)
927 "Return the number of screens associated with DISPLAY."
928 (let ((frame-type (framep-on-display display
)))
930 ((memq frame-type
'(x w32
))
931 (x-display-screens display
))
932 (t ;; FIXME: is this correct for the Mac?
935 (defun display-pixel-height (&optional display
)
936 "Return the height of DISPLAY's screen in pixels.
937 For character terminals, each character counts as a single pixel."
938 (let ((frame-type (framep-on-display display
)))
940 ((memq frame-type
'(x w32 mac
))
941 (x-display-pixel-height display
))
943 (frame-height (if (framep display
) display
(selected-frame)))))))
945 (defun display-pixel-width (&optional display
)
946 "Return the width of DISPLAY's screen in pixels.
947 For character terminals, each character counts as a single pixel."
948 (let ((frame-type (framep-on-display display
)))
950 ((memq frame-type
'(x w32 mac
))
951 (x-display-pixel-width display
))
953 (frame-width (if (framep display
) display
(selected-frame)))))))
955 (defun display-mm-height (&optional display
)
956 "Return the height of DISPLAY's screen in millimeters.
957 If the information is unavailable, value is nil."
958 (and (memq (framep-on-display display
) '(x w32 mac
))
959 (x-display-mm-height display
)))
961 (defun display-mm-width (&optional display
)
962 "Return the width of DISPLAY's screen in millimeters.
963 If the information is unavailable, value is nil."
964 (and (memq (framep-on-display display
) '(x w32 mac
))
965 (x-display-mm-width display
)))
967 (defun display-backing-store (&optional display
)
968 "Return the backing store capability of DISPLAY's screen.
969 The value may be `always', `when-mapped', `not-useful', or nil if
970 the question is inapplicable to a certain kind of display."
971 (let ((frame-type (framep-on-display display
)))
973 ((memq frame-type
'(x w32 mac
))
974 (x-display-backing-store display
))
978 (defun display-save-under (&optional display
)
979 "Return non-nil if DISPLAY's screen supports the SaveUnder feature."
980 (let ((frame-type (framep-on-display display
)))
982 ((memq frame-type
'(x w32 mac
))
983 (x-display-save-under display
))
987 (defun display-planes (&optional display
)
988 "Return the number of planes supported by DISPLAY."
989 (let ((frame-type (framep-on-display display
)))
991 ((memq frame-type
'(x w32 mac
))
992 (x-display-planes display
))
996 (truncate (log (length (tty-color-alist)) 2))))))
998 (defun display-color-cells (&optional display
)
999 "Return the number of color cells supported by DISPLAY."
1000 (let ((frame-type (framep-on-display display
)))
1002 ((memq frame-type
'(x w32 mac
))
1003 (x-display-color-cells display
))
1004 ((eq frame-type
'pc
)
1007 (length (tty-color-alist))))))
1009 (defun display-visual-class (&optional display
)
1010 "Returns the visual class of DISPLAY.
1011 The value is one of the symbols `static-gray', `gray-scale',
1012 `static-color', `pseudo-color', `true-color', or `direct-color'."
1013 (let ((frame-type (framep-on-display display
)))
1015 ((memq frame-type
'(x w32 mac
))
1016 (x-display-visual-class display
))
1017 ((and (memq frame-type
'(pc t
))
1018 (tty-display-color-p display
))
1024 ;;;; Aliases for backward compatibility with Emacs 18.
1025 (defalias 'screen-height
'frame-height
)
1026 (defalias 'screen-width
'frame-width
)
1028 (defun set-screen-width (cols &optional pretend
)
1029 "Obsolete function to change the size of the screen to COLS columns.
1030 Optional second arg non-nil means that redisplay should use COLS columns
1031 but that the idea of the actual width of the frame should not be changed.
1032 This function is provided only for compatibility with Emacs 18; new code
1033 should use `set-frame-width instead'."
1034 (set-frame-width (selected-frame) cols pretend
))
1036 (defun set-screen-height (lines &optional pretend
)
1037 "Obsolete function to change the height of the screen to LINES lines.
1038 Optional second arg non-nil means that redisplay should use LINES lines
1039 but that the idea of the actual height of the screen should not be changed.
1040 This function is provided only for compatibility with Emacs 18; new code
1041 should use `set-frame-height' instead."
1042 (set-frame-height (selected-frame) lines pretend
))
1044 (defun delete-other-frames (&optional frame
)
1045 "Delete all frames except FRAME.
1046 FRAME nil or omitted means delete all frames except the selected frame."
1049 (setq frame
(selected-frame)))
1050 (mapcar 'delete-frame
(delq frame
(frame-list))))
1053 (make-obsolete 'screen-height
'frame-height
) ;before 19.15
1054 (make-obsolete 'screen-width
'frame-width
) ;before 19.15
1055 (make-obsolete 'set-screen-width
'set-frame-width
) ;before 19.15
1056 (make-obsolete 'set-screen-height
'set-frame-height
) ;before 19.15
1059 ;;; Highlighting trailing whitespace.
1061 (make-variable-buffer-local 'show-trailing-whitespace
)
1063 (defcustom show-trailing-whitespace nil
1064 "*Non-nil means highlight trailing whitespace in face `trailing-whitespace'."
1065 :tag
"Highlight trailing whitespace."
1066 :set
#'(lambda (symbol value
) (set-default symbol value
))
1074 (defgroup scrolling nil
1075 "Scrolling windows."
1079 (defcustom automatic-hscrolling t
1080 "*Allow or disallow autmatic scrolling windows horizontally.
1081 If non-nil, windows are automatically scrolled horizontally to make
1090 (defgroup cursor nil
1091 "Displaying text cursors."
1095 (defcustom blink-cursor-delay
0.5
1096 "*Seconds of idle time after which cursor starts to blink."
1097 :tag
"Delay in seconds."
1101 (defcustom blink-cursor-interval
0.5
1102 "*Length of cursor blink interval in seconds."
1103 :tag
"Blink interval in seconds."
1107 (defvar blink-cursor-idle-timer nil
1108 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
1109 The function `blink-cursor-start' is called when the timer fires.")
1111 (defvar blink-cursor-timer nil
1112 "Timer started from `blink-cursor-start'.
1113 This timer calls `blink-cursor' every `blink-cursor-interval' seconds.")
1115 (defvar blink-cursor-mode nil
1116 "Non-nil means blinking cursor is active.")
1118 (defun blink-cursor-mode (arg)
1119 "Toggle blinking cursor mode.
1120 With a numeric argument, turn blinking cursor mode on iff ARG is positive.
1121 When blinking cursor mode is enabled, the cursor of the selected
1124 (let ((on-p (if (null arg
)
1125 (not blink-cursor-mode
)
1126 (> (prefix-numeric-value arg
) 0))))
1127 (if blink-cursor-idle-timer
1128 (cancel-timer blink-cursor-idle-timer
))
1129 (if blink-cursor-timer
1130 (cancel-timer blink-cursor-timer
))
1131 (setq blink-cursor-idle-timer nil
1132 blink-cursor-timer nil
1133 blink-cursor-mode nil
)
1137 ;(internal-show-cursor nil nil)
1138 (setq blink-cursor-idle-timer
1139 (run-with-idle-timer blink-cursor-delay
1141 'blink-cursor-start
))
1142 (setq blink-cursor-mode t
))
1143 (internal-show-cursor nil t
))))
1145 ;; Note that this is really initialized from startup.el before
1146 ;; the init-file is read.
1148 (defcustom blink-cursor nil
1149 "*Non-nil means blinking cursor mode is active."
1151 :tag
"Blinking cursor"
1153 :set
#'(lambda (symbol value
)
1154 (set-default symbol value
)
1155 (blink-cursor-mode (or value
0))))
1157 (defun blink-cursor-start ()
1158 "Timer function called from the timer `blink-cursor-idle-timer'.
1159 This starts the timer `blink-cursor-timer', which makes the cursor blink
1160 if appropriate. It also arranges to cancel that timer when the next
1161 command starts, by installing a pre-command hook."
1162 (when (null blink-cursor-timer
)
1163 (add-hook 'pre-command-hook
'blink-cursor-end
)
1164 (setq blink-cursor-timer
1165 (run-with-timer blink-cursor-interval blink-cursor-interval
1166 'blink-cursor-timer-function
))))
1168 (defun blink-cursor-timer-function ()
1169 "Timer function of timer `blink-cursor-timer'."
1170 (internal-show-cursor nil
(not (internal-show-cursor-p))))
1172 (defun blink-cursor-end ()
1173 "Stop cursor blinking.
1174 This is installed as a pre-command hook by `blink-cursor-start'.
1175 When run, it cancels the timer `blink-cursor-timer' and removes
1176 itself as a pre-command hook."
1177 (remove-hook 'pre-command-hook
'blink-cursor-end
)
1178 (internal-show-cursor nil t
)
1179 (cancel-timer blink-cursor-timer
)
1180 (setq blink-cursor-timer nil
))
1184 ;;; Hourglass pointer
1186 (defcustom display-hourglass t
1187 "*Non-nil means show an hourglass pointer when running under a window system."
1188 :tag
"Hourglass pointer"
1192 (defcustom hourglass-delay
1
1193 "*Seconds to wait before displaying an hourglass pointer."
1194 :tag
"Hourglass delay"
1199 (defcustom cursor-in-non-selected-windows t
1200 "*Non-nil means show a hollow box cursor in non-selected-windows.
1201 If nil, don't show a cursor except in the selected window.
1202 Use Custom to set this variable to get the display updated."
1203 :tag
"Cursor in non-selected windows"
1206 :set
#'(lambda (symbol value
)
1207 (set-default symbol value
)
1208 (force-mode-line-update t
)))
1213 (define-key ctl-x-5-map
"2" 'make-frame-command
)
1214 (define-key ctl-x-5-map
"1" 'delete-other-frames
)
1215 (define-key ctl-x-5-map
"0" 'delete-frame
)
1216 (define-key ctl-x-5-map
"o" 'other-frame
)
1220 ;;; frame.el ends here