Fix initialization of the window-system variable.
[bpt/emacs.git] / lisp / frame.el
1 ;;; frame.el --- multi-frame management independent of window systems
2
3 ;; Copyright (C) 1993, 1994, 1996, 1997, 2000, 2001, 2003
4 ;; Free Software Foundation, Inc.
5
6 ;; Maintainer: FSF
7 ;; Keywords: internal
8
9 ;; This file is part of GNU Emacs.
10
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)
14 ;; any later version.
15
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.
20
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.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (defvar frame-creation-function-alist
31 (list (cons nil
32 (if (fboundp 'tty-create-frame-with-faces)
33 'tty-create-frame-with-faces
34 (function
35 (lambda (parameters)
36 (error "Can't create multiple frames without a window system"))))))
37 "Alist of window-system dependent functions to call to create a new frame.
38 The window system startup file should add its frame creation
39 function to this list, which should take an alist of parameters
40 as its argument.")
41
42 ;; The initial value given here used to ask for a minibuffer.
43 ;; But that's not necessary, because the default is to have one.
44 ;; By not specifying it here, we let an X resource specify it.
45 (defcustom initial-frame-alist nil
46 "*Alist of frame parameters for creating the initial X window frame.
47 You can set this in your `.emacs' file; for example,
48 (setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55)))
49 Parameters specified here supersede the values given in `default-frame-alist'.
50
51 If the value calls for a frame without a minibuffer, and you have not created
52 a minibuffer frame on your own, one is created according to
53 `minibuffer-frame-alist'.
54
55 You can specify geometry-related options for just the initial frame
56 by setting this variable in your `.emacs' file; however, they won't
57 take effect until Emacs reads `.emacs', which happens after first creating
58 the frame. If you want the frame to have the proper geometry as soon
59 as it appears, you need to use this three-step process:
60 * Specify X resources to give the geometry you want.
61 * Set `default-frame-alist' to override these options so that they
62 don't affect subsequent frames.
63 * Set `initial-frame-alist' in a way that matches the X resources,
64 to override what you put in `default-frame-alist'."
65 :type '(repeat (cons :format "%v"
66 (symbol :tag "Parameter")
67 (sexp :tag "Value")))
68 :group 'frames)
69
70 (defcustom minibuffer-frame-alist '((width . 80) (height . 2))
71 "*Alist of frame parameters for initially creating a minibuffer frame.
72 You can set this in your `.emacs' file; for example,
73 (setq minibuffer-frame-alist
74 '((top . 1) (left . 1) (width . 80) (height . 2)))
75 Parameters specified here supersede the values given in
76 `default-frame-alist', for a minibuffer frame."
77 :type '(repeat (cons :format "%v"
78 (symbol :tag "Parameter")
79 (sexp :tag "Value")))
80 :group 'frames)
81
82 (defcustom pop-up-frame-alist nil
83 "*Alist of frame parameters used when creating pop-up frames.
84 Pop-up frames are used for completions, help, and the like.
85 This variable can be set in your init file, like this:
86 (setq pop-up-frame-alist '((width . 80) (height . 20)))
87 These supersede the values given in `default-frame-alist',
88 for pop-up frames."
89 :type '(repeat (cons :format "%v"
90 (symbol :tag "Parameter")
91 (sexp :tag "Value")))
92 :group 'frames)
93
94 (setq pop-up-frame-function
95 ;; Using `function' here caused some sort of problem.
96 '(lambda ()
97 (make-frame pop-up-frame-alist)))
98
99 (defcustom special-display-frame-alist
100 '((height . 14) (width . 80) (unsplittable . t))
101 "*Alist of frame parameters used when creating special frames.
102 Special frames are used for buffers whose names are in
103 `special-display-buffer-names' and for buffers whose names match
104 one of the regular expressions in `special-display-regexps'.
105 This variable can be set in your init file, like this:
106 (setq special-display-frame-alist '((width . 80) (height . 20)))
107 These supersede the values given in `default-frame-alist'."
108 :type '(repeat (cons :format "%v"
109 (symbol :tag "Parameter")
110 (sexp :tag "Value")))
111 :group 'frames)
112
113 (defun special-display-popup-frame (buffer &optional args)
114 "Display BUFFER in its own frame, reusing an existing window if any.
115 Return the window chosen.
116 Currently we do not insist on selecting the window within its frame.
117 If ARGS is an alist, use it as a list of frame parameter specs.
118 If ARGS is a list whose car is a symbol,
119 use (car ARGS) as a function to do the work.
120 Pass it BUFFER as first arg, and (cdr ARGS) gives the rest of the args."
121 (if (and args (symbolp (car args)))
122 (apply (car args) buffer (cdr args))
123 (let ((window (get-buffer-window buffer t)))
124 (or
125 ;; If we have a window already, make it visible.
126 (when window
127 (let ((frame (window-frame window)))
128 (make-frame-visible frame)
129 (raise-frame frame)
130 window))
131 ;; Reuse the current window if the user requested it.
132 (when (cdr (assq 'same-window args))
133 (condition-case nil
134 (progn (switch-to-buffer buffer) (selected-window))
135 (error nil)))
136 ;; Stay on the same frame if requested.
137 (when (or (cdr (assq 'same-frame args)) (cdr (assq 'same-window args)))
138 (let* ((pop-up-frames nil) (pop-up-windows t)
139 special-display-regexps special-display-buffer-names
140 (window (display-buffer buffer)))
141 ;; (set-window-dedicated-p window t)
142 window))
143 ;; If no window yet, make one in a new frame.
144 (let ((frame (make-frame (append args special-display-frame-alist))))
145 (set-window-buffer (frame-selected-window frame) buffer)
146 (set-window-dedicated-p (frame-selected-window frame) t)
147 (frame-selected-window frame))))))
148
149 (defun handle-delete-frame (event)
150 "Handle delete-frame events from the X server."
151 (interactive "e")
152 (let ((frame (posn-window (event-start event)))
153 (i 0)
154 (tail (frame-list)))
155 (while tail
156 (and (frame-visible-p (car tail))
157 (not (eq (car tail) frame))
158 (setq i (1+ i)))
159 (setq tail (cdr tail)))
160 (if (> i 0)
161 (delete-frame frame t)
162 ;; Gildea@x.org says it is ok to ask questions before terminating.
163 (save-buffers-kill-emacs))))
164 \f
165 ;;;; Arrangement of frames at startup
166
167 ;; 1) Load the window system startup file from the lisp library and read the
168 ;; high-priority arguments (-q and the like). The window system startup
169 ;; file should create any frames specified in the window system defaults.
170 ;;
171 ;; 2) If no frames have been opened, we open an initial text frame.
172 ;;
173 ;; 3) Once the init file is done, we apply any newly set parameters
174 ;; in initial-frame-alist to the frame.
175
176 ;; These are now called explicitly at the proper times,
177 ;; since that is easier to understand.
178 ;; Actually using hooks within Emacs is bad for future maintenance. --rms.
179 ;; (add-hook 'before-init-hook 'frame-initialize)
180 ;; (add-hook 'window-setup-hook 'frame-notice-user-settings)
181
182 ;; If we create the initial frame, this is it.
183 (defvar frame-initial-frame nil)
184
185 ;; Record the parameters used in frame-initialize to make the initial frame.
186 (defvar frame-initial-frame-alist)
187
188 (defvar frame-initial-geometry-arguments nil)
189
190 ;; startup.el calls this function before loading the user's init
191 ;; file - if there is no frame with a minibuffer open now, create
192 ;; one to display messages while loading the init file.
193 (defun frame-initialize ()
194 "Create an initial frame if necessary."
195 ;; Are we actually running under a window system at all?
196 (if (and initial-window-system
197 (not noninteractive)
198 (not (eq initial-window-system 'pc)))
199 (progn
200 ;; Turn on special-display processing only if there's a window system.
201 (setq special-display-function 'special-display-popup-frame)
202
203 ;; If there is no frame with a minibuffer besides the terminal
204 ;; frame, then we need to create the opening frame. Make sure
205 ;; it has a minibuffer, but let initial-frame-alist omit the
206 ;; minibuffer spec.
207 (or (delq terminal-frame (minibuffer-frame-list))
208 (progn
209 (setq frame-initial-frame-alist
210 (append initial-frame-alist default-frame-alist nil))
211 (or (assq 'horizontal-scroll-bars frame-initial-frame-alist)
212 (setq frame-initial-frame-alist
213 (cons '(horizontal-scroll-bars . t)
214 frame-initial-frame-alist)))
215 (setq frame-initial-frame-alist
216 (cons (cons 'window-system initial-window-system)
217 frame-initial-frame-alist))
218 (setq default-minibuffer-frame
219 (setq frame-initial-frame
220 (make-frame frame-initial-frame-alist)))
221 ;; Delete any specifications for window geometry parameters
222 ;; so that we won't reapply them in frame-notice-user-settings.
223 ;; It would be wrong to reapply them then,
224 ;; because that would override explicit user resizing.
225 (setq initial-frame-alist
226 (frame-remove-geometry-params initial-frame-alist))))
227 ;; At this point, we know that we have a frame open, so we
228 ;; can delete the terminal frame.
229 (delete-frame terminal-frame)
230 (setq terminal-frame nil))))
231
232 (defvar frame-notice-user-settings t
233 "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
234
235 ;; startup.el calls this function after loading the user's init
236 ;; file. Now default-frame-alist and initial-frame-alist contain
237 ;; information to which we must react; do what needs to be done.
238 (defun frame-notice-user-settings ()
239 "Act on user's init file settings of frame parameters.
240 React to settings of `default-frame-alist', `initial-frame-alist' there."
241 ;; Make menu-bar-mode and default-frame-alist consistent.
242 (when (boundp 'menu-bar-mode)
243 (let ((default (assq 'menu-bar-lines default-frame-alist)))
244 (if default
245 (setq menu-bar-mode (not (eq (cdr default) 0)))
246 (setq default-frame-alist
247 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
248 default-frame-alist)))))
249
250 ;; Make tool-bar-mode and default-frame-alist consistent. Don't do
251 ;; it in batch mode since that would leave a tool-bar-lines
252 ;; parameter in default-frame-alist in a dumped Emacs, which is not
253 ;; what we want.
254 (when (and (boundp 'tool-bar-mode)
255 (not noninteractive))
256 (let ((default (assq 'tool-bar-lines default-frame-alist)))
257 (if default
258 (setq tool-bar-mode (not (eq (cdr default) 0)))
259 (setq default-frame-alist
260 (cons (cons 'tool-bar-lines (if tool-bar-mode 1 0))
261 default-frame-alist)))))
262
263 ;; Creating and deleting frames may shift the selected frame around,
264 ;; and thus the current buffer. Protect against that. We don't
265 ;; want to use save-excursion here, because that may also try to set
266 ;; the buffer of the selected window, which fails when the selected
267 ;; window is the minibuffer.
268 (let ((old-buffer (current-buffer)))
269
270 (when (and frame-notice-user-settings
271 (null frame-initial-frame))
272 ;; This case happens when we don't have a window system, and
273 ;; also for MS-DOS frames.
274 (let ((parms (frame-parameters frame-initial-frame)))
275 ;; Don't change the frame names.
276 (setq parms (delq (assq 'name parms) parms))
277 ;; Can't modify the minibuffer parameter, so don't try.
278 (setq parms (delq (assq 'minibuffer parms) parms))
279 (modify-frame-parameters nil
280 (if (null initial-window-system)
281 (append initial-frame-alist
282 default-frame-alist
283 parms
284 nil)
285 ;; initial-frame-alist and
286 ;; default-frame-alist were already
287 ;; applied in pc-win.el.
288 parms))
289 (if (null initial-window-system) ;; MS-DOS does this differently in pc-win.el
290 (let ((newparms (frame-parameters))
291 (frame (selected-frame)))
292 (tty-handle-reverse-video frame newparms)
293 ;; If we changed the background color, we need to update
294 ;; the background-mode parameter, and maybe some faces,
295 ;; too.
296 (when (assq 'background-color newparms)
297 (unless (or (assq 'background-mode initial-frame-alist)
298 (assq 'background-mode default-frame-alist))
299 (frame-set-background-mode frame))
300 (face-set-after-frame-default frame))))))
301
302 ;; If the initial frame is still around, apply initial-frame-alist
303 ;; and default-frame-alist to it.
304 (when (frame-live-p frame-initial-frame)
305
306 ;; When tool-bar has been switched off, correct the frame size
307 ;; by the lines added in x-create-frame for the tool-bar and
308 ;; switch `tool-bar-mode' off.
309 (when (display-graphic-p)
310 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
311 (assq 'tool-bar-lines default-frame-alist))))
312 (when (and tool-bar-originally-present
313 (or (null tool-bar-lines)
314 (null (cdr tool-bar-lines))
315 (eq 0 (cdr tool-bar-lines))))
316 (let* ((char-height (frame-char-height frame-initial-frame))
317 (image-height tool-bar-images-pixel-height)
318 (margin (cond ((and (consp tool-bar-button-margin)
319 (integerp (cdr tool-bar-button-margin))
320 (> tool-bar-button-margin 0))
321 (cdr tool-bar-button-margin))
322 ((and (integerp tool-bar-button-margin)
323 (> tool-bar-button-margin 0))
324 tool-bar-button-margin)
325 (t 0)))
326 (relief (if (and (integerp tool-bar-button-relief)
327 (> tool-bar-button-relief 0))
328 tool-bar-button-relief 3))
329 (lines (/ (+ image-height
330 (* 2 margin)
331 (* 2 relief)
332 (1- char-height))
333 char-height))
334 (height (frame-parameter frame-initial-frame 'height))
335 (newparms (list (cons 'height (- height lines))))
336 (initial-top (cdr (assq 'top
337 frame-initial-geometry-arguments)))
338 (top (frame-parameter frame-initial-frame 'top)))
339 (when (and (consp initial-top) (eq '- (car initial-top)))
340 (let ((adjusted-top
341 (cond ((and (consp top)
342 (eq '+ (car top)))
343 (list '+
344 (+ (cadr top)
345 (* lines char-height))))
346 ((and (consp top)
347 (eq '- (car top)))
348 (list '-
349 (- (cadr top)
350 (* lines char-height))))
351 (t (+ top (* lines char-height))))))
352 (setq newparms
353 (append newparms
354 `((top . ,adjusted-top))
355 nil))))
356 (modify-frame-parameters frame-initial-frame newparms)
357 (tool-bar-mode -1)))))
358
359 ;; The initial frame we create above always has a minibuffer.
360 ;; If the user wants to remove it, or make it a minibuffer-only
361 ;; frame, then we'll have to delete the current frame and make a
362 ;; new one; you can't remove or add a root window to/from an
363 ;; existing frame.
364 ;;
365 ;; NOTE: default-frame-alist was nil when we created the
366 ;; existing frame. We need to explicitly include
367 ;; default-frame-alist in the parameters of the screen we
368 ;; create here, so that its new value, gleaned from the user's
369 ;; .emacs file, will be applied to the existing screen.
370 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
371 (assq 'minibuffer default-frame-alist)
372 '(minibuffer . t)))
373 t))
374 ;; Create the new frame.
375 (let (parms new)
376 ;; If the frame isn't visible yet, wait till it is.
377 ;; If the user has to position the window,
378 ;; Emacs doesn't know its real position until
379 ;; the frame is seen to be visible.
380 (while (not (cdr (assq 'visibility
381 (frame-parameters frame-initial-frame))))
382 (sleep-for 1))
383 (setq parms (frame-parameters frame-initial-frame))
384
385 ;; Get rid of `name' unless it was specified explicitly before.
386 (or (assq 'name frame-initial-frame-alist)
387 (setq parms (delq (assq 'name parms) parms)))
388
389 (setq parms (append initial-frame-alist
390 default-frame-alist
391 parms
392 nil))
393
394 ;; Get rid of `reverse', because that was handled
395 ;; when we first made the frame.
396 (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
397
398 (if (assq 'height frame-initial-geometry-arguments)
399 (setq parms (assq-delete-all 'height parms)))
400 (if (assq 'width frame-initial-geometry-arguments)
401 (setq parms (assq-delete-all 'width parms)))
402 (if (assq 'left frame-initial-geometry-arguments)
403 (setq parms (assq-delete-all 'left parms)))
404 (if (assq 'top frame-initial-geometry-arguments)
405 (setq parms (assq-delete-all 'top parms)))
406 (setq new
407 (make-frame
408 ;; Use the geometry args that created the existing
409 ;; frame, rather than the parms we get for it.
410 (append frame-initial-geometry-arguments
411 '((user-size . t) (user-position . t))
412 parms)))
413 ;; The initial frame, which we are about to delete, may be
414 ;; the only frame with a minibuffer. If it is, create a
415 ;; new one.
416 (or (delq frame-initial-frame (minibuffer-frame-list))
417 (make-initial-minibuffer-frame nil))
418
419 ;; If the initial frame is serving as a surrogate
420 ;; minibuffer frame for any frames, we need to wean them
421 ;; onto a new frame. The default-minibuffer-frame
422 ;; variable must be handled similarly.
423 (let ((users-of-initial
424 (filtered-frame-list
425 (function (lambda (frame)
426 (and (not (eq frame frame-initial-frame))
427 (eq (window-frame
428 (minibuffer-window frame))
429 frame-initial-frame)))))))
430 (if (or users-of-initial
431 (eq default-minibuffer-frame frame-initial-frame))
432
433 ;; Choose an appropriate frame. Prefer frames which
434 ;; are only minibuffers.
435 (let* ((new-surrogate
436 (car
437 (or (filtered-frame-list
438 (function
439 (lambda (frame)
440 (eq (cdr (assq 'minibuffer
441 (frame-parameters frame)))
442 'only))))
443 (minibuffer-frame-list))))
444 (new-minibuffer (minibuffer-window new-surrogate)))
445
446 (if (eq default-minibuffer-frame frame-initial-frame)
447 (setq default-minibuffer-frame new-surrogate))
448
449 ;; Wean the frames using frame-initial-frame as
450 ;; their minibuffer frame.
451 (mapcar
452 (function
453 (lambda (frame)
454 (modify-frame-parameters
455 frame (list (cons 'minibuffer new-minibuffer)))))
456 users-of-initial))))
457
458 ;; Redirect events enqueued at this frame to the new frame.
459 ;; Is this a good idea?
460 (redirect-frame-focus frame-initial-frame new)
461
462 ;; Finally, get rid of the old frame.
463 (delete-frame frame-initial-frame t))
464
465 ;; Otherwise, we don't need all that rigamarole; just apply
466 ;; the new parameters.
467 (let (newparms allparms tail)
468 (setq allparms (append initial-frame-alist
469 default-frame-alist nil))
470 (if (assq 'height frame-initial-geometry-arguments)
471 (setq allparms (assq-delete-all 'height allparms)))
472 (if (assq 'width frame-initial-geometry-arguments)
473 (setq allparms (assq-delete-all 'width allparms)))
474 (if (assq 'left frame-initial-geometry-arguments)
475 (setq allparms (assq-delete-all 'left allparms)))
476 (if (assq 'top frame-initial-geometry-arguments)
477 (setq allparms (assq-delete-all 'top allparms)))
478 (setq tail allparms)
479 ;; Find just the parms that have changed since we first
480 ;; made this frame. Those are the ones actually set by
481 ;; the init file. For those parms whose values we already knew
482 ;; (such as those spec'd by command line options)
483 ;; it is undesirable to specify the parm again
484 ;; once the user has seen the frame and been able to alter it
485 ;; manually.
486 (while tail
487 (let (newval oldval)
488 (setq oldval (assq (car (car tail))
489 frame-initial-frame-alist))
490 (setq newval (cdr (assq (car (car tail)) allparms)))
491 (or (and oldval (eq (cdr oldval) newval))
492 (setq newparms
493 (cons (cons (car (car tail)) newval) newparms))))
494 (setq tail (cdr tail)))
495 (setq newparms (nreverse newparms))
496 (modify-frame-parameters frame-initial-frame
497 newparms)
498 ;; If we changed the background color,
499 ;; we need to update the background-mode parameter
500 ;; and maybe some faces too.
501 (when (assq 'background-color newparms)
502 (unless (assq 'background-mode newparms)
503 (frame-set-background-mode frame-initial-frame))
504 (face-set-after-frame-default frame-initial-frame)))))
505
506 ;; Restore the original buffer.
507 (set-buffer old-buffer)
508
509 ;; Make sure the initial frame can be GC'd if it is ever deleted.
510 ;; Make sure frame-notice-user-settings does nothing if called twice.
511 (setq frame-notice-user-settings nil)
512 (setq frame-initial-frame nil)))
513
514 (defun make-initial-minibuffer-frame (display)
515 (let ((parms (append minibuffer-frame-alist '((minibuffer . only)))))
516 (if display
517 (make-frame-on-display display parms)
518 (make-frame parms))))
519
520 ;;;; Creation of additional frames, and other frame miscellanea
521
522 (defun modify-all-frames-parameters (alist)
523 "modify all current and future frames parameters according to ALIST.
524 This changes `default-frame-alist' and possibly `initial-frame-alist'.
525 See help of `modify-frame-parameters' for more information."
526 (let (element) ;; temp
527 (dolist (frame (frame-list))
528 (modify-frame-parameters frame alist))
529
530 (dolist (pair alist) ;; conses to add/replace
531 ;; initial-frame-alist needs setting only when
532 ;; frame-notice-user-settings is true
533 (and frame-notice-user-settings
534 (setq element (assoc (car pair) initial-frame-alist))
535 (setq initial-frame-alist (delq element initial-frame-alist)))
536 (and (setq element (assoc (car pair) default-frame-alist))
537 (setq default-frame-alist (delq element default-frame-alist)))))
538 (and frame-notice-user-settings
539 (setq initial-frame-alist (append initial-frame-alist alist)))
540 (setq default-frame-alist (append default-frame-alist alist)))
541
542 (defun get-other-frame ()
543 "Return some frame other than the current frame.
544 Create one if necessary. Note that the minibuffer frame, if separate,
545 is not considered (see `next-frame')."
546 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
547 (make-frame)
548 (next-frame (selected-frame)))))
549 s))
550
551 (defun next-multiframe-window ()
552 "Select the next window, regardless of which frame it is on."
553 (interactive)
554 (select-window (next-window (selected-window)
555 (> (minibuffer-depth) 0)
556 t))
557 (select-frame-set-input-focus (selected-frame)))
558
559 (defun previous-multiframe-window ()
560 "Select the previous window, regardless of which frame it is on."
561 (interactive)
562 (select-window (previous-window (selected-window)
563 (> (minibuffer-depth) 0)
564 t))
565 (select-frame-set-input-focus (selected-frame)))
566
567 (defun make-frame-on-display (display &optional parameters)
568 "Make a frame on display DISPLAY.
569 The optional second argument PARAMETERS specifies additional frame parameters."
570 (interactive "sMake frame on display: ")
571 (or (string-match "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display)
572 (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
573 (load (concat term-file-prefix "x-win"))
574 (make-frame `((window-system . x) (display . ,display) . ,parameters)))
575
576 (defun make-frame-on-tty (device type &optional parameters)
577 "Make a frame on terminal DEVICE which is of type TYPE (e.g., \"xterm\").
578 The optional third argument PARAMETERS specifies additional frame parameters."
579 (interactive "fOpen frame on tty device: \nsTerminal type of %s: ")
580 (unless device
581 (error "Invalid terminal device"))
582 (unless type
583 (error "Invalid terminal type"))
584 (make-frame `((window-system . nil) (tty . ,device) (tty-type . ,type) . ,parameters)))
585
586 (defun make-frame-command ()
587 "Make a new frame, and select it if the terminal displays only one frame."
588 (interactive)
589 (if (and window-system (not (eq window-system 'pc)))
590 (make-frame)
591 (select-frame (make-frame))))
592
593 (defvar before-make-frame-hook nil
594 "Functions to run before a frame is created.")
595
596 (defvar after-make-frame-functions nil
597 "Functions to run after a frame is created.
598 The functions are run with one arg, the newly created frame.")
599
600 (defvar after-setting-font-hook nil
601 "Functions to run after a frame's font has been changed.")
602
603 ;; Alias, kept temporarily.
604 (defalias 'new-frame 'make-frame)
605 (make-obsolete 'new-frame 'make-frame "21.4")
606
607 (defun make-frame (&optional parameters)
608 "Return a newly created frame displaying the current buffer.
609 Optional argument PARAMETERS is an alist of parameters for the new frame.
610 Each element of PARAMETERS should have the form (NAME . VALUE), for example:
611
612 (name . STRING) The frame should be named STRING.
613
614 (width . NUMBER) The frame should be NUMBER characters in width.
615 (height . NUMBER) The frame should be NUMBER text lines high.
616
617 You cannot specify either `width' or `height', you must use neither or both.
618
619 (minibuffer . t) The frame should have a minibuffer.
620 (minibuffer . nil) The frame should have no minibuffer.
621 (minibuffer . only) The frame should contain only a minibuffer.
622 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
623
624 (window-system . nil) The frame should be displayed on a terminal device.
625 (window-system . x) The frame should be displayed in an X window.
626
627 Before the frame is created (via `frame-creation-function-alist'), functions on the
628 hook `before-make-frame-hook' are run. After the frame is created, functions
629 on `after-make-frame-functions' are run with one arg, the newly created frame."
630 (interactive)
631 (let* ((w (if (assq 'window-system parameters)
632 (cdr (assq 'window-system parameters))
633 window-system))
634 (frame-creation-function (cdr (assq w frame-creation-function-alist)))
635 frame)
636 (unless frame-creation-function
637 (error "Don't know how to create a frame on window system %s" w))
638 (run-hooks 'before-make-frame-hook)
639 (setq frame (funcall frame-creation-function parameters))
640 (run-hook-with-args 'after-make-frame-functions frame)
641 frame))
642
643 (defun filtered-frame-list (predicate)
644 "Return a list of all live frames which satisfy PREDICATE."
645 (let* ((frames (frame-list))
646 (list frames))
647 (while (consp frames)
648 (unless (funcall predicate (car frames))
649 (setcar frames nil))
650 (setq frames (cdr frames)))
651 (delq nil list)))
652
653 (defun minibuffer-frame-list ()
654 "Return a list of all frames with their own minibuffers."
655 (filtered-frame-list
656 (function (lambda (frame)
657 (eq frame (window-frame (minibuffer-window frame)))))))
658
659 (defun frames-on-display-list (&optional display)
660 "Return a list of all frames on DISPLAY.
661 DISPLAY is a name of a display, a string of the form HOST:SERVER.SCREEN.
662 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
663 (let* ((display (or display (frame-parameter nil 'display)))
664 (func #'(lambda (frame)
665 (equal (frame-parameter frame 'display) display))))
666 (filtered-frame-list func)))
667
668 (defun framep-on-display (&optional display)
669 "Return the type of frames on DISPLAY.
670 DISPLAY may be a display name or a frame. If it is a frame, its type is
671 returned.
672 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
673 All frames on a given display are of the same type."
674 (or (framep display)
675 (framep (car (frames-on-display-list display)))))
676
677 (defun frame-remove-geometry-params (param-list)
678 "Return the parameter list PARAM-LIST, but with geometry specs removed.
679 This deletes all bindings in PARAM-LIST for `top', `left', `width',
680 `height', `user-size' and `user-position' parameters.
681 Emacs uses this to avoid overriding explicit moves and resizings from
682 the user during startup."
683 (setq param-list (cons nil param-list))
684 (let ((tail param-list))
685 (while (consp (cdr tail))
686 (if (and (consp (car (cdr tail)))
687 (memq (car (car (cdr tail)))
688 '(height width top left user-position user-size)))
689 (progn
690 (setq frame-initial-geometry-arguments
691 (cons (car (cdr tail)) frame-initial-geometry-arguments))
692 (setcdr tail (cdr (cdr tail))))
693 (setq tail (cdr tail)))))
694 (setq frame-initial-geometry-arguments
695 (nreverse frame-initial-geometry-arguments))
696 (cdr param-list))
697
698 (defcustom focus-follows-mouse t
699 "*Non-nil if window system changes focus when you move the mouse.
700 You should set this variable to tell Emacs how your window manager
701 handles focus, since there is no way in general for Emacs to find out
702 automatically."
703 :type 'boolean
704 :group 'frames
705 :version "20.3")
706
707 (defun select-frame-set-input-focus (frame)
708 "Select FRAME, raise it, and set input focus, if possible."
709 (select-frame frame)
710 (raise-frame frame)
711 ;; Ensure, if possible, that frame gets input focus.
712 (cond ((eq (window-system frame) 'x)
713 (x-focus-frame frame))
714 ((eq (window-system frame) 'w32)
715 (w32-focus-frame frame)))
716 (cond (focus-follows-mouse
717 (set-mouse-position (selected-frame) (1- (frame-width)) 0))))
718
719 (defun other-frame (arg)
720 "Select the ARG'th different visible frame on current display, and raise it.
721 All frames are arranged in a cyclic order.
722 This command selects the frame ARG steps away in that order.
723 A negative ARG moves in the opposite order.
724
725 To make this command work properly, you must tell Emacs
726 how the system (or the window manager) generally handles
727 focus-switching between windows. If moving the mouse onto a window
728 selects it (gives it focus), set `focus-follows-mouse' to t.
729 Otherwise, that variable should be nil."
730 (interactive "p")
731 (let ((frame (selected-frame)))
732 (while (> arg 0)
733 (setq frame (next-frame frame))
734 (while (not (eq (frame-visible-p frame) t))
735 (setq frame (next-frame frame)))
736 (setq arg (1- arg)))
737 (while (< arg 0)
738 (setq frame (previous-frame frame))
739 (while (not (eq (frame-visible-p frame) t))
740 (setq frame (previous-frame frame)))
741 (setq arg (1+ arg)))
742 (select-frame-set-input-focus frame)))
743
744 (defun iconify-or-deiconify-frame ()
745 "Iconify the selected frame, or deiconify if it's currently an icon."
746 (interactive)
747 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
748 (iconify-frame)
749 (make-frame-visible)))
750
751 (defun make-frame-names-alist ()
752 (let* ((current-frame (selected-frame))
753 (falist
754 (cons
755 (cons (frame-parameter current-frame 'name) current-frame) nil))
756 (frame (next-frame nil t)))
757 (while (not (eq frame current-frame))
758 (progn
759 (setq falist (cons (cons (frame-parameter frame 'name) frame) falist))
760 (setq frame (next-frame frame t))))
761 falist))
762
763 (defvar frame-name-history nil)
764 (defun select-frame-by-name (name)
765 "Select the frame on the current terminal whose name is NAME and raise it.
766 If there is no frame by that name, signal an error."
767 (interactive
768 (let* ((frame-names-alist (make-frame-names-alist))
769 (default (car (car frame-names-alist)))
770 (input (completing-read
771 (format "Select Frame (default %s): " default)
772 frame-names-alist nil t nil 'frame-name-history)))
773 (if (= (length input) 0)
774 (list default)
775 (list input))))
776 (let* ((frame-names-alist (make-frame-names-alist))
777 (frame (cdr (assoc name frame-names-alist))))
778 (or frame
779 (error "There is no frame named `%s'" name))
780 (make-frame-visible frame)
781 (raise-frame frame)
782 (select-frame frame)
783 ;; Ensure, if possible, that frame gets input focus.
784 (cond ((eq (window-system frame) 'x)
785 (x-focus-frame frame))
786 ((eq (window-system frame) 'w32)
787 (w32-focus-frame frame)))
788 (when focus-follows-mouse
789 (set-mouse-position frame (1- (frame-width frame)) 0))))
790 \f
791 ;;;; Frame configurations
792
793 (defun current-frame-configuration ()
794 "Return a list describing the positions and states of all frames.
795 Its car is `frame-configuration'.
796 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
797 where
798 FRAME is a frame object,
799 ALIST is an association list specifying some of FRAME's parameters, and
800 WINDOW-CONFIG is a window configuration object for FRAME."
801 (cons 'frame-configuration
802 (mapcar (function
803 (lambda (frame)
804 (list frame
805 (frame-parameters frame)
806 (current-window-configuration frame))))
807 (frame-list))))
808
809 (defun set-frame-configuration (configuration &optional nodelete)
810 "Restore the frames to the state described by CONFIGURATION.
811 Each frame listed in CONFIGURATION has its position, size, window
812 configuration, and other parameters set as specified in CONFIGURATION.
813 Ordinarily, this function deletes all existing frames not
814 listed in CONFIGURATION. But if optional second argument NODELETE
815 is given and non-nil, the unwanted frames are iconified instead."
816 (or (frame-configuration-p configuration)
817 (signal 'wrong-type-argument
818 (list 'frame-configuration-p configuration)))
819 (let ((config-alist (cdr configuration))
820 frames-to-delete)
821 (mapcar (function
822 (lambda (frame)
823 (let ((parameters (assq frame config-alist)))
824 (if parameters
825 (progn
826 (modify-frame-parameters
827 frame
828 ;; Since we can't set a frame's minibuffer status,
829 ;; we might as well omit the parameter altogether.
830 (let* ((parms (nth 1 parameters))
831 (mini (assq 'minibuffer parms)))
832 (if mini (setq parms (delq mini parms)))
833 parms))
834 (set-window-configuration (nth 2 parameters)))
835 (setq frames-to-delete (cons frame frames-to-delete))))))
836 (frame-list))
837 (if nodelete
838 ;; Note: making frames invisible here was tried
839 ;; but led to some strange behavior--each time the frame
840 ;; was made visible again, the window manager asked afresh
841 ;; for where to put it.
842 (mapcar 'iconify-frame frames-to-delete)
843 (mapcar 'delete-frame frames-to-delete))))
844 \f
845 ;;;; Convenience functions for accessing and interactively changing
846 ;;;; frame parameters.
847
848 (defun frame-height (&optional frame)
849 "Return number of lines available for display on FRAME.
850 If FRAME is omitted, describe the currently selected frame."
851 (cdr (assq 'height (frame-parameters frame))))
852
853 (defun frame-width (&optional frame)
854 "Return number of columns available for display on FRAME.
855 If FRAME is omitted, describe the currently selected frame."
856 (cdr (assq 'width (frame-parameters frame))))
857
858 (defalias 'set-default-font 'set-frame-font)
859 (defun set-frame-font (font-name &optional keep-size)
860 "Set the font of the selected frame to FONT-NAME.
861 When called interactively, prompt for the name of the font to use.
862 To get the frame's current default font, use `frame-parameters'.
863
864 The default behavior is to keep the numbers of lines and columns in
865 the frame, thus may change its pixel size. If optional KEEP-SIZE is
866 non-nil (interactively, prefix argument) the current frame size (in
867 pixels) is kept by adjusting the numbers of the lines and columns."
868 (interactive
869 (let* ((completion-ignore-case t)
870 (font (completing-read "Font name: "
871 (mapcar #'list
872 ;; x-list-fonts will fail with an error
873 ;; if this frame doesn't support fonts.
874 (x-list-fonts "*" nil (selected-frame)))
875 nil nil nil nil
876 (frame-parameter nil 'font))))
877 (list font current-prefix-arg)))
878 (let (fht fwd)
879 (if keep-size
880 (setq fht (* (frame-parameter nil 'height) (frame-char-height))
881 fwd (* (frame-parameter nil 'width) (frame-char-width))))
882 (modify-frame-parameters (selected-frame)
883 (list (cons 'font font-name)))
884 (if keep-size
885 (modify-frame-parameters
886 (selected-frame)
887 (list (cons 'height (round fht (frame-char-height)))
888 (cons 'width (round fwd (frame-char-width)))))))
889 (run-hooks 'after-setting-font-hook 'after-setting-font-hooks))
890
891 (defun set-frame-parameter (frame parameter value)
892 (modify-frame-parameters frame (list (cons parameter value))))
893
894 (defun set-background-color (color-name)
895 "Set the background color of the selected frame to COLOR-NAME.
896 When called interactively, prompt for the name of the color to use.
897 To get the frame's current background color, use `frame-parameters'."
898 (interactive (list (facemenu-read-color)))
899 (modify-frame-parameters (selected-frame)
900 (list (cons 'background-color color-name)))
901 (or window-system
902 (face-set-after-frame-default (selected-frame))))
903
904 (defun set-foreground-color (color-name)
905 "Set the foreground color of the selected frame to COLOR-NAME.
906 When called interactively, prompt for the name of the color to use.
907 To get the frame's current foreground color, use `frame-parameters'."
908 (interactive (list (facemenu-read-color)))
909 (modify-frame-parameters (selected-frame)
910 (list (cons 'foreground-color color-name)))
911 (or window-system
912 (face-set-after-frame-default (selected-frame))))
913
914 (defun set-cursor-color (color-name)
915 "Set the text cursor color of the selected frame to COLOR-NAME.
916 When called interactively, prompt for the name of the color to use.
917 To get the frame's current cursor color, use `frame-parameters'."
918 (interactive (list (facemenu-read-color)))
919 (modify-frame-parameters (selected-frame)
920 (list (cons 'cursor-color color-name))))
921
922 (defun set-mouse-color (color-name)
923 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
924 When called interactively, prompt for the name of the color to use.
925 To get the frame's current mouse color, use `frame-parameters'."
926 (interactive (list (facemenu-read-color)))
927 (modify-frame-parameters (selected-frame)
928 (list (cons 'mouse-color
929 (or color-name
930 (cdr (assq 'mouse-color
931 (frame-parameters))))))))
932
933 (defun set-border-color (color-name)
934 "Set the color of the border of the selected frame to COLOR-NAME.
935 When called interactively, prompt for the name of the color to use.
936 To get the frame's current border color, use `frame-parameters'."
937 (interactive (list (facemenu-read-color)))
938 (modify-frame-parameters (selected-frame)
939 (list (cons 'border-color color-name))))
940
941 (defun auto-raise-mode (arg)
942 "Toggle whether or not the selected frame should auto-raise.
943 With arg, turn auto-raise mode on if and only if arg is positive.
944 Note that this controls Emacs's own auto-raise feature.
945 Some window managers allow you to enable auto-raise for certain windows.
946 You can use that for Emacs windows if you wish, but if you do,
947 that is beyond the control of Emacs and this command has no effect on it."
948 (interactive "P")
949 (if (null arg)
950 (setq arg
951 (if (cdr (assq 'auto-raise (frame-parameters (selected-frame))))
952 -1 1)))
953 (if (> arg 0)
954 (raise-frame (selected-frame)))
955 (modify-frame-parameters (selected-frame)
956 (list (cons 'auto-raise (> arg 0)))))
957
958 (defun auto-lower-mode (arg)
959 "Toggle whether or not the selected frame should auto-lower.
960 With arg, turn auto-lower mode on if and only if arg is positive.
961 Note that this controls Emacs's own auto-lower feature.
962 Some window managers allow you to enable auto-lower for certain windows.
963 You can use that for Emacs windows if you wish, but if you do,
964 that is beyond the control of Emacs and this command has no effect on it."
965 (interactive "P")
966 (if (null arg)
967 (setq arg
968 (if (cdr (assq 'auto-lower (frame-parameters (selected-frame))))
969 -1 1)))
970 (modify-frame-parameters (selected-frame)
971 (list (cons 'auto-lower (> arg 0)))))
972 (defun set-frame-name (name)
973 "Set the name of the selected frame to NAME.
974 When called interactively, prompt for the name of the frame.
975 The frame name is displayed on the modeline if the terminal displays only
976 one frame, otherwise the name is displayed on the frame's caption bar."
977 (interactive "sFrame name: ")
978 (modify-frame-parameters (selected-frame)
979 (list (cons 'name name))))
980
981 (defun frame-current-scroll-bars (&optional frame)
982 "Return the current scroll-bar settings in frame FRAME.
983 Value is a cons (VERTICAL . HORISONTAL) where VERTICAL specifies the
984 current location of the vertical scroll-bars (left, right, or nil),
985 and HORISONTAL specifies the current location of the horisontal scroll
986 bars (top, bottom, or nil)."
987 (let ((vert (frame-parameter frame 'vertical-scroll-bars))
988 (hor nil))
989 (unless (memq vert '(left right nil))
990 (setq vert default-frame-scroll-bars))
991 (cons vert hor)))
992 \f
993 ;;;; Frame/display capabilities.
994 (defun display-mouse-p (&optional display)
995 "Return non-nil if DISPLAY has a mouse available.
996 DISPLAY can be a display name, a frame, or nil (meaning the selected
997 frame's display)."
998 (let ((frame-type (framep-on-display display)))
999 (cond
1000 ((eq frame-type 'pc)
1001 (msdos-mouse-p))
1002 ((eq system-type 'windows-nt)
1003 (> w32-num-mouse-buttons 0))
1004 ((memq frame-type '(x mac))
1005 t) ;; We assume X and Mac *always* have a pointing device
1006 (t
1007 (or (and (featurep 'xt-mouse)
1008 xterm-mouse-mode)
1009 ;; t-mouse is distributed with the GPM package. It doesn't have
1010 ;; a toggle.
1011 (featurep 't-mouse))))))
1012
1013 (defun display-popup-menus-p (&optional display)
1014 "Return non-nil if popup menus are supported on DISPLAY.
1015 DISPLAY can be a display name, a frame, or nil (meaning the selected
1016 frame's display).
1017 Support for popup menus requires that the mouse be available."
1018 (and
1019 (let ((frame-type (framep-on-display display)))
1020 (memq frame-type '(x w32 pc mac)))
1021 (display-mouse-p display)))
1022
1023 (defun display-graphic-p (&optional display)
1024 "Return non-nil if DISPLAY is a graphic display.
1025 Graphical displays are those which are capable of displaying several
1026 frames and several different fonts at once. This is true for displays
1027 that use a window system such as X, and false for text-only terminals.
1028 DISPLAY can be a display name, a frame, or nil (meaning the selected
1029 frame's display)."
1030 (not (null (memq (framep-on-display display) '(x w32 mac)))))
1031
1032 (defun display-images-p (&optional display)
1033 "Return non-nil if DISPLAY can display images.
1034
1035 DISPLAY can be a display name, a frame, or nil (meaning the selected
1036 frame's display)."
1037 (and (display-graphic-p display)
1038 (fboundp 'image-mask-p)
1039 (fboundp 'image-size)))
1040
1041 (defalias 'display-multi-frame-p 'display-graphic-p)
1042 (defalias 'display-multi-font-p 'display-graphic-p)
1043
1044 (defun display-selections-p (&optional display)
1045 "Return non-nil if DISPLAY supports selections.
1046 A selection is a way to transfer text or other data between programs
1047 via special system buffers called `selection' or `cut buffer' or
1048 `clipboard'.
1049 DISPLAY can be a display name, a frame, or nil (meaning the selected
1050 frame's display)."
1051 (let ((frame-type (framep-on-display display)))
1052 (cond
1053 ((eq frame-type 'pc)
1054 ;; MS-DOG frames support selections when Emacs runs inside
1055 ;; the Windows' DOS Box.
1056 (not (null dos-windows-version)))
1057 ((memq frame-type '(x w32 mac))
1058 t) ;; FIXME?
1059 (t
1060 nil))))
1061
1062 (defun display-screens (&optional display)
1063 "Return the number of screens associated with DISPLAY."
1064 (let ((frame-type (framep-on-display display)))
1065 (cond
1066 ((memq frame-type '(x w32))
1067 (x-display-screens display))
1068 (t ;; FIXME: is this correct for the Mac?
1069 1))))
1070
1071 (defun display-pixel-height (&optional display)
1072 "Return the height of DISPLAY's screen in pixels.
1073 For character terminals, each character counts as a single pixel."
1074 (let ((frame-type (framep-on-display display)))
1075 (cond
1076 ((memq frame-type '(x w32 mac))
1077 (x-display-pixel-height display))
1078 (t
1079 (frame-height (if (framep display) display (selected-frame)))))))
1080
1081 (defun display-pixel-width (&optional display)
1082 "Return the width of DISPLAY's screen in pixels.
1083 For character terminals, each character counts as a single pixel."
1084 (let ((frame-type (framep-on-display display)))
1085 (cond
1086 ((memq frame-type '(x w32 mac))
1087 (x-display-pixel-width display))
1088 (t
1089 (frame-width (if (framep display) display (selected-frame)))))))
1090
1091 (defun display-mm-height (&optional display)
1092 "Return the height of DISPLAY's screen in millimeters.
1093 If the information is unavailable, value is nil."
1094 (and (memq (framep-on-display display) '(x w32 mac))
1095 (x-display-mm-height display)))
1096
1097 (defun display-mm-width (&optional display)
1098 "Return the width of DISPLAY's screen in millimeters.
1099 If the information is unavailable, value is nil."
1100 (and (memq (framep-on-display display) '(x w32 mac))
1101 (x-display-mm-width display)))
1102
1103 (defun display-backing-store (&optional display)
1104 "Return the backing store capability of DISPLAY's screen.
1105 The value may be `always', `when-mapped', `not-useful', or nil if
1106 the question is inapplicable to a certain kind of display."
1107 (let ((frame-type (framep-on-display display)))
1108 (cond
1109 ((memq frame-type '(x w32 mac))
1110 (x-display-backing-store display))
1111 (t
1112 'not-useful))))
1113
1114 (defun display-save-under (&optional display)
1115 "Return non-nil if DISPLAY's screen supports the SaveUnder feature."
1116 (let ((frame-type (framep-on-display display)))
1117 (cond
1118 ((memq frame-type '(x w32 mac))
1119 (x-display-save-under display))
1120 (t
1121 'not-useful))))
1122
1123 (defun display-planes (&optional display)
1124 "Return the number of planes supported by DISPLAY."
1125 (let ((frame-type (framep-on-display display)))
1126 (cond
1127 ((memq frame-type '(x w32 mac))
1128 (x-display-planes display))
1129 ((eq frame-type 'pc)
1130 4)
1131 (t
1132 (truncate (log (length (tty-color-alist)) 2))))))
1133
1134 (defun display-color-cells (&optional display)
1135 "Return the number of color cells supported by DISPLAY."
1136 (let ((frame-type (framep-on-display display)))
1137 (cond
1138 ((memq frame-type '(x w32 mac))
1139 (x-display-color-cells display))
1140 ((eq frame-type 'pc)
1141 16)
1142 (t
1143 (tty-display-color-cells display)))))
1144
1145 (defun display-visual-class (&optional display)
1146 "Returns the visual class of DISPLAY.
1147 The value is one of the symbols `static-gray', `gray-scale',
1148 `static-color', `pseudo-color', `true-color', or `direct-color'."
1149 (let ((frame-type (framep-on-display display)))
1150 (cond
1151 ((memq frame-type '(x w32 mac))
1152 (x-display-visual-class display))
1153 ((and (memq frame-type '(pc t))
1154 (tty-display-color-p display))
1155 'static-color)
1156 (t
1157 'static-gray))))
1158
1159 \f
1160 ;;;; Aliases for backward compatibility with Emacs 18.
1161 (defalias 'screen-height 'frame-height)
1162 (defalias 'screen-width 'frame-width)
1163
1164 (defun set-screen-width (cols &optional pretend)
1165 "Obsolete function to change the size of the screen to COLS columns.
1166 Optional second arg non-nil means that redisplay should use COLS columns
1167 but that the idea of the actual width of the frame should not be changed.
1168 This function is provided only for compatibility with Emacs 18; new code
1169 should use `set-frame-width instead'."
1170 (set-frame-width (selected-frame) cols pretend))
1171
1172 (defun set-screen-height (lines &optional pretend)
1173 "Obsolete function to change the height of the screen to LINES lines.
1174 Optional second arg non-nil means that redisplay should use LINES lines
1175 but that the idea of the actual height of the screen should not be changed.
1176 This function is provided only for compatibility with Emacs 18; new code
1177 should use `set-frame-height' instead."
1178 (set-frame-height (selected-frame) lines pretend))
1179
1180 (defun delete-other-frames (&optional frame)
1181 "Delete all frames except FRAME.
1182 If FRAME uses another frame's minibuffer, the minibuffer frame is
1183 left untouched. FRAME nil or omitted means use the selected frame."
1184 (interactive)
1185 (unless frame
1186 (setq frame (selected-frame)))
1187 (let* ((mini-frame (window-frame (minibuffer-window frame)))
1188 (frames (delq mini-frame (delq frame (frame-list)))))
1189 ;; Delete mon-minibuffer-only frames first, because `delete-frame'
1190 ;; signals an error when trying to delete a mini-frame that's
1191 ;; still in use by another frame.
1192 (dolist (frame frames)
1193 (unless (eq (frame-parameter frame 'minibuffer) 'only)
1194 (delete-frame frame)))
1195 ;; Delete minibuffer-only frames.
1196 (dolist (frame frames)
1197 (when (eq (frame-parameter frame 'minibuffer) 'only)
1198 (delete-frame frame)))))
1199
1200 (make-obsolete 'screen-height 'frame-height) ;before 19.15
1201 (make-obsolete 'screen-width 'frame-width) ;before 19.15
1202 (make-obsolete 'set-screen-width 'set-frame-width) ;before 19.15
1203 (make-obsolete 'set-screen-height 'set-frame-height) ;before 19.15
1204
1205 ;; miscellaneous obsolescence declarations
1206 (defvaralias 'delete-frame-hook 'delete-frame-functions)
1207 (make-obsolete-variable 'delete-frame-hook 'delete-frame-functions "21.4")
1208
1209 \f
1210 ;; Highlighting trailing whitespace.
1211
1212 (make-variable-buffer-local 'show-trailing-whitespace)
1213
1214 (defcustom show-trailing-whitespace nil
1215 "*Non-nil means highlight trailing whitespace in face `trailing-whitespace'.
1216
1217 Setting this variable makes it local to the current buffer."
1218 :tag "Highlight trailing whitespace."
1219 :type 'boolean
1220 :group 'font-lock)
1221
1222
1223 \f
1224 ;; Scrolling
1225
1226 (defgroup scrolling nil
1227 "Scrolling windows."
1228 :version "21.1"
1229 :group 'frames)
1230
1231 (defcustom auto-hscroll-mode t
1232 "*Allow or disallow automatic scrolling windows horizontally.
1233 If non-nil, windows are automatically scrolled horizontally to make
1234 point visible."
1235 :version "21.1"
1236 :type 'boolean
1237 :group 'scrolling)
1238 (defvaralias 'automatic-hscrolling 'auto-hscroll-mode)
1239
1240 \f
1241 ;; Blinking cursor
1242
1243 (defgroup cursor nil
1244 "Displaying text cursors."
1245 :version "21.1"
1246 :group 'frames)
1247
1248 (defcustom blink-cursor-delay 0.5
1249 "*Seconds of idle time after which cursor starts to blink."
1250 :tag "Delay in seconds."
1251 :type 'number
1252 :group 'cursor)
1253
1254 (defcustom blink-cursor-interval 0.5
1255 "*Length of cursor blink interval in seconds."
1256 :tag "Blink interval in seconds."
1257 :type 'number
1258 :group 'cursor)
1259
1260 (defvar blink-cursor-idle-timer nil
1261 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
1262 The function `blink-cursor-start' is called when the timer fires.")
1263
1264 (defvar blink-cursor-timer nil
1265 "Timer started from `blink-cursor-start'.
1266 This timer calls `blink-cursor' every `blink-cursor-interval' seconds.")
1267
1268 (defvar blink-cursor-mode nil
1269 "Non-nil means blinking cursor is active.")
1270
1271 (defun blink-cursor-mode (arg)
1272 "Toggle blinking cursor mode.
1273 With a numeric argument, turn blinking cursor mode on iff ARG is positive.
1274 When blinking cursor mode is enabled, the cursor of the selected
1275 window blinks.
1276
1277 Note that this command is effective only when Emacs
1278 displays through a window system, because then Emacs does its own
1279 cursor display. On a text-only terminal, this is not implemented."
1280 (interactive "P")
1281 (let ((on-p (if (null arg)
1282 (not blink-cursor-mode)
1283 (> (prefix-numeric-value arg) 0))))
1284 (if blink-cursor-idle-timer
1285 (cancel-timer blink-cursor-idle-timer))
1286 (if blink-cursor-timer
1287 (cancel-timer blink-cursor-timer))
1288 (setq blink-cursor-idle-timer nil
1289 blink-cursor-timer nil
1290 blink-cursor-mode nil)
1291 (if on-p
1292 (progn
1293 ;; Hide the cursor.
1294 ;(internal-show-cursor nil nil)
1295 (setq blink-cursor-idle-timer
1296 (run-with-idle-timer blink-cursor-delay
1297 blink-cursor-delay
1298 'blink-cursor-start))
1299 (setq blink-cursor-mode t))
1300 (internal-show-cursor nil t))))
1301
1302 ;; Note that this is really initialized from startup.el before
1303 ;; the init-file is read.
1304
1305 (defcustom blink-cursor nil
1306 "*Non-nil means blinking cursor mode is active."
1307 :group 'cursor
1308 :tag "Blinking cursor"
1309 :type 'boolean
1310 :set #'(lambda (symbol value)
1311 (set-default symbol value)
1312 (blink-cursor-mode (or value 0))))
1313
1314 (defun blink-cursor-start ()
1315 "Timer function called from the timer `blink-cursor-idle-timer'.
1316 This starts the timer `blink-cursor-timer', which makes the cursor blink
1317 if appropriate. It also arranges to cancel that timer when the next
1318 command starts, by installing a pre-command hook."
1319 (when (null blink-cursor-timer)
1320 (add-hook 'pre-command-hook 'blink-cursor-end)
1321 (setq blink-cursor-timer
1322 (run-with-timer blink-cursor-interval blink-cursor-interval
1323 'blink-cursor-timer-function))))
1324
1325 (defun blink-cursor-timer-function ()
1326 "Timer function of timer `blink-cursor-timer'."
1327 (internal-show-cursor nil (not (internal-show-cursor-p))))
1328
1329 (defun blink-cursor-end ()
1330 "Stop cursor blinking.
1331 This is installed as a pre-command hook by `blink-cursor-start'.
1332 When run, it cancels the timer `blink-cursor-timer' and removes
1333 itself as a pre-command hook."
1334 (remove-hook 'pre-command-hook 'blink-cursor-end)
1335 (internal-show-cursor nil t)
1336 (cancel-timer blink-cursor-timer)
1337 (setq blink-cursor-timer nil))
1338
1339
1340 \f
1341 ;; Hourglass pointer
1342
1343 (defcustom display-hourglass t
1344 "*Non-nil means show an hourglass pointer when running under a window system."
1345 :tag "Hourglass pointer"
1346 :type 'boolean
1347 :group 'cursor)
1348
1349 (defcustom hourglass-delay 1
1350 "*Seconds to wait before displaying an hourglass pointer."
1351 :tag "Hourglass delay"
1352 :type 'number
1353 :group 'cursor)
1354
1355 \f
1356 (defcustom cursor-in-non-selected-windows t
1357 "*Non-nil means show a hollow box cursor in non-selected-windows.
1358 If nil, don't show a cursor except in the selected window.
1359 Use Custom to set this variable to get the display updated."
1360 :tag "Cursor in non-selected windows"
1361 :type 'boolean
1362 :group 'cursor
1363 :set #'(lambda (symbol value)
1364 (set-default symbol value)
1365 (force-mode-line-update t)))
1366
1367 \f
1368 ;;;; Key bindings
1369
1370 (define-key ctl-x-5-map "2" 'make-frame-command)
1371 (define-key ctl-x-5-map "1" 'delete-other-frames)
1372 (define-key ctl-x-5-map "0" 'delete-frame)
1373 (define-key ctl-x-5-map "o" 'other-frame)
1374
1375 (provide 'frame)
1376
1377 ;;; arch-tag: 82979c70-b8f2-4306-b2ad-ddbd6b328b56
1378 ;;; frame.el ends here