(lm-get-header-re): Allow spaces between the header and the colon.
[emacs.git] / lisp / frame.el
blobe4770cc6be1d2a375020d9b0548c114e72b24e6e
1 ;;; frame.el --- multi-frame management independent of window systems.
3 ;; Copyright (C) 1993, 1994, 1996, 1997, 2000 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
6 ;; Keywords: internal
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)
13 ;; any later version.
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.
25 ;;; Code:
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")
57 (sexp :tag "Value")))
58 :group 'frames)
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")
69 (sexp :tag "Value")))
70 :group 'frames)
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',
78 for pop-up frames."
79 :type '(repeat (cons :format "%v"
80 (symbol :tag "Parameter")
81 (sexp :tag "Value")))
82 :group 'frames)
84 (setq pop-up-frame-function
85 (function (lambda ()
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")
99 (sexp :tag "Value")))
100 :group 'frames)
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)))
113 (if window
114 ;; If we have a window already, make it visible.
115 (let ((frame (window-frame window)))
116 (make-frame-visible frame)
117 (raise-frame frame)
118 window)
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."
127 (interactive "e")
128 (let ((frame (posn-window (event-start event)))
129 (i 0)
130 (tail (frame-list)))
131 (while tail
132 (and (frame-visible-p (car tail))
133 (not (eq (car tail) frame))
134 (setq i (1+ i)))
135 (setq tail (cdr tail)))
136 (if (> i 0)
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)))
173 (progn
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
180 ;; minibuffer spec.
181 (or (delq terminal-frame (minibuffer-frame-list))
182 (progn
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
209 (function
210 (lambda (parameters)
211 (error
212 "Can't create multiple frames without a window system"))))))))
214 (defvar frame-notice-user-settings t
215 "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
217 ;;; startup.el calls this function after loading the user's init
218 ;;; file. Now default-frame-alist and initial-frame-alist contain
219 ;;; information to which we must react; do what needs to be done.
220 (defun frame-notice-user-settings ()
221 "Act on user's init file settings of frame parameters.
222 React to settings of `default-frame-alist', `initial-frame-alist' there."
223 ;; Make menu-bar-mode and default-frame-alist consistent.
224 (if (boundp 'menu-bar-mode)
225 (let ((default (assq 'menu-bar-lines default-frame-alist)))
226 (if default
227 (setq menu-bar-mode (not (eq (cdr default) 0)))
228 (setq default-frame-alist
229 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
230 default-frame-alist)))))
232 ;; Creating and deleting frames may shift the selected frame around,
233 ;; and thus the current buffer. Protect against that. We don't
234 ;; want to use save-excursion here, because that may also try to set
235 ;; the buffer of the selected window, which fails when the selected
236 ;; window is the minibuffer.
237 (let ((old-buffer (current-buffer)))
239 (when (and frame-notice-user-settings
240 (null frame-initial-frame))
241 ;; This case happens when we don't have a window system.
242 (let ((parms (frame-parameters frame-initial-frame)))
243 ;; Don't change the frame names.
244 (setq parms (delq (assq 'name parms) parms))
245 ;; Can't modify the minibuffer parameter, so don't try.
246 (setq parms (delq (assq 'minibuffer parms) parms))
247 (modify-frame-parameters nil
248 (append initial-frame-alist
249 default-frame-alist
250 parms
251 nil))))
253 ;; If the initial frame is still around, apply initial-frame-alist
254 ;; and default-frame-alist to it.
255 (if (frame-live-p frame-initial-frame)
257 ;; The initial frame we create above always has a minibuffer.
258 ;; If the user wants to remove it, or make it a minibuffer-only
259 ;; frame, then we'll have to delete the current frame and make a
260 ;; new one; you can't remove or add a root window to/from an
261 ;; existing frame.
263 ;; NOTE: default-frame-alist was nil when we created the
264 ;; existing frame. We need to explicitly include
265 ;; default-frame-alist in the parameters of the screen we
266 ;; create here, so that its new value, gleaned from the user's
267 ;; .emacs file, will be applied to the existing screen.
268 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
269 (assq 'minibuffer default-frame-alist)
270 '(minibuffer . t)))
272 ;; Create the new frame.
273 (let (parms new)
274 ;; If the frame isn't visible yet, wait till it is.
275 ;; If the user has to position the window,
276 ;; Emacs doesn't know its real position until
277 ;; the frame is seen to be visible.
278 (while (not (cdr (assq 'visibility
279 (frame-parameters frame-initial-frame))))
280 (sleep-for 1))
281 (setq parms (frame-parameters frame-initial-frame))
282 ;; Get rid of `name' unless it was specified explicitly before.
283 (or (assq 'name frame-initial-frame-alist)
284 (setq parms (delq (assq 'name parms) parms)))
285 (setq parms (append initial-frame-alist
286 default-frame-alist
287 parms
288 nil))
289 ;; Get rid of `reverse', because that was handled
290 ;; when we first made the frame.
291 (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
292 (if (assq 'height frame-initial-geometry-arguments)
293 (setq parms (assq-delete-all 'height parms)))
294 (if (assq 'width frame-initial-geometry-arguments)
295 (setq parms (assq-delete-all 'width parms)))
296 (if (assq 'left frame-initial-geometry-arguments)
297 (setq parms (assq-delete-all 'left parms)))
298 (if (assq 'top frame-initial-geometry-arguments)
299 (setq parms (assq-delete-all 'top parms)))
300 (setq new
301 (make-frame
302 ;; Use the geometry args that created the existing
303 ;; frame, rather than the parms we get for it.
304 (append frame-initial-geometry-arguments
305 '((user-size . t) (user-position . t))
306 parms)))
307 ;; The initial frame, which we are about to delete, may be
308 ;; the only frame with a minibuffer. If it is, create a
309 ;; new one.
310 (or (delq frame-initial-frame (minibuffer-frame-list))
311 (make-initial-minibuffer-frame nil))
313 ;; If the initial frame is serving as a surrogate
314 ;; minibuffer frame for any frames, we need to wean them
315 ;; onto a new frame. The default-minibuffer-frame
316 ;; variable must be handled similarly.
317 (let ((users-of-initial
318 (filtered-frame-list
319 (function (lambda (frame)
320 (and (not (eq frame frame-initial-frame))
321 (eq (window-frame
322 (minibuffer-window frame))
323 frame-initial-frame)))))))
324 (if (or users-of-initial
325 (eq default-minibuffer-frame frame-initial-frame))
327 ;; Choose an appropriate frame. Prefer frames which
328 ;; are only minibuffers.
329 (let* ((new-surrogate
330 (car
331 (or (filtered-frame-list
332 (function
333 (lambda (frame)
334 (eq (cdr (assq 'minibuffer
335 (frame-parameters frame)))
336 'only))))
337 (minibuffer-frame-list))))
338 (new-minibuffer (minibuffer-window new-surrogate)))
340 (if (eq default-minibuffer-frame frame-initial-frame)
341 (setq default-minibuffer-frame new-surrogate))
343 ;; Wean the frames using frame-initial-frame as
344 ;; their minibuffer frame.
345 (mapcar
346 (function
347 (lambda (frame)
348 (modify-frame-parameters
349 frame (list (cons 'minibuffer new-minibuffer)))))
350 users-of-initial))))
352 ;; Redirect events enqueued at this frame to the new frame.
353 ;; Is this a good idea?
354 (redirect-frame-focus frame-initial-frame new)
356 ;; Finally, get rid of the old frame.
357 (delete-frame frame-initial-frame t))
359 ;; Otherwise, we don't need all that rigamarole; just apply
360 ;; the new parameters.
361 (let (newparms allparms tail)
362 (setq allparms (append initial-frame-alist
363 default-frame-alist))
364 (if (assq 'height frame-initial-geometry-arguments)
365 (setq allparms (assq-delete-all 'height allparms)))
366 (if (assq 'width frame-initial-geometry-arguments)
367 (setq allparms (assq-delete-all 'width allparms)))
368 (if (assq 'left frame-initial-geometry-arguments)
369 (setq allparms (assq-delete-all 'left allparms)))
370 (if (assq 'top frame-initial-geometry-arguments)
371 (setq allparms (assq-delete-all 'top allparms)))
372 (setq tail allparms)
373 ;; Find just the parms that have changed since we first
374 ;; made this frame. Those are the ones actually set by
375 ;; the init file. For those parms whose values we already knew
376 ;; (such as those spec'd by command line options)
377 ;; it is undesirable to specify the parm again
378 ;; once the user has seen the frame and been able to alter it
379 ;; manually.
380 (while tail
381 (let (newval oldval)
382 (setq oldval (assq (car (car tail))
383 frame-initial-frame-alist))
384 (setq newval (cdr (assq (car (car tail)) allparms)))
385 (or (and oldval (eq (cdr oldval) newval))
386 (setq newparms
387 (cons (cons (car (car tail)) newval) newparms))))
388 (setq tail (cdr tail)))
389 (setq newparms (nreverse newparms))
390 (modify-frame-parameters frame-initial-frame
391 newparms)
392 ;; If we changed the background color,
393 ;; we need to update the background-mode parameter
394 ;; and maybe some faces too.
395 (when (assq 'background-color newparms)
396 (unless (assq 'background-mode newparms)
397 (frame-set-background-mode frame-initial-frame))
398 (face-set-after-frame-default frame-initial-frame))
399 (if (assq 'font newparms)
400 (frame-update-faces frame-initial-frame)))))
402 ;; Restore the original buffer.
403 (set-buffer old-buffer)
405 ;; Make sure the initial frame can be GC'd if it is ever deleted.
406 ;; Make sure frame-notice-user-settings does nothing if called twice.
407 (setq frame-notice-user-settings nil)
408 (setq frame-initial-frame nil)))
410 (defun make-initial-minibuffer-frame (display)
411 (let ((parms (append minibuffer-frame-alist '((minibuffer . only)))))
412 (if display
413 (make-frame-on-display display parms)
414 (make-frame parms))))
416 ;;;; Creation of additional frames, and other frame miscellanea
418 (defun get-other-frame ()
419 "Return some frame other than the current frame.
420 Create one if necessary. Note that the minibuffer frame, if separate,
421 is not considered (see `next-frame')."
422 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
423 (make-frame)
424 (next-frame (selected-frame)))))
427 (defun next-multiframe-window ()
428 "Select the next window, regardless of which frame it is on."
429 (interactive)
430 (select-window (next-window (selected-window)
431 (> (minibuffer-depth) 0)
432 t)))
434 (defun previous-multiframe-window ()
435 "Select the previous window, regardless of which frame it is on."
436 (interactive)
437 (select-window (previous-window (selected-window)
438 (> (minibuffer-depth) 0)
439 t)))
441 (defun make-frame-on-display (display &optional parameters)
442 "Make a frame on display DISPLAY.
443 The optional second argument PARAMETERS specifies additional frame parameters."
444 (interactive "sMake frame on display: ")
445 (or (string-match "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display)
446 (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
447 (make-frame (cons (cons 'display display) parameters)))
449 (defun make-frame-command ()
450 "Make a new frame, and select it if the terminal displays only one frame."
451 (interactive)
452 (if (and window-system (not (eq window-system 'pc)))
453 (make-frame)
454 (select-frame (make-frame))))
456 (defvar before-make-frame-hook nil
457 "Functions to run before a frame is created.")
459 (defvar after-make-frame-functions nil
460 "Functions to run after a frame is created.
461 The functions are run with one arg, the newly created frame.")
463 (defvar after-setting-font-hooks nil
464 "Functions to run after a frame's font has been changed.")
466 ;; Alias, kept temporarily.
467 (defalias 'new-frame 'make-frame)
469 (defun make-frame (&optional parameters)
470 "Return a newly created frame displaying the current buffer.
471 Optional argument PARAMETERS is an alist of parameters for the new frame.
472 Each element of PARAMETERS should have the form (NAME . VALUE), for example:
474 (name . STRING) The frame should be named STRING.
476 (width . NUMBER) The frame should be NUMBER characters in width.
477 (height . NUMBER) The frame should be NUMBER text lines high.
479 You cannot specify either `width' or `height', you must use neither or both.
481 (minibuffer . t) The frame should have a minibuffer.
482 (minibuffer . nil) The frame should have no minibuffer.
483 (minibuffer . only) The frame should contain only a minibuffer.
484 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
486 Before the frame is created (via `frame-creation-function'), functions on the
487 hook `before-make-frame-hook' are run. After the frame is created, functions
488 on `after-make-frame-functions' are run with one arg, the newly created frame."
489 (interactive)
490 (run-hooks 'before-make-frame-hook)
491 (let ((frame (funcall frame-creation-function parameters)))
492 (run-hook-with-args 'after-make-frame-functions frame)
493 frame))
495 (defun filtered-frame-list (predicate)
496 "Return a list of all live frames which satisfy PREDICATE."
497 (let* ((frames (frame-list))
498 (list frames))
499 (while (consp frames)
500 (unless (funcall predicate (car frames))
501 (setcar frames nil))
502 (setq frames (cdr frames)))
503 (delq nil list)))
505 (defun minibuffer-frame-list ()
506 "Return a list of all frames with their own minibuffers."
507 (filtered-frame-list
508 (function (lambda (frame)
509 (eq frame (window-frame (minibuffer-window frame)))))))
511 (defun frames-on-display-list (&optional display)
512 "Return a list of all frames on DISPLAY.
513 DISPLAY is a name of a display, a string of the form HOST:SERVER.SCREEN.
514 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
515 (let* ((display (or display (frame-parameter nil 'display)))
516 (func #'(lambda (frame)
517 (eq (frame-parameter frame 'display) display))))
518 (filtered-frame-list func)))
520 (defun framep-on-display (&optional display)
521 "Return the type of frames on DISPLAY.
522 DISPLAY may be a display name or a frame. If it is a frame, its type is
523 returned.
524 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
525 All frames on a given display are of the same type."
526 (or (framep display)
527 (framep (car (frames-on-display-list display)))))
529 (defun frame-remove-geometry-params (param-list)
530 "Return the parameter list PARAM-LIST, but with geometry specs removed.
531 This deletes all bindings in PARAM-LIST for `top', `left', `width',
532 `height', `user-size' and `user-position' parameters.
533 Emacs uses this to avoid overriding explicit moves and resizings from
534 the user during startup."
535 (setq param-list (cons nil param-list))
536 (let ((tail param-list))
537 (while (consp (cdr tail))
538 (if (and (consp (car (cdr tail)))
539 (memq (car (car (cdr tail)))
540 '(height width top left user-position user-size)))
541 (progn
542 (setq frame-initial-geometry-arguments
543 (cons (car (cdr tail)) frame-initial-geometry-arguments))
544 (setcdr tail (cdr (cdr tail))))
545 (setq tail (cdr tail)))))
546 (setq frame-initial-geometry-arguments
547 (nreverse frame-initial-geometry-arguments))
548 (cdr param-list))
551 (defcustom focus-follows-mouse t
552 "*Non-nil if window system changes focus when you move the mouse."
553 :type 'boolean
554 :group 'frames
555 :version "20.3")
557 (defun other-frame (arg)
558 "Select the ARG'th different visible frame, and raise it.
559 All frames are arranged in a cyclic order.
560 This command selects the frame ARG steps away in that order.
561 A negative ARG moves in the opposite order."
562 (interactive "p")
563 (let ((frame (selected-frame)))
564 (while (> arg 0)
565 (setq frame (next-frame frame))
566 (while (not (eq (frame-visible-p frame) t))
567 (setq frame (next-frame frame)))
568 (setq arg (1- arg)))
569 (while (< arg 0)
570 (setq frame (previous-frame frame))
571 (while (not (eq (frame-visible-p frame) t))
572 (setq frame (previous-frame frame)))
573 (setq arg (1+ arg)))
574 (select-frame frame)
575 (raise-frame frame)
576 ;; Ensure, if possible, that frame gets input focus.
577 (when (eq window-system 'w32)
578 (w32-focus-frame frame))
579 (cond (focus-follows-mouse
580 (unless (eq window-system 'w32)
581 (set-mouse-position (selected-frame) (1- (frame-width)) 0)))
583 (when (eq window-system 'x)
584 (x-focus-frame frame))))))
586 (defun make-frame-names-alist ()
587 (let* ((current-frame (selected-frame))
588 (falist
589 (cons
590 (cons (frame-parameter current-frame 'name) current-frame) nil))
591 (frame (next-frame nil t)))
592 (while (not (eq frame current-frame))
593 (progn
594 (setq falist (cons (cons (frame-parameter frame 'name) frame) falist))
595 (setq frame (next-frame frame t))))
596 falist))
598 (defvar frame-name-history nil)
599 (defun select-frame-by-name (name)
600 "Select the frame whose name is NAME and raise it.
601 If there is no frame by that name, signal an error."
602 (interactive
603 (let* ((frame-names-alist (make-frame-names-alist))
604 (default (car (car frame-names-alist)))
605 (input (completing-read
606 (format "Select Frame (default %s): " default)
607 frame-names-alist nil t nil 'frame-name-history)))
608 (if (= (length input) 0)
609 (list default)
610 (list input))))
611 (let* ((frame-names-alist (make-frame-names-alist))
612 (frame (cdr (assoc name frame-names-alist))))
613 (or frame
614 (error "There is no frame named `%s'" name))
615 (make-frame-visible frame)
616 (raise-frame frame)
617 (select-frame frame)
618 ;; Ensure, if possible, that frame gets input focus.
619 (if (eq window-system 'w32)
620 (w32-focus-frame frame)
621 (when focus-follows-mouse
622 (set-mouse-position (selected-frame) (1- (frame-width)) 0)))))
624 ;;;; Frame configurations
626 (defun current-frame-configuration ()
627 "Return a list describing the positions and states of all frames.
628 Its car is `frame-configuration'.
629 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
630 where
631 FRAME is a frame object,
632 ALIST is an association list specifying some of FRAME's parameters, and
633 WINDOW-CONFIG is a window configuration object for FRAME."
634 (cons 'frame-configuration
635 (mapcar (function
636 (lambda (frame)
637 (list frame
638 (frame-parameters frame)
639 (current-window-configuration frame))))
640 (frame-list))))
642 (defun set-frame-configuration (configuration &optional nodelete)
643 "Restore the frames to the state described by CONFIGURATION.
644 Each frame listed in CONFIGURATION has its position, size, window
645 configuration, and other parameters set as specified in CONFIGURATION.
646 Ordinarily, this function deletes all existing frames not
647 listed in CONFIGURATION. But if optional second argument NODELETE
648 is given and non-nil, the unwanted frames are iconified instead."
649 (or (frame-configuration-p configuration)
650 (signal 'wrong-type-argument
651 (list 'frame-configuration-p configuration)))
652 (let ((config-alist (cdr configuration))
653 frames-to-delete)
654 (mapcar (function
655 (lambda (frame)
656 (let ((parameters (assq frame config-alist)))
657 (if parameters
658 (progn
659 (modify-frame-parameters
660 frame
661 ;; Since we can't set a frame's minibuffer status,
662 ;; we might as well omit the parameter altogether.
663 (let* ((parms (nth 1 parameters))
664 (mini (assq 'minibuffer parms)))
665 (if mini (setq parms (delq mini parms)))
666 parms))
667 (set-window-configuration (nth 2 parameters)))
668 (setq frames-to-delete (cons frame frames-to-delete))))))
669 (frame-list))
670 (if nodelete
671 ;; Note: making frames invisible here was tried
672 ;; but led to some strange behavior--each time the frame
673 ;; was made visible again, the window manager asked afresh
674 ;; for where to put it.
675 (mapcar 'iconify-frame frames-to-delete)
676 (mapcar 'delete-frame frames-to-delete))))
678 ;;;; Convenience functions for accessing and interactively changing
679 ;;;; frame parameters.
681 (defun frame-height (&optional frame)
682 "Return number of lines available for display on FRAME.
683 If FRAME is omitted, describe the currently selected frame."
684 (cdr (assq 'height (frame-parameters frame))))
686 (defun frame-width (&optional frame)
687 "Return number of columns available for display on FRAME.
688 If FRAME is omitted, describe the currently selected frame."
689 (cdr (assq 'width (frame-parameters frame))))
691 (defalias 'set-default-font 'set-frame-font)
692 (defun set-frame-font (font-name)
693 "Set the font of the selected frame to FONT-NAME.
694 When called interactively, prompt for the name of the font to use.
695 To get the frame's current default font, use `frame-parameters'."
696 (interactive
697 (list
698 (let ((completion-ignore-case t))
699 (completing-read "Font name: "
700 (mapcar #'list
701 ;; x-list-fonts will fail with an error
702 ;; if this frame doesn't support fonts.
703 (x-list-fonts "*" nil (selected-frame)))))))
704 (modify-frame-parameters (selected-frame)
705 (list (cons 'font font-name)))
706 ;; Update faces that want a bold or italic version of the default font.
707 (frame-update-faces (selected-frame))
708 (run-hooks 'after-setting-font-hooks))
710 (defun set-background-color (color-name)
711 "Set the background color of the selected frame to COLOR-NAME.
712 When called interactively, prompt for the name of the color to use.
713 To get the frame's current background color, use `frame-parameters'."
714 (interactive (list (facemenu-read-color)))
715 (modify-frame-parameters (selected-frame)
716 (list (cons 'background-color color-name)))
717 (frame-update-face-colors (selected-frame)))
719 (defun set-foreground-color (color-name)
720 "Set the foreground color of the selected frame to COLOR-NAME.
721 When called interactively, prompt for the name of the color to use.
722 To get the frame's current foreground color, use `frame-parameters'."
723 (interactive (list (facemenu-read-color)))
724 (modify-frame-parameters (selected-frame)
725 (list (cons 'foreground-color color-name)))
726 (frame-update-face-colors (selected-frame)))
728 (defun set-cursor-color (color-name)
729 "Set the text cursor color of the selected frame to COLOR-NAME.
730 When called interactively, prompt for the name of the color to use.
731 To get the frame's current cursor color, use `frame-parameters'."
732 (interactive (list (facemenu-read-color)))
733 (modify-frame-parameters (selected-frame)
734 (list (cons 'cursor-color color-name))))
736 (defun set-mouse-color (color-name)
737 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
738 When called interactively, prompt for the name of the color to use.
739 To get the frame's current mouse color, use `frame-parameters'."
740 (interactive (list (facemenu-read-color)))
741 (modify-frame-parameters (selected-frame)
742 (list (cons 'mouse-color
743 (or color-name
744 (cdr (assq 'mouse-color
745 (frame-parameters))))))))
747 (defun set-border-color (color-name)
748 "Set the color of the border of the selected frame to COLOR-NAME.
749 When called interactively, prompt for the name of the color to use.
750 To get the frame's current border color, use `frame-parameters'."
751 (interactive (list (facemenu-read-color)))
752 (modify-frame-parameters (selected-frame)
753 (list (cons 'border-color color-name))))
755 (defun auto-raise-mode (arg)
756 "Toggle whether or not the selected frame should auto-raise.
757 With arg, turn auto-raise mode on if and only if arg is positive.
758 Note that this controls Emacs's own auto-raise feature.
759 Some window managers allow you to enable auto-raise for certain windows.
760 You can use that for Emacs windows if you wish, but if you do,
761 that is beyond the control of Emacs and this command has no effect on it."
762 (interactive "P")
763 (if (null arg)
764 (setq arg
765 (if (cdr (assq 'auto-raise (frame-parameters (selected-frame))))
766 -1 1)))
767 (if (> arg 0)
768 (raise-frame (selected-frame)))
769 (modify-frame-parameters (selected-frame)
770 (list (cons 'auto-raise (> arg 0)))))
772 (defun auto-lower-mode (arg)
773 "Toggle whether or not the selected frame should auto-lower.
774 With arg, turn auto-lower mode on if and only if arg is positive.
775 Note that this controls Emacs's own auto-lower feature.
776 Some window managers allow you to enable auto-lower for certain windows.
777 You can use that for Emacs windows if you wish, but if you do,
778 that is beyond the control of Emacs and this command has no effect on it."
779 (interactive "P")
780 (if (null arg)
781 (setq arg
782 (if (cdr (assq 'auto-lower (frame-parameters (selected-frame))))
783 -1 1)))
784 (modify-frame-parameters (selected-frame)
785 (list (cons 'auto-lower (> arg 0)))))
786 (defun set-frame-name (name)
787 "Set the name of the selected frame to NAME.
788 When called interactively, prompt for the name of the frame.
789 The frame name is displayed on the modeline if the terminal displays only
790 one frame, otherwise the name is displayed on the frame's caption bar."
791 (interactive "sFrame name: ")
792 (modify-frame-parameters (selected-frame)
793 (list (cons 'name name))))
795 ;;;; Frame/display capabilities.
796 (defun display-mouse-p (&optional display)
797 "Return non-nil if DISPLAY has a mouse available.
798 DISPLAY can be a display name, a frame, or nil (meaning the selected
799 frame's display)."
800 (let ((frame-type (framep-on-display display)))
801 (cond
802 ((eq frame-type 'pc)
803 (msdos-mouse-p))
804 ((eq system-type 'windows-nt)
805 (> w32-num-mouse-buttons 0))
806 ((memq frame-type '(x mac))
807 t) ;; We assume X and Mac *always* have a pointing device
809 (or (and (featurep 'xt-mouse)
810 xterm-mouse-mode)
811 ;; t-mouse is distributed with the GPM package. It doesn't have
812 ;; a toggle.
813 (featurep 't-mouse))))))
815 (defun display-popup-menus-p (&optional display)
816 "Return non-nil if popup menus are supported on DISPLAY.
817 DISPLAY can be a display name, a frame, or nil (meaning the selected
818 frame's display).
819 Support for popup menus requires that the mouse be available."
820 (and
821 (let ((frame-type (framep-on-display display)))
822 (memq frame-type '(x w32 pc mac)))
823 (display-mouse-p display)))
825 (defun display-graphic-p (&optional display)
826 "Return non-nil if DISPLAY is a graphic display.
827 Graphical displays are those which are capable of displaying several
828 frames and several different fonts at once. This is true for displays
829 that use a window system such as X, and false for text-only terminals.
830 DISPLAY can be a display name, a frame, or nil (meaning the selected
831 frame's display)."
832 (not (null (memq (framep-on-display display) '(x w32 mac)))))
834 (defalias 'display-multi-frame-p 'display-graphic-p)
835 (defalias 'display-multi-font-p 'display-graphic-p)
837 (defun display-selections-p (&optional display)
838 "Return non-nil if DISPLAY supports selections.
839 A selection is a way to transfer text or other data between programs
840 via special system buffers called `selection' or `cut buffer' or
841 `clipboard'.
842 DISPLAY can be a display name, a frame, or nil (meaning the selected
843 frame's display)."
844 (let ((frame-type (framep-on-display display)))
845 (cond
846 ((eq frame-type 'pc)
847 ;; MS-DOG frames support selections when Emacs runs inside
848 ;; the Windows' DOS Box.
849 (not (null dos-windows-version)))
850 ((memq frame-type '(x w32 mac))
851 t) ;; FIXME?
853 nil))))
855 (defun display-screens (&optional display)
856 "Return the number of screens associated with DISPLAY."
857 (let ((frame-type (framep-on-display display)))
858 (cond
859 ((memq frame-type '(x w32))
860 (x-display-screens display))
861 (t ;; FIXME: is this correct for the Mac?
862 1))))
864 (defun display-pixel-height (&optional display)
865 "Return the height of DISPLAY's screen in pixels.
866 For character terminals, each character counts as a single pixel."
867 (let ((frame-type (framep-on-display display)))
868 (cond
869 ((memq frame-type '(x w32 mac))
870 (x-display-pixel-height display))
872 (frame-height (if (framep display) display (selected-frame)))))))
874 (defun display-pixel-width (&optional display)
875 "Return the width of DISPLAY's screen in pixels.
876 For character terminals, each character counts as a single pixel."
877 (let ((frame-type (framep-on-display display)))
878 (cond
879 ((memq frame-type '(x w32 mac))
880 (x-display-pixel-width display))
882 (frame-width (if (framep display) display (selected-frame)))))))
884 (defun display-mm-height (&optional display)
885 "Return the height of DISPLAY's screen in millimeters.
886 If the information is unavailable, value is nil."
887 (and (memq (framep-on-display display) '(x w32 mac))
888 (x-display-mm-height display)))
890 (defun display-mm-width (&optional display)
891 "Return the width of DISPLAY's screen in millimeters.
892 If the information is unavailable, value is nil."
893 (and (memq (framep-on-display display) '(x w32 mac))
894 (x-display-mm-width display)))
896 (defun display-backing-store (&optional display)
897 "Return the backing store capability of DISPLAY's screen.
898 The value may be `always', `when-mapped', `not-useful', or nil if
899 the question is inapplicable to a certain kind of display."
900 (let ((frame-type (framep-on-display display)))
901 (cond
902 ((memq frame-type '(x w32 mac))
903 (x-display-backing-store display))
905 'not-useful))))
907 (defun display-save-under (&optional display)
908 "Return non-nil if DISPLAY's screen supports the SaveUnder feature."
909 (let ((frame-type (framep-on-display display)))
910 (cond
911 ((memq frame-type '(x w32 mac))
912 (x-display-save-under display))
914 'not-useful))))
916 (defun display-planes (&optional display)
917 "Return the number of planes supported by DISPLAY."
918 (let ((frame-type (framep-on-display display)))
919 (cond
920 ((memq frame-type '(x w32 mac))
921 (x-display-planes display))
922 ((eq frame-type 'pc)
925 (truncate (log (length (tty-color-alist)) 2))))))
927 (defun display-color-cells (&optional display)
928 "Return the number of color cells supported by DISPLAY."
929 (let ((frame-type (framep-on-display display)))
930 (cond
931 ((memq frame-type '(x w32 mac))
932 (x-display-color-cells display))
933 ((eq frame-type 'pc)
936 (length (tty-color-alist))))))
938 (defun display-visual-class (&optional display)
939 "Returns the visual class of DISPLAY.
940 The value is one of the symbols `static-gray', `gray-scale',
941 `static-color', `pseudo-color', `true-color', or `direct-color'."
942 (let ((frame-type (framep-on-display display)))
943 (cond
944 ((memq frame-type '(x w32 mac))
945 (x-display-visual-class display))
946 ((and (memq frame-type '(pc t))
947 (tty-display-color-p display))
948 'static-color)
950 'static-gray))))
953 ;;;; Aliases for backward compatibility with Emacs 18.
954 (defalias 'screen-height 'frame-height)
955 (defalias 'screen-width 'frame-width)
957 (defun set-screen-width (cols &optional pretend)
958 "Obsolete function to change the size of the screen to COLS columns.
959 Optional second arg non-nil means that redisplay should use COLS columns
960 but that the idea of the actual width of the frame should not be changed.
961 This function is provided only for compatibility with Emacs 18; new code
962 should use `set-frame-width instead'."
963 (set-frame-width (selected-frame) cols pretend))
965 (defun set-screen-height (lines &optional pretend)
966 "Obsolete function to change the height of the screen to LINES lines.
967 Optional second arg non-nil means that redisplay should use LINES lines
968 but that the idea of the actual height of the screen should not be changed.
969 This function is provided only for compatibility with Emacs 18; new code
970 should use `set-frame-height' instead."
971 (set-frame-height (selected-frame) lines pretend))
973 (defun delete-other-frames (&optional frame)
974 "Delete all frames except FRAME.
975 FRAME nil or omitted means delete all frames except the selected frame."
976 (interactive)
977 (unless frame
978 (setq frame (selected-frame)))
979 (mapcar 'delete-frame (delq frame (frame-list))))
982 (make-obsolete 'screen-height 'frame-height) ;before 19.15
983 (make-obsolete 'screen-width 'frame-width) ;before 19.15
984 (make-obsolete 'set-screen-width 'set-frame-width) ;before 19.15
985 (make-obsolete 'set-screen-height 'set-frame-height) ;before 19.15
988 ;;; Highlighting trailing whitespace.
990 (make-variable-buffer-local 'show-trailing-whitespace)
992 (defcustom show-trailing-whitespace nil
993 "*Non-nil means highlight trailing whitespace in face `trailing-whitespace'."
994 :tag "Highlight trailing whitespace."
995 :set #'(lambda (symbol value) (set-default symbol value))
996 :type 'boolean
997 :group 'font-lock)
1001 ;;; Scrolling
1003 (defgroup scrolling nil
1004 "Scrolling windows."
1005 :version "21.1"
1006 :group 'frames)
1008 (defcustom automatic-hscrolling t
1009 "*Allow or disallow autmatic scrolling windows horizontally.
1010 If non-nil, windows are automatically scrolled horizontally to make
1011 point visible."
1012 :version "21.1"
1013 :type 'boolean
1014 :group 'scrolling)
1017 ;;; Blinking cursor
1019 (defgroup cursor nil
1020 "Displaying text cursors."
1021 :version "21.1"
1022 :group 'frames)
1024 (defcustom blink-cursor-delay 0.5
1025 "*Seconds of idle time after which cursor starts to blink."
1026 :tag "Delay in seconds."
1027 :type 'number
1028 :group 'cursor)
1030 (defcustom blink-cursor-interval 0.5
1031 "*Length of cursor blink interval in seconds."
1032 :tag "Blink interval in seconds."
1033 :type 'number
1034 :group 'cursor)
1036 (defvar blink-cursor-idle-timer nil
1037 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
1038 The function `blink-cursor-start' is called when the timer fires.")
1040 (defvar blink-cursor-timer nil
1041 "Timer started from `blink-cursor-start'.
1042 This timer calls `blink-cursor' every `blink-cursor-interval' seconds.")
1044 (defvar blink-cursor-mode nil
1045 "Non-nil means blinking cursor is active.")
1047 (defun blink-cursor-mode (arg)
1048 "Toggle blinking cursor mode.
1049 With arg, turn blinking cursor mode on iff arg is positive.
1050 When blinking cursor mode is enabled, the cursor of the selected
1051 window blinks."
1052 (interactive "P")
1053 (let ((on-p (if (null arg)
1054 (not blink-cursor-mode)
1055 (> (prefix-numeric-value arg) 0))))
1056 (if blink-cursor-idle-timer
1057 (cancel-timer blink-cursor-idle-timer))
1058 (if blink-cursor-timer
1059 (cancel-timer blink-cursor-timer))
1060 (setq blink-cursor-idle-timer nil
1061 blink-cursor-timer nil
1062 blink-cursor-mode nil)
1063 (if on-p
1064 (progn
1065 ;; Hide the cursor.
1066 ;(internal-show-cursor nil nil)
1067 (setq blink-cursor-idle-timer
1068 (run-with-idle-timer blink-cursor-delay
1069 blink-cursor-delay
1070 'blink-cursor-start))
1071 (setq blink-cursor-mode t))
1072 (internal-show-cursor nil t))))
1074 ;; Note that this is really initialized from startup.el before
1075 ;; the init-file is read.
1077 (defcustom blink-cursor nil
1078 "*Non-nil means blinking cursor mode is active."
1079 :group 'cursor
1080 :tag "Blinking cursor"
1081 :type 'boolean
1082 :set #'(lambda (symbol value)
1083 (set-default symbol value)
1084 (blink-cursor-mode (or value 0))))
1086 (defun blink-cursor-start ()
1087 "Timer function called from the timer `blink-cursor-idle-timer'.
1088 This starts the timer `blink-cursor-timer', which makes the cursor blink
1089 if appropriate. It also arranges to cancel that timer when the next
1090 command starts, by installing a pre-command hook."
1091 (when (null blink-cursor-timer)
1092 (add-hook 'pre-command-hook 'blink-cursor-end)
1093 (setq blink-cursor-timer
1094 (run-with-timer blink-cursor-interval blink-cursor-interval
1095 'blink-cursor-timer-function))))
1097 (defun blink-cursor-timer-function ()
1098 "Timer function of timer `blink-cursor-timer'."
1099 (internal-show-cursor nil (not (internal-show-cursor-p))))
1101 (defun blink-cursor-end ()
1102 "Stop cursor blinking.
1103 This is installed as a pre-command hook by `blink-cursor-start'.
1104 When run, it cancels the timer `blink-cursor-timer' and removes
1105 itself as a pre-command hook."
1106 (remove-hook 'pre-command-hook 'blink-cursor-end)
1107 (internal-show-cursor nil t)
1108 (cancel-timer blink-cursor-timer)
1109 (setq blink-cursor-timer nil))
1113 ;;; Busy-cursor.
1115 (defcustom busy-cursor t
1116 "*Non-nil means show a busy-cursor when running under a window system."
1117 :tag "Busy-cursor"
1118 :type 'boolean
1119 :group 'cursor
1120 :get #'(lambda (symbol) display-busy-cursor)
1121 :set #'(lambda (symbol value)
1122 (set-default symbol value)
1123 (setq display-busy-cursor value)))
1125 (defcustom busy-cursor-delay-seconds 1
1126 "*Seconds to wait before displaying a busy-cursor."
1127 :tag "Busy-cursor delay"
1128 :type 'number
1129 :group 'cursor
1130 :get #'(lambda (symbol) busy-cursor-delay)
1131 :set #'(lambda (symbol value)
1132 (set-default symbol value)
1133 (setq busy-cursor-delay value)))
1136 (defcustom show-cursor-in-non-selected-windows t
1137 "*Non-nil means show a hollow box cursor in non-selected-windows.
1138 If nil, don't show a cursor except in the selected window."
1139 :tag "Cursor in non-selected windows"
1140 :type 'boolean
1141 :group 'cursor
1142 :get #'(lambda (symbol) cursor-in-non-selected-windows)
1143 :set #'(lambda (symbol value)
1144 (set-default symbol value)
1145 (setq cursor-in-non-selected-windows value)
1146 (force-mode-line-update t)))
1149 ;;;; Key bindings
1151 (define-key ctl-x-5-map "2" 'make-frame-command)
1152 (define-key ctl-x-5-map "1" 'delete-other-frames)
1153 (define-key ctl-x-5-map "0" 'delete-frame)
1154 (define-key ctl-x-5-map "o" 'other-frame)
1156 (provide 'frame)
1158 ;;; frame.el ends here
1159 (frame-notice-user-settings):