1 ;;; frame.el --- multi-frame management independent of window systems.
3 ;; Copyright (C) 1993, 1994, 1996, 1997 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 (defvar frame-creation-function nil
28 "Window-system dependent function to call to create a new frame.
29 The window system startup file should set this to its frame creation
30 function, which should take an alist of parameters as its argument.")
32 ;;; The initial value given here for used to ask for a minibuffer.
33 ;;; But that's not necessary, because the default is to have one.
34 ;;; By not specifying it here, we let an X resource specify it.
35 (defcustom initial-frame-alist nil
36 "*Alist of frame parameters for creating the initial X window frame.
37 You can set this in your `.emacs' file; for example,
38 (setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55)))
39 Parameters specified here supersede the values given in `default-frame-alist'.
41 If the value calls for a frame without a minibuffer, and you have not created
42 a minibuffer frame on your own, one is created according to
43 `minibuffer-frame-alist'.
45 You can specify geometry-related options for just the initial frame
46 by setting this variable in your `.emacs' file; however, they won't
47 take effect until Emacs reads `.emacs', which happens after first creating
48 the frame. If you want the frame to have the proper geometry as soon
49 as it appears, you need to use this three-step process:
50 * Specify X resources to give the geometry you want.
51 * Set `default-frame-alist' to override these options so that they
52 don't affect subsequent frames.
53 * Set `initial-frame-alist' in a way that matches the X resources,
54 to override what you put in `default-frame-alist'."
55 :type
'(repeat (cons :format
"%v"
56 (symbol :tag
"Parameter")
60 (defcustom minibuffer-frame-alist
'((width .
80) (height .
2))
61 "*Alist of frame parameters for initially creating a minibuffer frame.
62 You can set this in your `.emacs' file; for example,
63 (setq minibuffer-frame-alist
64 '((top . 1) (left . 1) (width . 80) (height . 2)))
65 Parameters specified here supersede the values given in
66 `default-frame-alist', for a minibuffer frame."
67 :type
'(repeat (cons :format
"%v"
68 (symbol :tag
"Parameter")
72 (defcustom pop-up-frame-alist nil
73 "*Alist of frame parameters used when creating pop-up frames.
74 Pop-up frames are used for completions, help, and the like.
75 This variable can be set in your init file, like this:
76 (setq pop-up-frame-alist '((width . 80) (height . 20)))
77 These supersede the values given in `default-frame-alist',
79 :type
'(repeat (cons :format
"%v"
80 (symbol :tag
"Parameter")
84 (setq pop-up-frame-function
86 (make-frame pop-up-frame-alist
))))
88 (defcustom special-display-frame-alist
89 '((height .
14) (width .
80) (unsplittable . t
))
90 "*Alist of frame parameters used when creating special frames.
91 Special frames are used for buffers whose names are in
92 `special-display-buffer-names' and for buffers whose names match
93 one of the regular expressions in `special-display-regexps'.
94 This variable can be set in your init file, like this:
95 (setq special-display-frame-alist '((width . 80) (height . 20)))
96 These supersede the values given in `default-frame-alist'."
97 :type
'(repeat (cons :format
"%v"
98 (symbol :tag
"Parameter")
102 (defun special-display-popup-frame (buffer &optional args
)
103 "Display BUFFER in its own frame, reusing an existing window if any.
104 Return the window chosen.
105 Currently we do not insist on selecting the window within its frame.
106 If ARGS is an alist, use it as a list of frame parameter specs.
107 If ARGS is a list whose car is a symbol,
108 use (car ARGS) as a function to do the work.
109 Pass it BUFFER as first arg, and (cdr ARGS) gives the rest of the args."
110 (if (and args
(symbolp (car args
)))
111 (apply (car args
) buffer
(cdr args
))
112 (let ((window (get-buffer-window buffer t
)))
114 ;; If we have a window already, make it visible.
115 (let ((frame (window-frame window
)))
116 (make-frame-visible frame
)
119 ;; If no window yet, make one in a new frame.
120 (let ((frame (make-frame (append args special-display-frame-alist
))))
121 (set-window-buffer (frame-selected-window frame
) buffer
)
122 (set-window-dedicated-p (frame-selected-window frame
) t
)
123 (frame-selected-window frame
))))))
125 (defun handle-delete-frame (event)
126 "Handle delete-frame events from the X server."
128 (let ((frame (posn-window (event-start event
)))
132 (and (frame-visible-p (car tail
))
133 (not (eq (car tail
) frame
))
135 (setq tail
(cdr tail
)))
137 (delete-frame frame t
)
138 ;; Gildea@x.org says it is ok to ask questions before terminating.
139 (save-buffers-kill-emacs))))
141 ;;;; Arrangement of frames at startup
143 ;;; 1) Load the window system startup file from the lisp library and read the
144 ;;; high-priority arguments (-q and the like). The window system startup
145 ;;; file should create any frames specified in the window system defaults.
147 ;;; 2) If no frames have been opened, we open an initial text frame.
149 ;;; 3) Once the init file is done, we apply any newly set parameters
150 ;;; in initial-frame-alist to the frame.
152 ;; These are now called explicitly at the proper times,
153 ;; since that is easier to understand.
154 ;; Actually using hooks within Emacs is bad for future maintenance. --rms.
155 ;; (add-hook 'before-init-hook 'frame-initialize)
156 ;; (add-hook 'window-setup-hook 'frame-notice-user-settings)
158 ;;; If we create the initial frame, this is it.
159 (defvar frame-initial-frame nil
)
161 ;; Record the parameters used in frame-initialize to make the initial frame.
162 (defvar frame-initial-frame-alist
)
164 (defvar frame-initial-geometry-arguments nil
)
166 ;;; startup.el calls this function before loading the user's init
167 ;;; file - if there is no frame with a minibuffer open now, create
168 ;;; one to display messages while loading the init file.
169 (defun frame-initialize ()
170 "Create an in initial frame if necessary."
171 ;; Are we actually running under a window system at all?
172 (if (and window-system
(not noninteractive
) (not (eq window-system
'pc
)))
174 ;; Turn on special-display processing only if there's a window system.
175 (setq special-display-function
'special-display-popup-frame
)
177 ;; If there is no frame with a minibuffer besides the terminal
178 ;; frame, then we need to create the opening frame. Make sure
179 ;; it has a minibuffer, but let initial-frame-alist omit the
181 (or (delq terminal-frame
(minibuffer-frame-list))
183 (setq frame-initial-frame-alist
184 (append initial-frame-alist default-frame-alist nil
))
185 (or (assq 'horizontal-scroll-bars frame-initial-frame-alist
)
186 (setq frame-initial-frame-alist
187 (cons '(horizontal-scroll-bars . t
)
188 frame-initial-frame-alist
)))
189 (setq default-minibuffer-frame
190 (setq frame-initial-frame
191 (make-frame frame-initial-frame-alist
)))
192 ;; Delete any specifications for window geometry parameters
193 ;; so that we won't reapply them in frame-notice-user-settings.
194 ;; It would be wrong to reapply them then,
195 ;; because that would override explicit user resizing.
196 (setq initial-frame-alist
197 (frame-remove-geometry-params initial-frame-alist
))))
198 ;; At this point, we know that we have a frame open, so we
199 ;; can delete the terminal frame.
200 (delete-frame terminal-frame
)
201 (setq terminal-frame nil
))
203 ;; No, we're not running a window system. Use make-terminal-frame if
204 ;; we support that feature, otherwise arrange to cause errors.
205 (or (eq window-system
'pc
)
206 (setq frame-creation-function
207 (if (fboundp 'tty-create-frame-with-faces
)
208 'tty-create-frame-with-faces
212 "Can't create multiple frames without a window system"))))))))
214 ;;; startup.el calls this function after loading the user's init
215 ;;; file. Now default-frame-alist and initial-frame-alist contain
216 ;;; information to which we must react; do what needs to be done.
217 (defun frame-notice-user-settings ()
218 "Act on user's init file settings of frame parameters.
219 React to settings of `default-frame-alist', `initial-frame-alist' there."
220 ;; Make menu-bar-mode and default-frame-alist consistent.
221 (if (boundp 'menu-bar-mode
)
222 (let ((default (assq 'menu-bar-lines default-frame-alist
)))
224 (setq menu-bar-mode
(not (eq (cdr default
) 0)))
225 (setq default-frame-alist
226 (cons (cons 'menu-bar-lines
(if menu-bar-mode
1 0))
227 default-frame-alist
)))))
229 ;; Creating and deleting frames may shift the selected frame around,
230 ;; and thus the current buffer. Protect against that. We don't
231 ;; want to use save-excursion here, because that may also try to set
232 ;; the buffer of the selected window, which fails when the selected
233 ;; window is the minibuffer.
234 (let ((old-buffer (current-buffer)))
236 ;; If the initial frame is still around, apply initial-frame-alist
237 ;; and default-frame-alist to it.
238 (if (frame-live-p frame-initial-frame
)
240 ;; The initial frame we create above always has a minibuffer.
241 ;; If the user wants to remove it, or make it a minibuffer-only
242 ;; frame, then we'll have to delete the current frame and make a
243 ;; new one; you can't remove or add a root window to/from an
246 ;; NOTE: default-frame-alist was nil when we created the
247 ;; existing frame. We need to explicitly include
248 ;; default-frame-alist in the parameters of the screen we
249 ;; create here, so that its new value, gleaned from the user's
250 ;; .emacs file, will be applied to the existing screen.
251 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist
)
252 (assq 'minibuffer default-frame-alist
)
255 ;; Create the new frame.
257 ;; If the frame isn't visible yet, wait till it is.
258 ;; If the user has to position the window,
259 ;; Emacs doesn't know its real position until
260 ;; the frame is seen to be visible.
261 (while (not (cdr (assq 'visibility
262 (frame-parameters frame-initial-frame
))))
264 (setq parms
(frame-parameters frame-initial-frame
))
265 ;; Get rid of `name' unless it was specified explicitly before.
266 (or (assq 'name frame-initial-frame-alist
)
267 (setq parms
(delq (assq 'name parms
) parms
)))
268 (setq parms
(append initial-frame-alist
272 ;; Get rid of `reverse', because that was handled
273 ;; when we first made the frame.
274 (setq parms
(cons '(reverse) (delq (assq 'reverse parms
) parms
)))
275 (if (assq 'height frame-initial-geometry-arguments
)
276 (setq parms
(assoc-delete-all 'height parms
)))
277 (if (assq 'width frame-initial-geometry-arguments
)
278 (setq parms
(assoc-delete-all 'width parms
)))
279 (if (assq 'left frame-initial-geometry-arguments
)
280 (setq parms
(assoc-delete-all 'left parms
)))
281 (if (assq 'top frame-initial-geometry-arguments
)
282 (setq parms
(assoc-delete-all 'top parms
)))
285 ;; Use the geometry args that created the existing
286 ;; frame, rather than the parms we get for it.
287 (append frame-initial-geometry-arguments
288 '((user-size . t
) (user-position . t
))
290 ;; The initial frame, which we are about to delete, may be
291 ;; the only frame with a minibuffer. If it is, create a
293 (or (delq frame-initial-frame
(minibuffer-frame-list))
294 (make-initial-minibuffer-frame nil
))
296 ;; If the initial frame is serving as a surrogate
297 ;; minibuffer frame for any frames, we need to wean them
298 ;; onto a new frame. The default-minibuffer-frame
299 ;; variable must be handled similarly.
300 (let ((users-of-initial
302 (function (lambda (frame)
303 (and (not (eq frame frame-initial-frame
))
305 (minibuffer-window frame
))
306 frame-initial-frame
)))))))
307 (if (or users-of-initial
308 (eq default-minibuffer-frame frame-initial-frame
))
310 ;; Choose an appropriate frame. Prefer frames which
311 ;; are only minibuffers.
312 (let* ((new-surrogate
314 (or (filtered-frame-list
317 (eq (cdr (assq 'minibuffer
318 (frame-parameters frame
)))
320 (minibuffer-frame-list))))
321 (new-minibuffer (minibuffer-window new-surrogate
)))
323 (if (eq default-minibuffer-frame frame-initial-frame
)
324 (setq default-minibuffer-frame new-surrogate
))
326 ;; Wean the frames using frame-initial-frame as
327 ;; their minibuffer frame.
331 (modify-frame-parameters
332 frame
(list (cons 'minibuffer new-minibuffer
)))))
335 ;; Redirect events enqueued at this frame to the new frame.
336 ;; Is this a good idea?
337 (redirect-frame-focus frame-initial-frame new
)
339 ;; Finally, get rid of the old frame.
340 (delete-frame frame-initial-frame t
))
342 ;; Otherwise, we don't need all that rigamarole; just apply
343 ;; the new parameters.
344 (let (newparms allparms tail
)
345 (setq allparms
(append initial-frame-alist
346 default-frame-alist
))
347 (if (assq 'height frame-initial-geometry-arguments
)
348 (setq allparms
(assoc-delete-all 'height allparms
)))
349 (if (assq 'width frame-initial-geometry-arguments
)
350 (setq allparms
(assoc-delete-all 'width allparms
)))
351 (if (assq 'left frame-initial-geometry-arguments
)
352 (setq allparms
(assoc-delete-all 'left allparms
)))
353 (if (assq 'top frame-initial-geometry-arguments
)
354 (setq allparms
(assoc-delete-all 'top allparms
)))
356 ;; Find just the parms that have changed since we first
357 ;; made this frame. Those are the ones actually set by
358 ;; the init file. For those parms whose values we already knew
359 ;; (such as those spec'd by command line options)
360 ;; it is undesirable to specify the parm again
361 ;; once the user has seen the frame and been able to alter it
365 (setq oldval
(assq (car (car tail
))
366 frame-initial-frame-alist
))
367 (setq newval
(cdr (assq (car (car tail
)) allparms
)))
368 (or (and oldval
(eq (cdr oldval
) newval
))
370 (cons (cons (car (car tail
)) newval
) newparms
))))
371 (setq tail
(cdr tail
)))
372 (setq newparms
(nreverse newparms
))
373 (modify-frame-parameters frame-initial-frame
375 ;; If we changed the background color,
376 ;; we need to update the background-mode parameter
377 ;; and maybe some faces too.
378 (when (assq 'background-color newparms
)
379 (unless (assq 'background-mode newparms
)
380 (frame-set-background-mode frame-initial-frame
))
381 (face-set-after-frame-default frame-initial-frame
))
382 (if (assq 'font newparms
)
383 (frame-update-faces frame-initial-frame
)))))
385 ;; Restore the original buffer.
386 (set-buffer old-buffer
)
388 ;; Make sure the initial frame can be GC'd if it is ever deleted.
389 ;; Make sure frame-notice-user-settings does nothing if called twice.
390 (setq frame-initial-frame nil
)))
392 (defun make-initial-minibuffer-frame (display)
393 (let ((parms (append minibuffer-frame-alist
'((minibuffer . only
)))))
395 (make-frame-on-display display parms
)
396 (make-frame parms
))))
398 ;;;; Creation of additional frames, and other frame miscellanea
400 (defun get-other-frame ()
401 "Return some frame other than the current frame.
402 Create one if necessary. Note that the minibuffer frame, if separate,
403 is not considered (see `next-frame')."
404 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
406 (next-frame (selected-frame)))))
409 (defun next-multiframe-window ()
410 "Select the next window, regardless of which frame it is on."
412 (select-window (next-window (selected-window)
413 (> (minibuffer-depth) 0)
416 (defun previous-multiframe-window ()
417 "Select the previous window, regardless of which frame it is on."
419 (select-window (previous-window (selected-window)
420 (> (minibuffer-depth) 0)
423 (defun make-frame-on-display (display &optional parameters
)
424 "Make a frame on display DISPLAY.
425 The optional second argument PARAMETERS specifies additional frame parameters."
426 (interactive "sMake frame on display: ")
427 (or (string-match "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display
)
428 (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
429 (make-frame (cons (cons 'display display
) parameters
)))
431 (defun make-frame-command ()
432 "Make a new frame, and select it if the terminal displays only one frame."
434 (if (and window-system
(not (eq window-system
'pc
)))
436 (select-frame (make-frame))))
438 (defvar before-make-frame-hook nil
439 "Functions to run before a frame is created.")
441 (defvar after-make-frame-functions nil
442 "Functions to run after a frame is created.
443 The functions are run with one arg, the newly created frame.")
445 (defvar after-setting-font-hooks nil
446 "Functions to run after a frame's font has been changed.")
448 ;; Alias, kept temporarily.
449 (defalias 'new-frame
'make-frame
)
451 (defun make-frame (&optional parameters
)
452 "Return a newly created frame displaying the current buffer.
453 Optional argument PARAMETERS is an alist of parameters for the new frame.
454 Each element of PARAMETERS should have the form (NAME . VALUE), for example:
456 (name . STRING) The frame should be named STRING.
458 (width . NUMBER) The frame should be NUMBER characters in width.
459 (height . NUMBER) The frame should be NUMBER text lines high.
461 You cannot specify either `width' or `height', you must use neither or both.
463 (minibuffer . t) The frame should have a minibuffer.
464 (minibuffer . nil) The frame should have no minibuffer.
465 (minibuffer . only) The frame should contain only a minibuffer.
466 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
468 Before the frame is created (via `frame-creation-function'), functions on the
469 hook `before-make-frame-hook' are run. After the frame is created, functions
470 on `after-make-frame-functions' are run with one arg, the newly created frame."
472 (run-hooks 'before-make-frame-hook
)
473 (let ((frame (funcall frame-creation-function parameters
)))
474 (run-hook-with-args 'after-make-frame-functions frame
)
477 (defun filtered-frame-list (predicate)
478 "Return a list of all live frames which satisfy PREDICATE."
479 (let ((frames (frame-list))
481 (while (consp frames
)
482 (if (funcall predicate
(car frames
))
483 (setq good-frames
(cons (car frames
) good-frames
)))
484 (setq frames
(cdr frames
)))
487 (defun minibuffer-frame-list ()
488 "Return a list of all frames with their own minibuffers."
490 (function (lambda (frame)
491 (eq frame
(window-frame (minibuffer-window frame
)))))))
493 (defun frame-remove-geometry-params (param-list)
494 "Return the parameter list PARAM-LIST, but with geometry specs removed.
495 This deletes all bindings in PARAM-LIST for `top', `left', `width',
496 `height', `user-size' and `user-position' parameters.
497 Emacs uses this to avoid overriding explicit moves and resizings from
498 the user during startup."
499 (setq param-list
(cons nil param-list
))
500 (let ((tail param-list
))
501 (while (consp (cdr tail
))
502 (if (and (consp (car (cdr tail
)))
503 (memq (car (car (cdr tail
)))
504 '(height width top left user-position user-size
)))
506 (setq frame-initial-geometry-arguments
507 (cons (car (cdr tail
)) frame-initial-geometry-arguments
))
508 (setcdr tail
(cdr (cdr tail
))))
509 (setq tail
(cdr tail
)))))
510 (setq frame-initial-geometry-arguments
511 (nreverse frame-initial-geometry-arguments
))
515 (defcustom focus-follows-mouse t
516 "*Non-nil if window system changes focus when you move the mouse."
521 (defun other-frame (arg)
522 "Select the ARG'th different visible frame, and raise it.
523 All frames are arranged in a cyclic order.
524 This command selects the frame ARG steps away in that order.
525 A negative ARG moves in the opposite order."
527 (let ((frame (selected-frame)))
529 (setq frame
(next-frame frame
))
530 (while (not (eq (frame-visible-p frame
) t
))
531 (setq frame
(next-frame frame
)))
534 (setq frame
(previous-frame frame
))
535 (while (not (eq (frame-visible-p frame
) t
))
536 (setq frame
(previous-frame frame
)))
540 ;; Ensure, if possible, that frame gets input focus.
541 (if (eq window-system
'w32
)
542 (w32-focus-frame frame
)
543 (when focus-follows-mouse
544 (set-mouse-position (selected-frame) (1- (frame-width)) 0)))))
546 (defun make-frame-names-alist ()
547 (let* ((current-frame (selected-frame))
550 (cons (frame-parameter current-frame
'name
) current-frame
) nil
))
551 (frame (next-frame nil t
)))
552 (while (not (eq frame current-frame
))
554 (setq falist
(cons (cons (frame-parameter frame
'name
) frame
) falist
))
555 (setq frame
(next-frame frame t
))))
558 (defvar frame-name-history nil
)
559 (defun select-frame-by-name (name)
560 "Select the frame whose name is NAME and raise it.
561 If there is no frame by that name, signal an error."
563 (let* ((frame-names-alist (make-frame-names-alist))
564 (default (car (car frame-names-alist
)))
565 (input (completing-read
566 (format "Select Frame (default %s): " default
)
567 frame-names-alist nil t nil
'frame-name-history
)))
568 (if (= (length input
) 0)
571 (let* ((frame-names-alist (make-frame-names-alist))
572 (frame (cdr (assoc name frame-names-alist
))))
574 (error "There is no frame named `%s'" name
))
575 (make-frame-visible frame
)
578 ;; Ensure, if possible, that frame gets input focus.
579 (if (eq window-system
'w32
)
580 (w32-focus-frame frame
)
581 (when focus-follows-mouse
582 (set-mouse-position (selected-frame) (1- (frame-width)) 0)))))
584 ;;;; Frame configurations
586 (defun current-frame-configuration ()
587 "Return a list describing the positions and states of all frames.
588 Its car is `frame-configuration'.
589 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
591 FRAME is a frame object,
592 ALIST is an association list specifying some of FRAME's parameters, and
593 WINDOW-CONFIG is a window configuration object for FRAME."
594 (cons 'frame-configuration
598 (frame-parameters frame
)
599 (current-window-configuration frame
))))
602 (defun set-frame-configuration (configuration &optional nodelete
)
603 "Restore the frames to the state described by CONFIGURATION.
604 Each frame listed in CONFIGURATION has its position, size, window
605 configuration, and other parameters set as specified in CONFIGURATION.
606 Ordinarily, this function deletes all existing frames not
607 listed in CONFIGURATION. But if optional second argument NODELETE
608 is given and non-nil, the unwanted frames are iconified instead."
609 (or (frame-configuration-p configuration
)
610 (signal 'wrong-type-argument
611 (list 'frame-configuration-p configuration
)))
612 (let ((config-alist (cdr configuration
))
616 (let ((parameters (assq frame config-alist
)))
619 (modify-frame-parameters
621 ;; Since we can't set a frame's minibuffer status,
622 ;; we might as well omit the parameter altogether.
623 (let* ((parms (nth 1 parameters
))
624 (mini (assq 'minibuffer parms
)))
625 (if mini
(setq parms
(delq mini parms
)))
627 (set-window-configuration (nth 2 parameters
)))
628 (setq frames-to-delete
(cons frame frames-to-delete
))))))
631 ;; Note: making frames invisible here was tried
632 ;; but led to some strange behavior--each time the frame
633 ;; was made visible again, the window manager asked afresh
634 ;; for where to put it.
635 (mapcar 'iconify-frame frames-to-delete
)
636 (mapcar 'delete-frame frames-to-delete
))))
638 ;;;; Convenience functions for accessing and interactively changing
639 ;;;; frame parameters.
641 (defun frame-parameter (frame parameter
)
642 "Return FRAME's value for parameter PARAMETER.
643 If FRAME is nil, describe the currently selected frame."
644 (cdr (assq parameter
(frame-parameters frame
))))
646 (defun frame-height (&optional frame
)
647 "Return number of lines available for display on FRAME.
648 If FRAME is omitted, describe the currently selected frame."
649 (cdr (assq 'height
(frame-parameters frame
))))
651 (defun frame-width (&optional frame
)
652 "Return number of columns available for display on FRAME.
653 If FRAME is omitted, describe the currently selected frame."
654 (cdr (assq 'width
(frame-parameters frame
))))
656 (defalias 'set-default-font
'set-frame-font
)
657 (defun set-frame-font (font-name)
658 "Set the font of the selected frame to FONT-NAME.
659 When called interactively, prompt for the name of the font to use.
660 To get the frame's current default font, use `frame-parameters'."
661 (interactive "sFont name: ")
662 (modify-frame-parameters (selected-frame)
663 (list (cons 'font font-name
)))
664 ;; Update faces that want a bold or italic version of the default font.
665 (frame-update-faces (selected-frame))
666 (run-hooks 'after-setting-font-hooks
))
668 (defun set-background-color (color-name)
669 "Set the background color of the selected frame to COLOR-NAME.
670 When called interactively, prompt for the name of the color to use.
671 To get the frame's current background color, use `frame-parameters'."
672 (interactive (list (facemenu-read-color)))
673 (modify-frame-parameters (selected-frame)
674 (list (cons 'background-color color-name
)))
675 (frame-update-face-colors (selected-frame)))
677 (defun set-foreground-color (color-name)
678 "Set the foreground color of the selected frame to COLOR-NAME.
679 When called interactively, prompt for the name of the color to use.
680 To get the frame's current foreground color, use `frame-parameters'."
681 (interactive (list (facemenu-read-color)))
682 (modify-frame-parameters (selected-frame)
683 (list (cons 'foreground-color color-name
)))
684 (frame-update-face-colors (selected-frame)))
686 (defun set-cursor-color (color-name)
687 "Set the text cursor color of the selected frame to COLOR-NAME.
688 When called interactively, prompt for the name of the color to use.
689 To get the frame's current cursor color, use `frame-parameters'."
690 (interactive (list (facemenu-read-color)))
691 (modify-frame-parameters (selected-frame)
692 (list (cons 'cursor-color color-name
))))
694 (defun set-mouse-color (color-name)
695 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
696 When called interactively, prompt for the name of the color to use.
697 To get the frame's current mouse color, use `frame-parameters'."
698 (interactive (list (facemenu-read-color)))
699 (modify-frame-parameters (selected-frame)
700 (list (cons 'mouse-color
702 (cdr (assq 'mouse-color
703 (frame-parameters))))))))
705 (defun set-border-color (color-name)
706 "Set the color of the border of the selected frame to COLOR-NAME.
707 When called interactively, prompt for the name of the color to use.
708 To get the frame's current border color, use `frame-parameters'."
709 (interactive (list (facemenu-read-color)))
710 (modify-frame-parameters (selected-frame)
711 (list (cons 'border-color color-name
))))
713 (defun auto-raise-mode (arg)
714 "Toggle whether or not the selected frame should auto-raise.
715 With arg, turn auto-raise mode on if and only if arg is positive.
716 Note that this controls Emacs's own auto-raise feature.
717 Some window managers allow you to enable auto-raise for certain windows.
718 You can use that for Emacs windows if you wish, but if you do,
719 that is beyond the control of Emacs and this command has no effect on it."
723 (if (cdr (assq 'auto-raise
(frame-parameters (selected-frame))))
726 (raise-frame (selected-frame)))
727 (modify-frame-parameters (selected-frame)
728 (list (cons 'auto-raise
(> arg
0)))))
730 (defun auto-lower-mode (arg)
731 "Toggle whether or not the selected frame should auto-lower.
732 With arg, turn auto-lower mode on if and only if arg is positive.
733 Note that this controls Emacs's own auto-lower feature.
734 Some window managers allow you to enable auto-lower for certain windows.
735 You can use that for Emacs windows if you wish, but if you do,
736 that is beyond the control of Emacs and this command has no effect on it."
740 (if (cdr (assq 'auto-lower
(frame-parameters (selected-frame))))
742 (modify-frame-parameters (selected-frame)
743 (list (cons 'auto-lower
(> arg
0)))))
744 (defun set-frame-name (name)
745 "Set the name of the selected frame to NAME.
746 When called interactively, prompt for the name of the frame.
747 The frame name is displayed on the modeline if the terminal displays only
748 one frame, otherwise the name is displayed on the frame's caption bar."
749 (interactive "sFrame name: ")
750 (modify-frame-parameters (selected-frame)
751 (list (cons 'name name
))))
753 ;;;; Aliases for backward compatibility with Emacs 18.
754 (defalias 'screen-height
'frame-height
)
755 (defalias 'screen-width
'frame-width
)
757 (defun set-screen-width (cols &optional pretend
)
758 "Obsolete function to change the size of the screen to COLS columns.
759 Optional second arg non-nil means that redisplay should use COLS columns
760 but that the idea of the actual width of the frame should not be changed.
761 This function is provided only for compatibility with Emacs 18; new code
762 should use `set-frame-width instead'."
763 (set-frame-width (selected-frame) cols pretend
))
765 (defun set-screen-height (lines &optional pretend
)
766 "Obsolete function to change the height of the screen to LINES lines.
767 Optional second arg non-nil means that redisplay should use LINES lines
768 but that the idea of the actual height of the screen should not be changed.
769 This function is provided only for compatibility with Emacs 18; new code
770 should use `set-frame-height' instead."
771 (set-frame-height (selected-frame) lines pretend
))
773 (make-obsolete 'screen-height
'frame-height
)
774 (make-obsolete 'screen-width
'frame-width
)
775 (make-obsolete 'set-screen-width
'set-frame-width
)
776 (make-obsolete 'set-screen-height
'set-frame-height
)
779 ;;; Highlighting trailing whitespace.
781 (make-variable-buffer-local 'show-trailing-whitespace
)
783 (defcustom show-trailing-whitespace nil
784 "*Non-nil means highlight trailing whitespace in face `trailing-whitespace'."
785 :tag
"Highlight trailing whitespace."
786 :set
#'(lambda (symbol value
) (set-default symbol value
))
795 "Displaying text cursors."
799 (defcustom blink-cursor-delay
0.5
800 "*Seconds of idle time after which cursor starts to blink."
801 :tag
"Delay in seconds."
805 (defcustom blink-cursor-interval
0.5
806 "*Length of cursor blink interval in seconds."
807 :tag
"Blink interval in seconds."
811 (defvar blink-cursor-idle-timer nil
812 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
813 The function `blink-cursor-start' is called when the timer fires.")
815 (defvar blink-cursor-timer nil
816 "Timer started from `blink-cursor-start'.
817 This timer calls `blink-cursor' every `blink-cursor-interval' seconds.")
819 (defvar blink-cursor-mode nil
820 "Non-nil means blinking cursor is active.")
822 (defun blink-cursor-mode (arg)
823 "Toggle blinking cursor mode.
824 With arg, turn blinking cursor mode on iff arg is positive.
825 When blinking cursor mode is enabled, the cursor of the selected
828 (let ((on-p (if (null arg
)
829 (not blink-cursor-mode
)
830 (> (prefix-numeric-value arg
) 0))))
831 (if blink-cursor-idle-timer
832 (cancel-timer blink-cursor-idle-timer
))
833 (if blink-cursor-timer
834 (cancel-timer blink-cursor-timer
))
835 (setq blink-cursor-idle-timer nil
836 blink-cursor-timer nil
837 blink-cursor-mode nil
)
841 (internal-show-cursor nil nil
)
842 (setq blink-cursor-idle-timer
843 (run-with-idle-timer blink-cursor-delay
845 'blink-cursor-start
))
846 (setq blink-cursor-mode t
)))))
848 (defcustom blink-cursor
(not (eq system-type
'ms-dos
))
849 "*Non-nil means blinking cursor mode is active."
850 :tag
"Blinking cursor"
853 :set
#'(lambda (symbol value
)
854 (set-default symbol value
)
855 (blink-cursor-mode (or value
0))))
857 (defun blink-cursor-start ()
858 "Timer function called from the timer `blink-cursor-idle-timer'.
859 This starts the timer `blink-cursor-timer', which makes the cursor blink
860 if appropriate. It also arranges to cancel that timer when the next
861 command starts, by installing a pre-command hook."
862 (when (null blink-cursor-timer
)
863 (add-hook 'pre-command-hook
'blink-cursor-end
)
864 (setq blink-cursor-timer
865 (run-with-timer blink-cursor-interval blink-cursor-interval
866 'blink-cursor-timer-function
))))
868 (defun blink-cursor-timer-function ()
869 "Timer function of timer `blink-cursor-timer'."
870 (internal-show-cursor nil
(not (internal-show-cursor-p))))
872 (defun blink-cursor-end ()
873 "Stop cursor blinking.
874 This is installed as a pre-command hook by `blink-cursor-start'.
875 When run, it cancels the timer `blink-cursor-timer' and removes
876 itself as a pre-command hook."
877 (remove-hook 'pre-command-hook
'blink-cursor-end
)
878 (internal-show-cursor nil t
)
879 (cancel-timer blink-cursor-timer
)
880 (setq blink-cursor-timer nil
))
886 (defcustom busy-cursor t
887 "*Non-nil means show a busy-cursor when running under a window system."
891 :get
#'(lambda (symbol) display-busy-cursor
)
892 :set
#'(lambda (symbol value
)
893 (set-default symbol value
)
894 (setq display-busy-cursor value
)))
900 (define-key ctl-x-5-map
"2" 'make-frame-command
)
901 (define-key ctl-x-5-map
"0" 'delete-frame
)
902 (define-key ctl-x-5-map
"o" 'other-frame
)
906 ;;; frame.el ends here
907 (frame-notice-user-settings):