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