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