merge trunk
[bpt/emacs.git] / lisp / frame.el
CommitLineData
55535639 1;;; frame.el --- multi-frame management independent of window systems
c88ab9ce 2
0d30b337 3;; Copyright (C) 1993, 1994, 1996, 1997, 2000, 2001, 2002, 2003,
114f9c96 4;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
3a801d0c 5
fc68affa 6;; Maintainer: FSF
fd7fa35a 7;; Keywords: internal
bd78fa1d 8;; Package: emacs
fc68affa 9
b578f267
EN
10;; This file is part of GNU Emacs.
11
eb3fa2cf 12;; GNU Emacs is free software: you can redistribute it and/or modify
b578f267 13;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
b578f267
EN
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
eb3fa2cf 23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
64c669bc 24
55535639
PJ
25;;; Commentary:
26
fc68affa 27;;; Code:
f44379e7 28(eval-when-compile (require 'cl))
fc68affa 29
2246281f
KL
30(defvar frame-creation-function-alist
31 (list (cons nil
32 (if (fboundp 'tty-create-frame-with-faces)
33 'tty-create-frame-with-faces
371fed4e
SM
34 (lambda (parameters)
35 (error "Can't create multiple frames without a window system")))))
2246281f
KL
36 "Alist of window-system dependent functions to call to create a new frame.
37The window system startup file should add its frame creation
38function to this list, which should take an alist of parameters
39as its argument.")
114a8b8c 40
bf1ba39f
KL
41(defvar window-system-default-frame-alist nil
42 "Alist of window-system dependent default frame parameters.
dca6c418
MR
43Parameters specified here supersede the values given in
44`default-frame-alist'.")
bf1ba39f 45
7e573c4a
SM
46;; The initial value given here used to ask for a minibuffer.
47;; But that's not necessary, because the default is to have one.
48;; By not specifying it here, we let an X resource specify it.
fac580eb 49(defcustom initial-frame-alist nil
dca6c418
MR
50 "Alist of parameters for the initial X window frame.
51You can set this in your init file; for example,
52
53 (setq initial-frame-alist
54 '((top . 1) (left . 1) (width . 80) (height . 55)))
55
56Parameters specified here supersede the values given in
57`default-frame-alist'.
58
59If the value calls for a frame without a minibuffer, and you have
60not created a minibuffer frame on your own, a minibuffer frame is
61created according to `minibuffer-frame-alist'.
62
63You can specify geometry-related options for just the initial
64frame by setting this variable in your init file; however, they
65won't take effect until Emacs reads your init file, which happens
66after creating the initial frame. If you want the initial frame
67to have the proper geometry as soon as it appears, you need to
68use this three-step process:
de17da15
RS
69* Specify X resources to give the geometry you want.
70* Set `default-frame-alist' to override these options so that they
71 don't affect subsequent frames.
72* Set `initial-frame-alist' in a way that matches the X resources,
0c966f88
RS
73 to override what you put in `default-frame-alist'."
74 :type '(repeat (cons :format "%v"
75 (symbol :tag "Parameter")
76 (sexp :tag "Value")))
77 :group 'frames)
64c669bc 78
0b9d32af 79(defcustom minibuffer-frame-alist '((width . 80) (height . 2))
92e02072
CY
80 "Alist of parameters for the initial minibuffer frame.
81This is the minibuffer frame created if `initial-frame-alist'
82calls for a frame without a minibuffer. The parameters specified
83here supersede those given in `default-frame-alist', for the
84initial minibuffer frame.
85
dca6c418
MR
86You can set this in your init file; for example,
87
dc6d9681 88 (setq minibuffer-frame-alist
dca6c418
MR
89 '((top . 1) (left . 1) (width . 80) (height . 2)))
90
92e02072
CY
91It is not necessary to include (minibuffer . only); that is
92appended when the minibuffer frame is created."
0b9d32af
RS
93 :type '(repeat (cons :format "%v"
94 (symbol :tag "Parameter")
95 (sexp :tag "Value")))
96 :group 'frames)
64c669bc 97
0b9d32af 98(defcustom pop-up-frame-alist nil
dca6c418
MR
99 "Alist of parameters for automatically generated new frames.
100You can set this in your init file; for example,
101
dc6d9681 102 (setq pop-up-frame-alist '((width . 80) (height . 20)))
dca6c418
MR
103
104If non-nil, the value you specify here is used by the default
105`pop-up-frame-function' for the creation of new frames.
106
107Since `pop-up-frame-function' is used by `display-buffer' for
60898913 108making new frames, any value specified here by default affects
dca6c418
MR
109the automatic generation of new frames via `display-buffer' and
110all functions based on it. The behavior of `make-frame' is not
111affected by this variable."
0b9d32af
RS
112 :type '(repeat (cons :format "%v"
113 (symbol :tag "Parameter")
114 (sexp :tag "Value")))
115 :group 'frames)
64c669bc 116
25831d66
MR
117(defcustom pop-up-frame-function
118 (lambda () (make-frame pop-up-frame-alist))
dca6c418
MR
119 "Function used by `display-buffer' for creating a new frame.
120This function is called with no arguments and should return a new
121frame. The default value calls `make-frame' with the argument
122`pop-up-frame-alist'."
36fc0932 123 :type 'function
25831d66 124 :group 'frames)
64c669bc 125
30e19aee 126(defcustom special-display-frame-alist
8a9e86e6 127 '((height . 14) (width . 80) (unsplittable . t))
dca6c418 128 "Alist of parameters for special frames.
60898913 129Special frames are used for buffers whose names are listed in
8a9e86e6
RS
130`special-display-buffer-names' and for buffers whose names match
131one of the regular expressions in `special-display-regexps'.
dca6c418 132
8a9e86e6 133This variable can be set in your init file, like this:
dca6c418 134
8a9e86e6 135 (setq special-display-frame-alist '((width . 80) (height . 20)))
dca6c418 136
30e19aee
RS
137These supersede the values given in `default-frame-alist'."
138 :type '(repeat (cons :format "%v"
139 (symbol :tag "Parameter")
140 (sexp :tag "Value")))
141 :group 'frames)
8a9e86e6 142
95e6cf39 143(defun special-display-popup-frame (buffer &optional args)
60898913
MR
144 "Display BUFFER and return the window chosen.
145If BUFFER is already displayed in a visible or iconified frame,
146raise that frame. Otherwise, display BUFFER in a new frame.
147
148Optional argument ARGS is a list specifying additional
149information.
150
151If ARGS is an alist, use it as a list of frame parameters. If
152these parameters contain \(same-window . t), display BUFFER in
153the selected window. If they contain \(same-frame . t), display
154BUFFER in a window of the selected frame.
155
156If ARGS is a list whose car is a symbol, use (car ARGS) as a
157function to do the work. Pass it BUFFER as first argument,
158and (cdr ARGS) as second."
95e6cf39
RS
159 (if (and args (symbolp (car args)))
160 (apply (car args) buffer (cdr args))
bb2c34b1 161 (let ((window (get-buffer-window buffer 0)))
7e573c4a
SM
162 (or
163 ;; If we have a window already, make it visible.
164 (when window
165 (let ((frame (window-frame window)))
166 (make-frame-visible frame)
167 (raise-frame frame)
168 window))
169 ;; Reuse the current window if the user requested it.
170 (when (cdr (assq 'same-window args))
171 (condition-case nil
172 (progn (switch-to-buffer buffer) (selected-window))
173 (error nil)))
174 ;; Stay on the same frame if requested.
175 (when (or (cdr (assq 'same-frame args)) (cdr (assq 'same-window args)))
60898913
MR
176 (let* ((pop-up-windows t)
177 pop-up-frames
178 special-display-buffer-names special-display-regexps)
179 (display-buffer buffer)))
7e573c4a 180 ;; If no window yet, make one in a new frame.
bf247b6e 181 (let ((frame
86bd482f
RS
182 (with-current-buffer buffer
183 (make-frame (append args special-display-frame-alist)))))
7e573c4a
SM
184 (set-window-buffer (frame-selected-window frame) buffer)
185 (set-window-dedicated-p (frame-selected-window frame) t)
186 (frame-selected-window frame))))))
8a9e86e6 187
924be53a 188(defun handle-delete-frame (event)
40d34803 189 "Handle delete-frame events from the X server."
924be53a
RS
190 (interactive "e")
191 (let ((frame (posn-window (event-start event)))
192 (i 0)
193 (tail (frame-list)))
194 (while tail
195 (and (frame-visible-p (car tail))
196 (not (eq (car tail) frame))
197 (setq i (1+ i)))
198 (setq tail (cdr tail)))
199 (if (> i 0)
200 (delete-frame frame t)
a9562d19
RS
201 ;; Gildea@x.org says it is ok to ask questions before terminating.
202 (save-buffers-kill-emacs))))
64c669bc 203\f
dc6d9681 204;;;; Arrangement of frames at startup
64c669bc 205
7e573c4a
SM
206;; 1) Load the window system startup file from the lisp library and read the
207;; high-priority arguments (-q and the like). The window system startup
208;; file should create any frames specified in the window system defaults.
209;;
210;; 2) If no frames have been opened, we open an initial text frame.
211;;
212;; 3) Once the init file is done, we apply any newly set parameters
213;; in initial-frame-alist to the frame.
64c669bc 214
85557d7e 215;; These are now called explicitly at the proper times,
fc4d4afb
RS
216;; since that is easier to understand.
217;; Actually using hooks within Emacs is bad for future maintenance. --rms.
218;; (add-hook 'before-init-hook 'frame-initialize)
219;; (add-hook 'window-setup-hook 'frame-notice-user-settings)
64c669bc 220
7e573c4a 221;; If we create the initial frame, this is it.
dc6d9681 222(defvar frame-initial-frame nil)
64c669bc 223
3f2f8c83
RS
224;; Record the parameters used in frame-initialize to make the initial frame.
225(defvar frame-initial-frame-alist)
226
791e09d8
RS
227(defvar frame-initial-geometry-arguments nil)
228
7e573c4a
SM
229;; startup.el calls this function before loading the user's init
230;; file - if there is no frame with a minibuffer open now, create
231;; one to display messages while loading the init file.
dc6d9681 232(defun frame-initialize ()
ff2a1c79 233 "Create an initial frame if necessary."
64c669bc 234 ;; Are we actually running under a window system at all?
2246281f
KL
235 (if (and initial-window-system
236 (not noninteractive)
237 (not (eq initial-window-system 'pc)))
7eadab74
JB
238 (progn
239 ;; If there is no frame with a minibuffer besides the terminal
240 ;; frame, then we need to create the opening frame. Make sure
241 ;; it has a minibuffer, but let initial-frame-alist omit the
242 ;; minibuffer spec.
243 (or (delq terminal-frame (minibuffer-frame-list))
36fc9c9f 244 (progn
3f2f8c83 245 (setq frame-initial-frame-alist
9688894d 246 (append initial-frame-alist default-frame-alist nil))
a8bb5882
RS
247 (or (assq 'horizontal-scroll-bars frame-initial-frame-alist)
248 (setq frame-initial-frame-alist
249 (cons '(horizontal-scroll-bars . t)
250 frame-initial-frame-alist)))
2246281f
KL
251 (setq frame-initial-frame-alist
252 (cons (cons 'window-system initial-window-system)
253 frame-initial-frame-alist))
36fc9c9f
RS
254 (setq default-minibuffer-frame
255 (setq frame-initial-frame
96a84970 256 (make-frame frame-initial-frame-alist)))
11281034
RS
257 ;; Delete any specifications for window geometry parameters
258 ;; so that we won't reapply them in frame-notice-user-settings.
259 ;; It would be wrong to reapply them then,
260 ;; because that would override explicit user resizing.
58bf6042 261 (setq initial-frame-alist
c2079f0a 262 (frame-remove-geometry-params initial-frame-alist))))
a13f8f50
KL
263 ;; Copy the environment of the Emacs process into the new frame.
264 (set-frame-parameter frame-initial-frame 'environment
265 (frame-parameter terminal-frame 'environment))
85557d7e 266 ;; At this point, we know that we have a frame open, so we
dc6d9681
JB
267 ;; can delete the terminal frame.
268 (delete-frame terminal-frame)
2246281f 269 (setq terminal-frame nil))))
85557d7e 270
8f2a992b
GM
271(defvar frame-notice-user-settings t
272 "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
273
aa360da1
GM
274(declare-function tool-bar-mode "tool-bar" (&optional arg))
275
7e573c4a
SM
276;; startup.el calls this function after loading the user's init
277;; file. Now default-frame-alist and initial-frame-alist contain
278;; information to which we must react; do what needs to be done.
dc6d9681 279(defun frame-notice-user-settings ()
40d34803 280 "Act on user's init file settings of frame parameters.
0e1bfc78
KL
281React to settings of `initial-frame-alist',
282`window-system-default-frame-alist' and `default-frame-alist'
283there (in decreasing order of priority)."
7eadab74
JB
284 ;; Creating and deleting frames may shift the selected frame around,
285 ;; and thus the current buffer. Protect against that. We don't
286 ;; want to use save-excursion here, because that may also try to set
287 ;; the buffer of the selected window, which fails when the selected
288 ;; window is the minibuffer.
0e1bfc78 289 (let ((old-buffer (current-buffer))
cb01ce3f
SM
290 (window-system-frame-alist
291 (cdr (assq initial-window-system
292 window-system-default-frame-alist))))
7eadab74 293
8f2a992b
GM
294 (when (and frame-notice-user-settings
295 (null frame-initial-frame))
42002db5
EZ
296 ;; This case happens when we don't have a window system, and
297 ;; also for MS-DOS frames.
8f2a992b
GM
298 (let ((parms (frame-parameters frame-initial-frame)))
299 ;; Don't change the frame names.
300 (setq parms (delq (assq 'name parms) parms))
301 ;; Can't modify the minibuffer parameter, so don't try.
302 (setq parms (delq (assq 'minibuffer parms) parms))
303 (modify-frame-parameters nil
2246281f 304 (if (null initial-window-system)
42002db5 305 (append initial-frame-alist
0e1bfc78 306 window-system-frame-alist
42002db5
EZ
307 default-frame-alist
308 parms
309 nil)
310 ;; initial-frame-alist and
311 ;; default-frame-alist were already
312 ;; applied in pc-win.el.
313 parms))
2246281f 314 (if (null initial-window-system) ;; MS-DOS does this differently in pc-win.el
42002db5
EZ
315 (let ((newparms (frame-parameters))
316 (frame (selected-frame)))
317 (tty-handle-reverse-video frame newparms)
318 ;; If we changed the background color, we need to update
319 ;; the background-mode parameter, and maybe some faces,
320 ;; too.
321 (when (assq 'background-color newparms)
322 (unless (or (assq 'background-mode initial-frame-alist)
323 (assq 'background-mode default-frame-alist))
324 (frame-set-background-mode frame))
325 (face-set-after-frame-default frame))))))
8f2a992b 326
7eadab74
JB
327 ;; If the initial frame is still around, apply initial-frame-alist
328 ;; and default-frame-alist to it.
9688894d
GM
329 (when (frame-live-p frame-initial-frame)
330
331 ;; When tool-bar has been switched off, correct the frame size
332 ;; by the lines added in x-create-frame for the tool-bar and
333 ;; switch `tool-bar-mode' off.
085ef9b3
GM
334 (when (display-graphic-p)
335 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
0e1bfc78 336 (assq 'tool-bar-lines window-system-frame-alist)
085ef9b3 337 (assq 'tool-bar-lines default-frame-alist))))
5c39a60f
JR
338 (when (and tool-bar-originally-present
339 (or (null tool-bar-lines)
340 (null (cdr tool-bar-lines))
341 (eq 0 (cdr tool-bar-lines))))
085ef9b3 342 (let* ((char-height (frame-char-height frame-initial-frame))
5c39a60f 343 (image-height tool-bar-images-pixel-height)
085ef9b3
GM
344 (margin (cond ((and (consp tool-bar-button-margin)
345 (integerp (cdr tool-bar-button-margin))
346 (> tool-bar-button-margin 0))
347 (cdr tool-bar-button-margin))
348 ((and (integerp tool-bar-button-margin)
349 (> tool-bar-button-margin 0))
350 tool-bar-button-margin)
351 (t 0)))
352 (relief (if (and (integerp tool-bar-button-relief)
353 (> tool-bar-button-relief 0))
354 tool-bar-button-relief 3))
f39784dd 355 (lines (/ (+ image-height
085ef9b3
GM
356 (* 2 margin)
357 (* 2 relief)
358 (1- char-height))
359 char-height))
360 (height (frame-parameter frame-initial-frame 'height))
361 (newparms (list (cons 'height (- height lines))))
f39784dd 362 (initial-top (cdr (assq 'top
085ef9b3
GM
363 frame-initial-geometry-arguments)))
364 (top (frame-parameter frame-initial-frame 'top)))
365 (when (and (consp initial-top) (eq '- (car initial-top)))
7f18ce22
RS
366 (let ((adjusted-top
367 (cond ((and (consp top)
368 (eq '+ (car top)))
369 (list '+
370 (+ (cadr top)
371 (* lines char-height))))
372 ((and (consp top)
373 (eq '- (car top)))
374 (list '-
375 (- (cadr top)
376 (* lines char-height))))
377 (t (+ top (* lines char-height))))))
378 (setq newparms
379 (append newparms
380 `((top . ,adjusted-top))
381 nil))))
085ef9b3
GM
382 (modify-frame-parameters frame-initial-frame newparms)
383 (tool-bar-mode -1)))))
9688894d
GM
384
385 ;; The initial frame we create above always has a minibuffer.
386 ;; If the user wants to remove it, or make it a minibuffer-only
387 ;; frame, then we'll have to delete the current frame and make a
388 ;; new one; you can't remove or add a root window to/from an
389 ;; existing frame.
390 ;;
391 ;; NOTE: default-frame-alist was nil when we created the
392 ;; existing frame. We need to explicitly include
393 ;; default-frame-alist in the parameters of the screen we
394 ;; create here, so that its new value, gleaned from the user's
395 ;; .emacs file, will be applied to the existing screen.
de2f5dbe 396 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
0e1bfc78 397 (assq 'minibuffer window-system-frame-alist)
de2f5dbe
GM
398 (assq 'minibuffer default-frame-alist)
399 '(minibuffer . t)))
400 t))
401 ;; Create the new frame.
402 (let (parms new)
403 ;; If the frame isn't visible yet, wait till it is.
404 ;; If the user has to position the window,
405 ;; Emacs doesn't know its real position until
406 ;; the frame is seen to be visible.
407 (while (not (cdr (assq 'visibility
408 (frame-parameters frame-initial-frame))))
409 (sleep-for 1))
410 (setq parms (frame-parameters frame-initial-frame))
9688894d 411
f39784dd 412 ;; Get rid of `name' unless it was specified explicitly before.
de2f5dbe
GM
413 (or (assq 'name frame-initial-frame-alist)
414 (setq parms (delq (assq 'name parms) parms)))
2f5bb432
SM
415 ;; An explicit parent-id is a request to XEmbed the frame.
416 (or (assq 'parent-id frame-initial-frame-alist)
417 (setq parms (delq (assq 'parent-id parms) parms)))
de2f5dbe
GM
418
419 (setq parms (append initial-frame-alist
0e1bfc78 420 window-system-frame-alist
de2f5dbe
GM
421 default-frame-alist
422 parms
423 nil))
424
425 ;; Get rid of `reverse', because that was handled
426 ;; when we first made the frame.
427 (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
428
429 (if (assq 'height frame-initial-geometry-arguments)
430 (setq parms (assq-delete-all 'height parms)))
431 (if (assq 'width frame-initial-geometry-arguments)
432 (setq parms (assq-delete-all 'width parms)))
433 (if (assq 'left frame-initial-geometry-arguments)
434 (setq parms (assq-delete-all 'left parms)))
435 (if (assq 'top frame-initial-geometry-arguments)
436 (setq parms (assq-delete-all 'top parms)))
437 (setq new
438 (make-frame
439 ;; Use the geometry args that created the existing
440 ;; frame, rather than the parms we get for it.
441 (append frame-initial-geometry-arguments
442 '((user-size . t) (user-position . t))
443 parms)))
444 ;; The initial frame, which we are about to delete, may be
445 ;; the only frame with a minibuffer. If it is, create a
446 ;; new one.
447 (or (delq frame-initial-frame (minibuffer-frame-list))
448 (make-initial-minibuffer-frame nil))
449
450 ;; If the initial frame is serving as a surrogate
451 ;; minibuffer frame for any frames, we need to wean them
452 ;; onto a new frame. The default-minibuffer-frame
453 ;; variable must be handled similarly.
454 (let ((users-of-initial
455 (filtered-frame-list
b7de6024
SM
456 (lambda (frame)
457 (and (not (eq frame frame-initial-frame))
458 (eq (window-frame
459 (minibuffer-window frame))
460 frame-initial-frame))))))
461 (if (or users-of-initial
de2f5dbe
GM
462 (eq default-minibuffer-frame frame-initial-frame))
463
464 ;; Choose an appropriate frame. Prefer frames which
465 ;; are only minibuffers.
466 (let* ((new-surrogate
467 (car
468 (or (filtered-frame-list
b7de6024
SM
469 (lambda (frame)
470 (eq (cdr (assq 'minibuffer
471 (frame-parameters frame)))
472 'only)))
de2f5dbe
GM
473 (minibuffer-frame-list))))
474 (new-minibuffer (minibuffer-window new-surrogate)))
475
476 (if (eq default-minibuffer-frame frame-initial-frame)
477 (setq default-minibuffer-frame new-surrogate))
478
479 ;; Wean the frames using frame-initial-frame as
480 ;; their minibuffer frame.
b7de6024
SM
481 (dolist (frame users-of-initial)
482 (modify-frame-parameters
483 frame (list (cons 'minibuffer new-minibuffer)))))))
484
485 ;; Redirect events enqueued at this frame to the new frame.
de2f5dbe
GM
486 ;; Is this a good idea?
487 (redirect-frame-focus frame-initial-frame new)
488
489 ;; Finally, get rid of the old frame.
490 (delete-frame frame-initial-frame t))
9688894d
GM
491
492 ;; Otherwise, we don't need all that rigamarole; just apply
493 ;; the new parameters.
494 (let (newparms allparms tail)
495 (setq allparms (append initial-frame-alist
0e1bfc78 496 window-system-frame-alist
9688894d
GM
497 default-frame-alist nil))
498 (if (assq 'height frame-initial-geometry-arguments)
499 (setq allparms (assq-delete-all 'height allparms)))
500 (if (assq 'width frame-initial-geometry-arguments)
501 (setq allparms (assq-delete-all 'width allparms)))
502 (if (assq 'left frame-initial-geometry-arguments)
503 (setq allparms (assq-delete-all 'left allparms)))
504 (if (assq 'top frame-initial-geometry-arguments)
505 (setq allparms (assq-delete-all 'top allparms)))
506 (setq tail allparms)
507 ;; Find just the parms that have changed since we first
508 ;; made this frame. Those are the ones actually set by
f39784dd 509 ;; the init file. For those parms whose values we already knew
9688894d
GM
510 ;; (such as those spec'd by command line options)
511 ;; it is undesirable to specify the parm again
f39784dd 512 ;; once the user has seen the frame and been able to alter it
9688894d
GM
513 ;; manually.
514 (while tail
515 (let (newval oldval)
516 (setq oldval (assq (car (car tail))
517 frame-initial-frame-alist))
518 (setq newval (cdr (assq (car (car tail)) allparms)))
519 (or (and oldval (eq (cdr oldval) newval))
520 (setq newparms
521 (cons (cons (car (car tail)) newval) newparms))))
522 (setq tail (cdr tail)))
523 (setq newparms (nreverse newparms))
524 (modify-frame-parameters frame-initial-frame
525 newparms)
526 ;; If we changed the background color,
527 ;; we need to update the background-mode parameter
528 ;; and maybe some faces too.
529 (when (assq 'background-color newparms)
530 (unless (assq 'background-mode newparms)
531 (frame-set-background-mode frame-initial-frame))
532 (face-set-after-frame-default frame-initial-frame)))))
64c669bc 533
7eadab74
JB
534 ;; Restore the original buffer.
535 (set-buffer old-buffer)
536
537 ;; Make sure the initial frame can be GC'd if it is ever deleted.
d202f1f2 538 ;; Make sure frame-notice-user-settings does nothing if called twice.
8f2a992b 539 (setq frame-notice-user-settings nil)
d202f1f2 540 (setq frame-initial-frame nil)))
64c669bc 541
746bd265
KH
542(defun make-initial-minibuffer-frame (display)
543 (let ((parms (append minibuffer-frame-alist '((minibuffer . only)))))
544 (if display
545 (make-frame-on-display display parms)
546 (make-frame parms))))
547
7eadab74 548;;;; Creation of additional frames, and other frame miscellanea
dc6d9681 549
63019bad 550(defun modify-all-frames-parameters (alist)
d398de43 551 "Modify all current and future frames' parameters according to ALIST.
63019bad 552This changes `default-frame-alist' and possibly `initial-frame-alist'.
095fe281
KL
553Furthermore, this function removes all parameters in ALIST from
554`window-system-default-frame-alist'.
63019bad 555See help of `modify-frame-parameters' for more information."
095fe281
KL
556 (dolist (frame (frame-list))
557 (modify-frame-parameters frame alist))
558
559 (dolist (pair alist) ;; conses to add/replace
560 ;; initial-frame-alist needs setting only when
561 ;; frame-notice-user-settings is true.
562 (and frame-notice-user-settings
563 (setq initial-frame-alist
564 (assq-delete-all (car pair) initial-frame-alist)))
565 (setq default-frame-alist
566 (assq-delete-all (car pair) default-frame-alist))
567 ;; Remove any similar settings from the window-system specific
568 ;; parameters---they would override default-frame-alist.
569 (dolist (w window-system-default-frame-alist)
570 (setcdr w (assq-delete-all (car pair) (cdr w)))))
571
63019bad
JB
572 (and frame-notice-user-settings
573 (setq initial-frame-alist (append initial-frame-alist alist)))
574 (setq default-frame-alist (append default-frame-alist alist)))
575
7253d8e0 576(defun get-other-frame ()
40d34803
DL
577 "Return some frame other than the current frame.
578Create one if necessary. Note that the minibuffer frame, if separate,
579is not considered (see `next-frame')."
dc6d9681 580 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
6eb018ba 581 (make-frame)
dc6d9681 582 (next-frame (selected-frame)))))
64c669bc
JB
583 s))
584
dc6d9681
JB
585(defun next-multiframe-window ()
586 "Select the next window, regardless of which frame it is on."
64c669bc
JB
587 (interactive)
588 (select-window (next-window (selected-window)
589 (> (minibuffer-depth) 0)
bb2c34b1 590 0))
030f4537 591 (select-frame-set-input-focus (selected-frame)))
64c669bc 592
dc6d9681
JB
593(defun previous-multiframe-window ()
594 "Select the previous window, regardless of which frame it is on."
64c669bc
JB
595 (interactive)
596 (select-window (previous-window (selected-window)
597 (> (minibuffer-depth) 0)
bb2c34b1 598 0))
030f4537 599 (select-frame-set-input-focus (selected-frame)))
64c669bc 600
bbf6ef44 601(declare-function x-initialize-window-system "term/x-win" ())
4c1863cd 602(declare-function ns-initialize-window-system "term/ns-win" ())
5f9214ee 603(defvar x-display-name) ; term/x-win
bbf6ef44 604
6d73e337 605(defun make-frame-on-display (display &optional parameters)
c5a8bc01
CY
606 "Make a frame on display DISPLAY.
607The optional argument PARAMETERS specifies additional frame parameters."
6d73e337 608 (interactive "sMake frame on display: ")
c5a8bc01
CY
609 (cond ((featurep 'ns)
610 (when (and (boundp 'ns-initialized) (not ns-initialized))
611 (setq x-display-name display)
612 (ns-initialize-window-system))
613 (make-frame `((window-system . ns)
614 (display . ,display) . ,parameters)))
615 ((eq system-type 'windows-nt)
616 ;; On Windows, ignore DISPLAY.
617 (make-frame parameters))
618 (t
69135f12 619 (unless (string-match-p "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display)
c5a8bc01
CY
620 (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
621 (when (and (boundp 'x-initialized) (not x-initialized))
622 (setq x-display-name display)
623 (x-initialize-window-system))
624 (make-frame `((window-system . x)
625 (display . ,display) . ,parameters)))))
6d73e337 626
aa360da1
GM
627(declare-function x-close-connection "xfns.c" (terminal))
628
b7de6024
SM
629(defun close-display-connection (display)
630 "Close the connection to a display, deleting all its associated frames.
631For DISPLAY, specify either a frame or a display name (a string).
632If DISPLAY is nil, that stands for the selected frame's display."
633 (interactive
634 (list
635 (let* ((default (frame-parameter nil 'display))
636 (display (completing-read
637 (format "Close display (default %s): " default)
638 (delete-dups
639 (mapcar (lambda (frame)
640 (frame-parameter frame 'display))
641 (frame-list)))
642 nil t nil nil
643 default)))
644 (if (zerop (length display)) default display))))
645 (let ((frames (delq nil
646 (mapcar (lambda (frame)
647 (if (equal display
648 (frame-parameter frame 'display))
649 frame))
650 (frame-list)))))
651 (if (and (consp frames)
652 (not (y-or-n-p (if (cdr frames)
653 (format "Delete %s frames? " (length frames))
654 (format "Delete %s ? " (car frames))))))
655 (error "Abort!")
656 (mapc 'delete-frame frames)
657 (x-close-connection display))))
658
6238bfaf 659(defun make-frame-command ()
e9e6aee8
CY
660 "Make a new frame, on the same terminal as the selected frame.
661If the terminal is a text-only terminal, this also selects the
662new frame."
6238bfaf 663 (interactive)
e9e6aee8 664 (if (display-graphic-p)
6238bfaf
RS
665 (make-frame)
666 (select-frame (make-frame))))
667
45c4fdeb
SM
668(defvar before-make-frame-hook nil
669 "Functions to run before a frame is created.")
670
671(defvar after-make-frame-functions nil
672 "Functions to run after a frame is created.
673The functions are run with one arg, the newly created frame.")
674
72bf1a8b 675(defvar after-setting-font-hook nil
81b99826
GM
676 "Functions to run after a frame's font has been changed.")
677
92e443b1 678;; Alias, kept temporarily.
84ed1560 679(define-obsolete-function-alias 'new-frame 'make-frame "22.1")
bc93c097 680
9e483377 681(defvar frame-inherited-parameters '()
ab6198b2
SM
682 ;; FIXME: Shouldn't we add `font' here as well?
683 "Parameters `make-frame' copies from the `selected-frame' to the new frame.")
684
45c4fdeb
SM
685(defun make-frame (&optional parameters)
686 "Return a newly created frame displaying the current buffer.
c1ef4455
CY
687Optional argument PARAMETERS is an alist of frame parameters for
688the new frame. Each element of PARAMETERS should have the
689form (NAME . VALUE), for example:
a105105a 690
45c4fdeb 691 (name . STRING) The frame should be named STRING.
43a2e52c 692
45c4fdeb
SM
693 (width . NUMBER) The frame should be NUMBER characters in width.
694 (height . NUMBER) The frame should be NUMBER text lines high.
43a2e52c 695
c1ef4455
CY
696You cannot specify either `width' or `height', you must specify
697neither or both.
43a2e52c 698
45c4fdeb
SM
699 (minibuffer . t) The frame should have a minibuffer.
700 (minibuffer . nil) The frame should have no minibuffer.
701 (minibuffer . only) The frame should contain only a minibuffer.
702 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
43a2e52c 703
2246281f
KL
704 (window-system . nil) The frame should be displayed on a terminal device.
705 (window-system . x) The frame should be displayed in an X window.
706
d51f6378 707 (terminal . TERMINAL) The frame should use the terminal object TERMINAL.
b6660415 708
c1ef4455
CY
709In addition, any parameter specified in `default-frame-alist',
710but not present in PARAMETERS, is applied.
8de9d3f6 711
c1ef4455
CY
712Before creating the frame (via `frame-creation-function-alist'),
713this function runs the hook `before-make-frame-hook'. After
714creating the frame, it runs the hook `after-make-frame-functions'
715with one arg, the newly created frame.
716
717On graphical displays, this function does not itself make the new
718frame the selected frame. However, the window system may select
719the new frame according to its own rules."
64c669bc 720 (interactive)
b6660415 721 (let* ((w (cond
6ed8eeff
KL
722 ((assq 'terminal parameters)
723 (let ((type (terminal-live-p (cdr (assq 'terminal parameters)))))
b6660415
KL
724 (cond
725 ((eq type t) nil)
cb01ce3f
SM
726 ((eq type nil) (error "Terminal %s does not exist"
727 (cdr (assq 'terminal parameters))))
b6660415
KL
728 (t type))))
729 ((assq 'window-system parameters)
730 (cdr (assq 'window-system parameters)))
731 (t window-system)))
2246281f 732 (frame-creation-function (cdr (assq w frame-creation-function-alist)))
da8e8fc1 733 (oldframe (selected-frame))
c1ef4455 734 (params parameters)
2246281f
KL
735 frame)
736 (unless frame-creation-function
737 (error "Don't know how to create a frame on window system %s" w))
c1ef4455
CY
738 ;; Add parameters from `window-system-default-frame-alist'.
739 (dolist (p (cdr (assq w window-system-default-frame-alist)))
21bd02a6 740 (unless (assq (car p) params)
c1ef4455
CY
741 (push p params)))
742 ;; Add parameters from `default-frame-alist'.
743 (dolist (p default-frame-alist)
21bd02a6 744 (unless (assq (car p) params)
c1ef4455
CY
745 (push p params)))
746 ;; Now make the frame.
2246281f 747 (run-hooks 'before-make-frame-hook)
c1ef4455 748 (setq frame (funcall frame-creation-function params))
30a2fded 749 (normal-erase-is-backspace-setup-frame frame)
ab6198b2
SM
750 ;; Inherit the original frame's parameters.
751 (dolist (param frame-inherited-parameters)
752 (unless (assq param parameters) ;Overridden by explicit parameters.
753 (let ((val (frame-parameter oldframe param)))
754 (when val (set-frame-parameter frame param val)))))
45c4fdeb
SM
755 (run-hook-with-args 'after-make-frame-functions frame)
756 frame))
64c669bc 757
7eadab74
JB
758(defun filtered-frame-list (predicate)
759 "Return a list of all live frames which satisfy PREDICATE."
047bc928
GM
760 (let* ((frames (frame-list))
761 (list frames))
7eadab74 762 (while (consp frames)
047bc928
GM
763 (unless (funcall predicate (car frames))
764 (setcar frames nil))
7eadab74 765 (setq frames (cdr frames)))
047bc928 766 (delq nil list)))
7eadab74
JB
767
768(defun minibuffer-frame-list ()
769 "Return a list of all frames with their own minibuffers."
770 (filtered-frame-list
b7de6024
SM
771 (lambda (frame)
772 (eq frame (window-frame (minibuffer-window frame))))))
7eadab74 773
371fed4e
SM
774;; Used to be called `terminal-id' in termdev.el.
775(defun get-device-terminal (device)
776 "Return the terminal corresponding to DEVICE.
777DEVICE can be a terminal, a frame, nil (meaning the selected frame's terminal),
778the name of an X display device (HOST.SERVER.SCREEN) or a tty device file."
779 (cond
780 ((or (null device) (framep device))
781 (frame-terminal device))
782 ((stringp device)
783 (let ((f (car (filtered-frame-list
784 (lambda (frame)
785 (or (equal (frame-parameter frame 'display) device)
786 (equal (frame-parameter frame 'tty) device)))))))
787 (or f (error "Display %s does not exist" device))
788 (frame-terminal f)))
789 ((terminal-live-p device) device)
790 (t
791 (error "Invalid argument %s in `get-device-terminal'" device))))
792
793(defun frames-on-display-list (&optional device)
794 "Return a list of all frames on DEVICE.
795
796DEVICE should be a terminal, a frame,
797or a name of an X display or tty (a string of the form
9684e4c9 798HOST:SERVER.SCREEN).
b6660415 799
371fed4e 800If DEVICE is omitted or nil, it defaults to the selected
9684e4c9 801frame's terminal device."
371fed4e 802 (let* ((terminal (get-device-terminal device))
047bc928 803 (func #'(lambda (frame)
6ed8eeff 804 (eq (frame-terminal frame) terminal))))
9911648b
EZ
805 (filtered-frame-list func)))
806
f35ca2fe
KL
807(defun framep-on-display (&optional terminal)
808 "Return the type of frames on TERMINAL.
809TERMINAL may be a terminal id, a display name or a frame. If it
810is a frame, its type is returned. If TERMINAL is omitted or nil,
811it defaults to the selected frame's terminal device. All frames
812on a given display are of the same type."
6ed8eeff 813 (or (terminal-live-p terminal)
f35ca2fe
KL
814 (framep terminal)
815 (framep (car (frames-on-display-list terminal)))))
9911648b 816
58bf6042
JB
817(defun frame-remove-geometry-params (param-list)
818 "Return the parameter list PARAM-LIST, but with geometry specs removed.
819This deletes all bindings in PARAM-LIST for `top', `left', `width',
791e09d8 820`height', `user-size' and `user-position' parameters.
58bf6042
JB
821Emacs uses this to avoid overriding explicit moves and resizings from
822the user during startup."
823 (setq param-list (cons nil param-list))
824 (let ((tail param-list))
825 (while (consp (cdr tail))
826 (if (and (consp (car (cdr tail)))
791e09d8
RS
827 (memq (car (car (cdr tail)))
828 '(height width top left user-position user-size)))
829 (progn
830 (setq frame-initial-geometry-arguments
831 (cons (car (cdr tail)) frame-initial-geometry-arguments))
832 (setcdr tail (cdr (cdr tail))))
58bf6042 833 (setq tail (cdr tail)))))
e11c3dc2
KH
834 (setq frame-initial-geometry-arguments
835 (nreverse frame-initial-geometry-arguments))
58bf6042
JB
836 (cdr param-list))
837
aa360da1
GM
838(declare-function x-focus-frame "xfns.c" (frame))
839
030f4537 840(defun select-frame-set-input-focus (frame)
bbca16d8 841 "Select FRAME, raise it, and set input focus, if possible.
e343066f 842If `mouse-autoselect-window' is non-nil, also move mouse pointer
bbca16d8
MR
843to FRAME's selected window. Otherwise, if `focus-follows-mouse'
844is non-nil, move mouse cursor to FRAME."
b0c7121c
MR
845 (select-frame frame)
846 (raise-frame frame)
bbca16d8 847 ;; Ensure, if possible, that FRAME gets input focus.
b0c7121c
MR
848 (when (memq (window-system frame) '(x w32 ns))
849 (x-focus-frame frame))
bbca16d8
MR
850 ;; Move mouse cursor if necessary.
851 (cond
852 (mouse-autoselect-window
853 (let ((edges (window-inside-edges (frame-selected-window frame))))
854 ;; Move mouse cursor into FRAME's selected window to avoid that
855 ;; Emacs mouse-autoselects another window.
856 (set-mouse-position frame (nth 2 edges) (nth 1 edges))))
857 (focus-follows-mouse
858 ;; Move mouse cursor into FRAME to avoid that another frame gets
859 ;; selected by the window manager.
860 (set-mouse-position frame (1- (frame-width frame)) 0))))
030f4537 861
ceab6935 862(defun other-frame (arg)
c2c93894 863 "Select the ARGth different visible frame on current display, and raise it.
ceab6935
RM
864All frames are arranged in a cyclic order.
865This command selects the frame ARG steps away in that order.
bb578a72
RS
866A negative ARG moves in the opposite order.
867
868To make this command work properly, you must tell Emacs
869how the system (or the window manager) generally handles
870focus-switching between windows. If moving the mouse onto a window
871selects it (gives it focus), set `focus-follows-mouse' to t.
872Otherwise, that variable should be nil."
ceab6935
RM
873 (interactive "p")
874 (let ((frame (selected-frame)))
875 (while (> arg 0)
a569dbc3
RM
876 (setq frame (next-frame frame))
877 (while (not (eq (frame-visible-p frame) t))
878 (setq frame (next-frame frame)))
879 (setq arg (1- arg)))
ceab6935 880 (while (< arg 0)
a569dbc3
RM
881 (setq frame (previous-frame frame))
882 (while (not (eq (frame-visible-p frame) t))
883 (setq frame (previous-frame frame)))
915cfd1f 884 (setq arg (1+ arg)))
030f4537 885 (select-frame-set-input-focus frame)))
845cde06 886
3db7df06
SM
887(defun iconify-or-deiconify-frame ()
888 "Iconify the selected frame, or deiconify if it's currently an icon."
889 (interactive)
890 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
891 (iconify-frame)
892 (make-frame-visible)))
893
0b0d3e0b
KL
894(defun suspend-frame ()
895 "Do whatever is right to suspend the current frame.
f35ca2fe
KL
896Calls `suspend-emacs' if invoked from the controlling tty device,
897`suspend-tty' from a secondary tty device, and
0b0d3e0b
KL
898`iconify-or-deiconify-frame' from an X frame."
899 (interactive)
900 (let ((type (framep (selected-frame))))
901 (cond
edfda783 902 ((memq type '(x ns w32)) (iconify-or-deiconify-frame))
0b0d3e0b 903 ((eq type t)
6ed8eeff 904 (if (controlling-tty-p)
4a933ef8
KL
905 (suspend-emacs)
906 (suspend-tty)))
0b0d3e0b
KL
907 (t (suspend-emacs)))))
908
845cde06
EZ
909(defun make-frame-names-alist ()
910 (let* ((current-frame (selected-frame))
911 (falist
912 (cons
913 (cons (frame-parameter current-frame 'name) current-frame) nil))
914 (frame (next-frame nil t)))
915 (while (not (eq frame current-frame))
916 (progn
917 (setq falist (cons (cons (frame-parameter frame 'name) frame) falist))
918 (setq frame (next-frame frame t))))
919 falist))
920
921(defvar frame-name-history nil)
845cde06 922(defun select-frame-by-name (name)
563283b1 923 "Select the frame on the current terminal whose name is NAME and raise it.
845cde06
EZ
924If there is no frame by that name, signal an error."
925 (interactive
716ff1c9
RS
926 (let* ((frame-names-alist (make-frame-names-alist))
927 (default (car (car frame-names-alist)))
928 (input (completing-read
929 (format "Select Frame (default %s): " default)
930 frame-names-alist nil t nil 'frame-name-history)))
845cde06
EZ
931 (if (= (length input) 0)
932 (list default)
933 (list input))))
716ff1c9
RS
934 (let* ((frame-names-alist (make-frame-names-alist))
935 (frame (cdr (assoc name frame-names-alist))))
bbca16d8
MR
936 (if frame
937 (select-frame-set-input-focus frame)
938 (error "There is no frame named `%s'" name))))
64c669bc 939\f
dc6d9681
JB
940;;;; Frame configurations
941
942(defun current-frame-configuration ()
943 "Return a list describing the positions and states of all frames.
376a7584
JB
944Its car is `frame-configuration'.
945Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
946where
947 FRAME is a frame object,
948 ALIST is an association list specifying some of FRAME's parameters, and
949 WINDOW-CONFIG is a window configuration object for FRAME."
950 (cons 'frame-configuration
b7de6024
SM
951 (mapcar (lambda (frame)
952 (list frame
953 (frame-parameters frame)
954 (current-window-configuration frame)))
376a7584 955 (frame-list))))
dc6d9681 956
68cd265f 957(defun set-frame-configuration (configuration &optional nodelete)
dc6d9681
JB
958 "Restore the frames to the state described by CONFIGURATION.
959Each frame listed in CONFIGURATION has its position, size, window
68cd265f 960configuration, and other parameters set as specified in CONFIGURATION.
d398de43
LT
961However, this function does not restore deleted frames.
962
a78db71c
RS
963Ordinarily, this function deletes all existing frames not
964listed in CONFIGURATION. But if optional second argument NODELETE
5da841d2 965is given and non-nil, the unwanted frames are iconified instead."
376a7584
JB
966 (or (frame-configuration-p configuration)
967 (signal 'wrong-type-argument
968 (list 'frame-configuration-p configuration)))
969 (let ((config-alist (cdr configuration))
970 frames-to-delete)
b7de6024
SM
971 (dolist (frame (frame-list))
972 (let ((parameters (assq frame config-alist)))
973 (if parameters
974 (progn
975 (modify-frame-parameters
976 frame
977 ;; Since we can't set a frame's minibuffer status,
978 ;; we might as well omit the parameter altogether.
979 (let* ((parms (nth 1 parameters))
b2529d56
MB
980 (mini (assq 'minibuffer parms))
981 (name (assq 'name parms))
982 (explicit-name (cdr (assq 'explicit-name parms))))
983 (when mini (setq parms (delq mini parms)))
984 ;; Leave name in iff it was set explicitly.
985 ;; This should fix the behavior reported in
986 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg01632.html
987 (when (and name (not explicit-name))
988 (setq parms (delq name parms)))
b7de6024
SM
989 parms))
990 (set-window-configuration (nth 2 parameters)))
991 (setq frames-to-delete (cons frame frames-to-delete)))))
992 (mapc (if nodelete
993 ;; Note: making frames invisible here was tried
994 ;; but led to some strange behavior--each time the frame
995 ;; was made visible again, the window manager asked afresh
996 ;; for where to put it.
997 'iconify-frame
998 'delete-frame)
999 frames-to-delete)))
64c669bc 1000\f
dc6d9681
JB
1001;;;; Convenience functions for accessing and interactively changing
1002;;;; frame parameters.
64c669bc 1003
151bdc83 1004(defun frame-height (&optional frame)
dc6d9681 1005 "Return number of lines available for display on FRAME.
4619ff5e
GM
1006If FRAME is omitted, describe the currently selected frame.
1007Exactly what is included in the return value depends on the
1008window-system and toolkit in use - see `frame-pixel-height' for
1009more details. The lines are in units of the default font height.
1010
1011The result is roughly related to the frame pixel height via
1012height in pixels = height in lines * `frame-char-height'.
1013However, this is only approximate, and is complicated e.g. by the
1014fact that individual window lines and menu bar lines can have
1015differing font heights."
151bdc83 1016 (cdr (assq 'height (frame-parameters frame))))
dc6d9681
JB
1017
1018(defun frame-width (&optional frame)
1019 "Return number of columns available for display on FRAME.
1020If FRAME is omitted, describe the currently selected frame."
151bdc83 1021 (cdr (assq 'width (frame-parameters frame))))
dc6d9681 1022
aa360da1
GM
1023(declare-function x-list-fonts "xfaces.c"
1024 (pattern &optional face frame maximum width))
1025
52ef9375 1026(define-obsolete-function-alias 'set-default-font 'set-frame-font "23.1")
1cef6541 1027(defun set-frame-font (font-name &optional keep-size)
40d34803 1028 "Set the font of the selected frame to FONT-NAME.
61298010 1029When called interactively, prompt for the name of the font to use.
1cef6541
JB
1030To get the frame's current default font, use `frame-parameters'.
1031
1032The default behavior is to keep the numbers of lines and columns in
84ed1560 1033the frame, thus may change its pixel size. If optional KEEP-SIZE is
1cef6541
JB
1034non-nil (interactively, prefix argument) the current frame size (in
1035pixels) is kept by adjusting the numbers of the lines and columns."
f39784dd 1036 (interactive
1cef6541
JB
1037 (let* ((completion-ignore-case t)
1038 (font (completing-read "Font name: "
1cef6541
JB
1039 ;; x-list-fonts will fail with an error
1040 ;; if this frame doesn't support fonts.
b7de6024
SM
1041 (x-list-fonts "*" nil (selected-frame))
1042 nil nil nil nil
1043 (frame-parameter nil 'font))))
1cef6541
JB
1044 (list font current-prefix-arg)))
1045 (let (fht fwd)
1046 (if keep-size
1047 (setq fht (* (frame-parameter nil 'height) (frame-char-height))
1048 fwd (* (frame-parameter nil 'width) (frame-char-width))))
1049 (modify-frame-parameters (selected-frame)
1050 (list (cons 'font font-name)))
1051 (if keep-size
1052 (modify-frame-parameters
1053 (selected-frame)
1054 (list (cons 'height (round fht (frame-char-height)))
1055 (cons 'width (round fwd (frame-char-width)))))))
72bf1a8b 1056 (run-hooks 'after-setting-font-hook 'after-setting-font-hooks))
64c669bc 1057
7e573c4a 1058(defun set-frame-parameter (frame parameter value)
0dac35b8
KL
1059 "Set frame parameter PARAMETER to VALUE on FRAME.
1060If FRAME is nil, it defaults to the selected frame.
c2c93894 1061See `modify-frame-parameters'."
7e573c4a
SM
1062 (modify-frame-parameters frame (list (cons parameter value))))
1063
8290babd 1064(defun set-background-color (color-name)
40d34803 1065 "Set the background color of the selected frame to COLOR-NAME.
61298010
RS
1066When called interactively, prompt for the name of the color to use.
1067To get the frame's current background color, use `frame-parameters'."
63ec4f94 1068 (interactive (list (facemenu-read-color "Background color: ")))
dc6d9681 1069 (modify-frame-parameters (selected-frame)
528e1416
EZ
1070 (list (cons 'background-color color-name)))
1071 (or window-system
1072 (face-set-after-frame-default (selected-frame))))
64c669bc 1073
8290babd 1074(defun set-foreground-color (color-name)
40d34803 1075 "Set the foreground color of the selected frame to COLOR-NAME.
61298010
RS
1076When called interactively, prompt for the name of the color to use.
1077To get the frame's current foreground color, use `frame-parameters'."
63ec4f94 1078 (interactive (list (facemenu-read-color "Foreground color: ")))
dc6d9681 1079 (modify-frame-parameters (selected-frame)
528e1416
EZ
1080 (list (cons 'foreground-color color-name)))
1081 (or window-system
1082 (face-set-after-frame-default (selected-frame))))
64c669bc
JB
1083
1084(defun set-cursor-color (color-name)
40d34803 1085 "Set the text cursor color of the selected frame to COLOR-NAME.
61298010
RS
1086When called interactively, prompt for the name of the color to use.
1087To get the frame's current cursor color, use `frame-parameters'."
63ec4f94 1088 (interactive (list (facemenu-read-color "Cursor color: ")))
dc6d9681 1089 (modify-frame-parameters (selected-frame)
7eadab74 1090 (list (cons 'cursor-color color-name))))
64c669bc 1091
eaa974e1 1092(defun set-mouse-color (color-name)
40d34803 1093 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
61298010
RS
1094When called interactively, prompt for the name of the color to use.
1095To get the frame's current mouse color, use `frame-parameters'."
63ec4f94 1096 (interactive (list (facemenu-read-color "Mouse color: ")))
dc6d9681 1097 (modify-frame-parameters (selected-frame)
ec6d4463
KH
1098 (list (cons 'mouse-color
1099 (or color-name
1100 (cdr (assq 'mouse-color
1101 (frame-parameters))))))))
7eadab74 1102
eaa974e1 1103(defun set-border-color (color-name)
40d34803 1104 "Set the color of the border of the selected frame to COLOR-NAME.
61298010
RS
1105When called interactively, prompt for the name of the color to use.
1106To get the frame's current border color, use `frame-parameters'."
63ec4f94 1107 (interactive (list (facemenu-read-color "Border color: ")))
eaa974e1
JB
1108 (modify-frame-parameters (selected-frame)
1109 (list (cons 'border-color color-name))))
1110
f44379e7 1111(define-minor-mode auto-raise-mode
7eadab74 1112 "Toggle whether or not the selected frame should auto-raise.
6cda144f 1113With ARG, turn auto-raise mode on if and only if ARG is positive.
79e6ae33
RS
1114Note that this controls Emacs's own auto-raise feature.
1115Some window managers allow you to enable auto-raise for certain windows.
1116You can use that for Emacs windows if you wish, but if you do,
1117that is beyond the control of Emacs and this command has no effect on it."
f44379e7
SM
1118 :variable (frame-parameter nil 'auto-raise)
1119 (if (frame-parameter nil 'auto-raise)
1120 (raise-frame)))
7eadab74 1121
f44379e7 1122(define-minor-mode auto-lower-mode
7eadab74 1123 "Toggle whether or not the selected frame should auto-lower.
6cda144f 1124With ARG, turn auto-lower mode on if and only if ARG is positive.
79e6ae33
RS
1125Note that this controls Emacs's own auto-lower feature.
1126Some window managers allow you to enable auto-lower for certain windows.
1127You can use that for Emacs windows if you wish, but if you do,
1128that is beyond the control of Emacs and this command has no effect on it."
f44379e7
SM
1129 :variable (frame-parameter nil 'auto-lower))
1130
7777d03b
EZ
1131(defun set-frame-name (name)
1132 "Set the name of the selected frame to NAME.
1133When called interactively, prompt for the name of the frame.
1134The frame name is displayed on the modeline if the terminal displays only
1135one frame, otherwise the name is displayed on the frame's caption bar."
1136 (interactive "sFrame name: ")
1137 (modify-frame-parameters (selected-frame)
1138 (list (cons 'name name))))
56cfea72
KS
1139
1140(defun frame-current-scroll-bars (&optional frame)
1141 "Return the current scroll-bar settings in frame FRAME.
1cecf04d 1142Value is a cons (VERTICAL . HORIZ0NTAL) where VERTICAL specifies the
56cfea72 1143current location of the vertical scroll-bars (left, right, or nil),
1cecf04d 1144and HORIZONTAL specifies the current location of the horizontal scroll
56cfea72
KS
1145bars (top, bottom, or nil)."
1146 (let ((vert (frame-parameter frame 'vertical-scroll-bars))
1147 (hor nil))
1148 (unless (memq vert '(left right nil))
1149 (setq vert default-frame-scroll-bars))
1150 (cons vert hor)))
64c669bc 1151\f
9911648b 1152;;;; Frame/display capabilities.
6ed8eeff
KL
1153(defun selected-terminal ()
1154 "Return the terminal that is now selected."
1155 (frame-terminal (selected-frame)))
b6660415 1156
73e6adaa
DN
1157(declare-function msdos-mouse-p "dosfns.c")
1158
9911648b
EZ
1159(defun display-mouse-p (&optional display)
1160 "Return non-nil if DISPLAY has a mouse available.
1161DISPLAY can be a display name, a frame, or nil (meaning the selected
1162frame's display)."
1163 (let ((frame-type (framep-on-display display)))
1164 (cond
1165 ((eq frame-type 'pc)
1166 (msdos-mouse-p))
1167 ((eq system-type 'windows-nt)
9fa5bb32
RS
1168 (with-no-warnings
1169 (> w32-num-mouse-buttons 0)))
9e2a2647
DN
1170 ((memq frame-type '(x ns))
1171 t) ;; We assume X and NeXTstep *always* have a pointing device
9911648b 1172 (t
7565ee93
DL
1173 (or (and (featurep 'xt-mouse)
1174 xterm-mouse-mode)
1175 ;; t-mouse is distributed with the GPM package. It doesn't have
1176 ;; a toggle.
1177 (featurep 't-mouse))))))
9911648b
EZ
1178
1179(defun display-popup-menus-p (&optional display)
1180 "Return non-nil if popup menus are supported on DISPLAY.
1181DISPLAY can be a display name, a frame, or nil (meaning the selected
1182frame's display).
1183Support for popup menus requires that the mouse be available."
1184 (and
1185 (let ((frame-type (framep-on-display display)))
9e2a2647 1186 (memq frame-type '(x w32 pc ns)))
9911648b
EZ
1187 (display-mouse-p display)))
1188
1189(defun display-graphic-p (&optional display)
1190 "Return non-nil if DISPLAY is a graphic display.
1191Graphical displays are those which are capable of displaying several
1192frames and several different fonts at once. This is true for displays
1193that use a window system such as X, and false for text-only terminals.
1194DISPLAY can be a display name, a frame, or nil (meaning the selected
1195frame's display)."
9e2a2647 1196 (not (null (memq (framep-on-display display) '(x w32 ns)))))
9911648b 1197
ddc456e4
EZ
1198(defun display-images-p (&optional display)
1199 "Return non-nil if DISPLAY can display images.
1200
1201DISPLAY can be a display name, a frame, or nil (meaning the selected
1202frame's display)."
1203 (and (display-graphic-p display)
1204 (fboundp 'image-mask-p)
fcc6f5cc 1205 (fboundp 'image-size)))
ddc456e4 1206
6693b279
EZ
1207(defalias 'display-multi-frame-p 'display-graphic-p)
1208(defalias 'display-multi-font-p 'display-graphic-p)
1209
9911648b
EZ
1210(defun display-selections-p (&optional display)
1211 "Return non-nil if DISPLAY supports selections.
1212A selection is a way to transfer text or other data between programs
1213via special system buffers called `selection' or `cut buffer' or
1214`clipboard'.
1215DISPLAY can be a display name, a frame, or nil (meaning the selected
1216frame's display)."
1217 (let ((frame-type (framep-on-display display)))
1218 (cond
1219 ((eq frame-type 'pc)
1220 ;; MS-DOG frames support selections when Emacs runs inside
1221 ;; the Windows' DOS Box.
9fa5bb32
RS
1222 (with-no-warnings
1223 (not (null dos-windows-version))))
9e2a2647 1224 ((memq frame-type '(x w32 ns))
9911648b
EZ
1225 t) ;; FIXME?
1226 (t
1227 nil))))
1228
aa360da1
GM
1229(declare-function x-display-screens "xfns.c" (&optional terminal))
1230
9911648b
EZ
1231(defun display-screens (&optional display)
1232 "Return the number of screens associated with DISPLAY."
1233 (let ((frame-type (framep-on-display display)))
1234 (cond
9e2a2647 1235 ((memq frame-type '(x w32 ns))
9911648b 1236 (x-display-screens display))
bb9404d6 1237 (t
9911648b
EZ
1238 1))))
1239
aa360da1
GM
1240(declare-function x-display-pixel-height "xfns.c" (&optional terminal))
1241
9911648b
EZ
1242(defun display-pixel-height (&optional display)
1243 "Return the height of DISPLAY's screen in pixels.
1244For character terminals, each character counts as a single pixel."
1245 (let ((frame-type (framep-on-display display)))
1246 (cond
9e2a2647 1247 ((memq frame-type '(x w32 ns))
9911648b
EZ
1248 (x-display-pixel-height display))
1249 (t
1250 (frame-height (if (framep display) display (selected-frame)))))))
1251
aa360da1
GM
1252(declare-function x-display-pixel-width "xfns.c" (&optional terminal))
1253
9911648b
EZ
1254(defun display-pixel-width (&optional display)
1255 "Return the width of DISPLAY's screen in pixels.
1256For character terminals, each character counts as a single pixel."
1257 (let ((frame-type (framep-on-display display)))
1258 (cond
9e2a2647 1259 ((memq frame-type '(x w32 ns))
9911648b
EZ
1260 (x-display-pixel-width display))
1261 (t
1262 (frame-width (if (framep display) display (selected-frame)))))))
1263
51e39dfc
KS
1264(defcustom display-mm-dimensions-alist nil
1265 "Alist for specifying screen dimensions in millimeters.
1266The dimensions will be used for `display-mm-height' and
1267`display-mm-width' if defined for the respective display.
1268
1269Each element of the alist has the form (display . (width . height)),
1270e.g. (\":0.0\" . (287 . 215)).
1271
1272If `display' equals t, it specifies dimensions for all graphical
1273displays not explicitely specified."
1274 :version "22.1"
1275 :type '(alist :key-type (choice (string :tag "Display name")
1276 (const :tag "Default" t))
1277 :value-type (cons :tag "Dimensions"
1278 (integer :tag "Width")
1279 (integer :tag "Height")))
1280 :group 'frames)
1281
aa360da1
GM
1282(declare-function x-display-mm-height "xfns.c" (&optional terminal))
1283
9911648b
EZ
1284(defun display-mm-height (&optional display)
1285 "Return the height of DISPLAY's screen in millimeters.
d7cd2d8b 1286System values can be overridden by `display-mm-dimensions-alist'.
9911648b 1287If the information is unavailable, value is nil."
9e2a2647 1288 (and (memq (framep-on-display display) '(x w32 ns))
51e39dfc
KS
1289 (or (cddr (assoc (or display (frame-parameter nil 'display))
1290 display-mm-dimensions-alist))
1291 (cddr (assoc t display-mm-dimensions-alist))
1292 (x-display-mm-height display))))
9911648b 1293
aa360da1
GM
1294(declare-function x-display-mm-width "xfns.c" (&optional terminal))
1295
9911648b
EZ
1296(defun display-mm-width (&optional display)
1297 "Return the width of DISPLAY's screen in millimeters.
d7cd2d8b 1298System values can be overridden by `display-mm-dimensions-alist'.
9911648b 1299If the information is unavailable, value is nil."
9e2a2647 1300 (and (memq (framep-on-display display) '(x w32 ns))
51e39dfc
KS
1301 (or (cadr (assoc (or display (frame-parameter nil 'display))
1302 display-mm-dimensions-alist))
1303 (cadr (assoc t display-mm-dimensions-alist))
1304 (x-display-mm-width display))))
9911648b 1305
aa360da1
GM
1306(declare-function x-display-backing-store "xfns.c" (&optional terminal))
1307
9911648b
EZ
1308(defun display-backing-store (&optional display)
1309 "Return the backing store capability of DISPLAY's screen.
1310The value may be `always', `when-mapped', `not-useful', or nil if
1311the question is inapplicable to a certain kind of display."
1312 (let ((frame-type (framep-on-display display)))
1313 (cond
9e2a2647 1314 ((memq frame-type '(x w32 ns))
9911648b
EZ
1315 (x-display-backing-store display))
1316 (t
1317 'not-useful))))
1318
aa360da1
GM
1319(declare-function x-display-save-under "xfns.c" (&optional terminal))
1320
9911648b
EZ
1321(defun display-save-under (&optional display)
1322 "Return non-nil if DISPLAY's screen supports the SaveUnder feature."
1323 (let ((frame-type (framep-on-display display)))
1324 (cond
9e2a2647 1325 ((memq frame-type '(x w32 ns))
9911648b
EZ
1326 (x-display-save-under display))
1327 (t
1328 'not-useful))))
1329
aa360da1
GM
1330(declare-function x-display-planes "xfns.c" (&optional terminal))
1331
9911648b
EZ
1332(defun display-planes (&optional display)
1333 "Return the number of planes supported by DISPLAY."
1334 (let ((frame-type (framep-on-display display)))
1335 (cond
9e2a2647 1336 ((memq frame-type '(x w32 ns))
9911648b
EZ
1337 (x-display-planes display))
1338 ((eq frame-type 'pc)
1339 4)
1340 (t
1341 (truncate (log (length (tty-color-alist)) 2))))))
1342
aa360da1
GM
1343(declare-function x-display-color-cells "xfns.c" (&optional terminal))
1344
9911648b
EZ
1345(defun display-color-cells (&optional display)
1346 "Return the number of color cells supported by DISPLAY."
1347 (let ((frame-type (framep-on-display display)))
1348 (cond
9e2a2647 1349 ((memq frame-type '(x w32 ns))
9911648b
EZ
1350 (x-display-color-cells display))
1351 ((eq frame-type 'pc)
1352 16)
1353 (t
3224dac1 1354 (tty-display-color-cells display)))))
9911648b 1355
aa360da1
GM
1356(declare-function x-display-visual-class "xfns.c" (&optional terminal))
1357
9911648b 1358(defun display-visual-class (&optional display)
6cda144f 1359 "Return the visual class of DISPLAY.
9911648b
EZ
1360The value is one of the symbols `static-gray', `gray-scale',
1361`static-color', `pseudo-color', `true-color', or `direct-color'."
1362 (let ((frame-type (framep-on-display display)))
1363 (cond
9e2a2647 1364 ((memq frame-type '(x w32 ns))
9911648b
EZ
1365 (x-display-visual-class display))
1366 ((and (memq frame-type '(pc t))
1367 (tty-display-color-p display))
1368 'static-color)
1369 (t
1370 'static-gray))))
1371
1372\f
a32c1804
RS
1373;;;; Frame geometry values
1374
1375(defun frame-geom-value-cons (type value &optional frame)
1376 "Return equivalent geometry value for FRAME as a cons with car `+'.
1377A geometry value equivalent to VALUE for FRAME is returned,
1378where the value is a cons with car `+', not numeric.
1379TYPE is the car of the original geometry spec (TYPE . VALUE).
1380 It is `top' or `left', depending on which edge VALUE is related to.
1381VALUE is the cdr of a frame geometry spec: (left/top . VALUE).
1382If VALUE is a number, then it is converted to a cons value, perhaps
1383 relative to the opposite frame edge from that in the original spec.
1384FRAME defaults to the selected frame.
1385
1386Examples (measures in pixels) -
1387 Assuming display height/width=1024, frame height/width=600:
1388 300 inside display edge: 300 => (+ 300)
1389 (+ 300) => (+ 300)
1390 300 inside opposite display edge: (- 300) => (+ 124)
1391 -300 => (+ 124)
1392 300 beyond display edge
1393 (= 724 inside opposite display edge): (+ -300) => (+ -300)
1394 300 beyond display edge
1395 (= 724 inside opposite display edge): (- -300) => (+ 724)
1396
1397In the 3rd, 4th, and 6th examples, the returned value is relative to
1398the opposite frame edge from the edge indicated in the input spec."
1399 (cond ((and (consp value) (eq '+ (car value))) ; e.g. (+ 300), (+ -300)
1400 value)
1401 ((natnump value) (list '+ value)) ; e.g. 300 => (+ 300)
1402 (t ; e.g. -300, (- 300), (- -300)
1403 (list '+ (- (if (eq 'left type) ; => (+ 124), (+ 124), (+ 724)
1404 (x-display-pixel-width)
1405 (x-display-pixel-height))
1406 (if (integerp value) (- value) (cadr value))
1407 (if (eq 'left type)
1408 (frame-pixel-width frame)
1409 (frame-pixel-height frame)))))))
1410
1411(defun frame-geom-spec-cons (spec &optional frame)
1412 "Return equivalent geometry spec for FRAME as a cons with car `+'.
1413A geometry specification equivalent to SPEC for FRAME is returned,
1414where the value is a cons with car `+', not numeric.
1415SPEC is a frame geometry spec: (left . VALUE) or (top . VALUE).
1416If VALUE is a number, then it is converted to a cons value, perhaps
1417 relative to the opposite frame edge from that in the original spec.
1418FRAME defaults to the selected frame.
1419
1420Examples (measures in pixels) -
1421 Assuming display height=1024, frame height=600:
1422 top 300 below display top: (top . 300) => (top + 300)
1423 (top + 300) => (top + 300)
1424 bottom 300 above display bottom: (top - 300) => (top + 124)
1425 (top . -300) => (top + 124)
1426 top 300 above display top
1427 (= bottom 724 above display bottom): (top + -300) => (top + -300)
1428 bottom 300 below display bottom
1429 (= top 724 below display top): (top - -300) => (top + 724)
1430
1431In the 3rd, 4th, and 6th examples, the returned value is relative to
1432the opposite frame edge from the edge indicated in the input spec."
1433 (cons (car spec) (frame-geom-value-cons (car spec) (cdr spec))))
1434\f
9e2b097b 1435
154a757e
GM
1436(defun delete-other-frames (&optional frame)
1437 "Delete all frames except FRAME.
a2125918
GM
1438If FRAME uses another frame's minibuffer, the minibuffer frame is
1439left untouched. FRAME nil or omitted means use the selected frame."
154a757e
GM
1440 (interactive)
1441 (unless frame
1442 (setq frame (selected-frame)))
a2125918
GM
1443 (let* ((mini-frame (window-frame (minibuffer-window frame)))
1444 (frames (delq mini-frame (delq frame (frame-list)))))
5e5ae184
SM
1445 ;; Only consider frames on the same terminal.
1446 (dolist (frame (prog1 frames (setq frames nil)))
1447 (if (eq (frame-terminal) (frame-terminal frame))
1448 (push frame frames)))
a2125918
GM
1449 ;; Delete mon-minibuffer-only frames first, because `delete-frame'
1450 ;; signals an error when trying to delete a mini-frame that's
1451 ;; still in use by another frame.
1452 (dolist (frame frames)
1453 (unless (eq (frame-parameter frame 'minibuffer) 'only)
1454 (delete-frame frame)))
1455 ;; Delete minibuffer-only frames.
1456 (dolist (frame frames)
1457 (when (eq (frame-parameter frame 'minibuffer) 'only)
1458 (delete-frame frame)))))
154a757e 1459
da7829a3 1460;; miscellaneous obsolescence declarations
84ed1560
JB
1461(define-obsolete-variable-alias 'delete-frame-hook
1462 'delete-frame-functions "22.1")
da7829a3 1463
dc6d9681 1464\f
7e573c4a 1465;; Highlighting trailing whitespace.
81b99826
GM
1466
1467(make-variable-buffer-local 'show-trailing-whitespace)
1468
1469(defcustom show-trailing-whitespace nil
6cda144f 1470 "Non-nil means highlight trailing whitespace.
e6c45c29 1471This is done in the face `trailing-whitespace'."
81b99826 1472 :type 'boolean
3a4f3a3b 1473 :safe 'booleanp
b4aefb19 1474 :group 'whitespace-faces)
81b99826
GM
1475
1476
1477\f
7e573c4a 1478;; Scrolling
79b14b94
GM
1479
1480(defgroup scrolling nil
1481 "Scrolling windows."
1482 :version "21.1"
1483 :group 'frames)
1484
968ecc28 1485(defcustom auto-hscroll-mode t
6cda144f 1486 "Allow or disallow automatic scrolling windows horizontally.
9ea60c46 1487If non-nil, windows are automatically scrolled horizontally to make
79b14b94
GM
1488point visible."
1489 :version "21.1"
1490 :type 'boolean
1491 :group 'scrolling)
968ecc28 1492(defvaralias 'automatic-hscrolling 'auto-hscroll-mode)
79b14b94
GM
1493
1494\f
7e573c4a 1495;; Blinking cursor
81b99826
GM
1496
1497(defgroup cursor nil
ca693be8 1498 "Displaying text cursors."
40d34803 1499 :version "21.1"
81b99826
GM
1500 :group 'frames)
1501
1502(defcustom blink-cursor-delay 0.5
6cda144f 1503 "Seconds of idle time after which cursor starts to blink."
81b99826
GM
1504 :type 'number
1505 :group 'cursor)
1506
1507(defcustom blink-cursor-interval 0.5
6cda144f 1508 "Length of cursor blink interval in seconds."
81b99826
GM
1509 :type 'number
1510 :group 'cursor)
1511
1512(defvar blink-cursor-idle-timer nil
ca693be8
GM
1513 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
1514The function `blink-cursor-start' is called when the timer fires.")
81b99826
GM
1515
1516(defvar blink-cursor-timer nil
ca693be8 1517 "Timer started from `blink-cursor-start'.
a795e09a
LT
1518This timer calls `blink-cursor-timer-function' every
1519`blink-cursor-interval' seconds.")
1520
81b99826 1521(defun blink-cursor-start ()
ca693be8
GM
1522 "Timer function called from the timer `blink-cursor-idle-timer'.
1523This starts the timer `blink-cursor-timer', which makes the cursor blink
1524if appropriate. It also arranges to cancel that timer when the next
1525command starts, by installing a pre-command hook."
81b99826 1526 (when (null blink-cursor-timer)
f9ac92c5
CY
1527 ;; Set up the timer first, so that if this signals an error,
1528 ;; blink-cursor-end is not added to pre-command-hook.
81b99826
GM
1529 (setq blink-cursor-timer
1530 (run-with-timer blink-cursor-interval blink-cursor-interval
f9ac92c5
CY
1531 'blink-cursor-timer-function))
1532 (add-hook 'pre-command-hook 'blink-cursor-end)
1533 (internal-show-cursor nil nil)))
0a5ebe4b
GM
1534
1535(defun blink-cursor-timer-function ()
1536 "Timer function of timer `blink-cursor-timer'."
1537 (internal-show-cursor nil (not (internal-show-cursor-p))))
81b99826
GM
1538
1539(defun blink-cursor-end ()
1540 "Stop cursor blinking.
ca693be8 1541This is installed as a pre-command hook by `blink-cursor-start'.
f39784dd 1542When run, it cancels the timer `blink-cursor-timer' and removes
ca693be8 1543itself as a pre-command hook."
81b99826 1544 (remove-hook 'pre-command-hook 'blink-cursor-end)
0a5ebe4b 1545 (internal-show-cursor nil t)
8ec94c16
SM
1546 (when blink-cursor-timer
1547 (cancel-timer blink-cursor-timer)
1548 (setq blink-cursor-timer nil)))
81b99826 1549
8ec94c16
SM
1550(define-minor-mode blink-cursor-mode
1551 "Toggle blinking cursor mode.
4837b516
GM
1552With a numeric argument, turn blinking cursor mode on if ARG is positive,
1553otherwise turn it off. When blinking cursor mode is enabled, the
1554cursor of the selected window blinks.
81b99826 1555
8ec94c16
SM
1556Note that this command is effective only when Emacs
1557displays through a window system, because then Emacs does its own
1558cursor display. On a text-only terminal, this is not implemented."
1559 :init-value (not (or noninteractive
1560 no-blinking-cursor
1561 (eq system-type 'ms-dos)
9e2a2647 1562 (not (memq window-system '(x w32)))))
adba8116 1563 :initialize 'custom-initialize-delay
8ec94c16
SM
1564 :group 'cursor
1565 :global t
1566 (if blink-cursor-idle-timer (cancel-timer blink-cursor-idle-timer))
1567 (setq blink-cursor-idle-timer nil)
1568 (blink-cursor-end)
1569 (when blink-cursor-mode
1570 ;; Hide the cursor.
1571 ;;(internal-show-cursor nil nil)
1572 (setq blink-cursor-idle-timer
1573 (run-with-idle-timer blink-cursor-delay
1574 blink-cursor-delay
1575 'blink-cursor-start))))
81b99826 1576
8ec94c16 1577(define-obsolete-variable-alias 'blink-cursor 'blink-cursor-mode "22.1")
81b99826 1578\f
7e573c4a 1579;; Hourglass pointer
81b99826 1580
a6c411ff 1581(defcustom display-hourglass t
6cda144f 1582 "Non-nil means show an hourglass pointer, when Emacs is busy.
088e75cc
RS
1583This feature only works when on a window system that can change
1584cursor shapes."
81b99826 1585 :type 'boolean
a6c411ff 1586 :group 'cursor)
81b99826 1587
a6c411ff 1588(defcustom hourglass-delay 1
6cda144f 1589 "Seconds to wait before displaying an hourglass pointer when Emacs is busy."
0a86e779 1590 :type 'number
a6c411ff 1591 :group 'cursor)
1d0a3ef4 1592
5b2c5477 1593\f
c0eb3c10 1594(defcustom cursor-in-non-selected-windows t
6cda144f 1595 "Non-nil means show a hollow box cursor in non-selected windows.
e053c60f 1596If nil, don't show a cursor except in the selected window.
772e490c
RS
1597If t, display a cursor related to the usual cursor type
1598 \(a solid box becomes hollow, a bar becomes a narrower bar).
1599You can also specify the cursor type as in the `cursor-type' variable.
f39784dd 1600Use Custom to set this variable to get the display updated."
63ec4f94 1601 :tag "Cursor In Non-selected Windows"
5b2c5477
GM
1602 :type 'boolean
1603 :group 'cursor
5b2c5477
GM
1604 :set #'(lambda (symbol value)
1605 (set-default symbol value)
5b2c5477 1606 (force-mode-line-update t)))
f39784dd 1607
81b99826 1608\f
64c669bc 1609;;;; Key bindings
64c669bc 1610
6238bfaf 1611(define-key ctl-x-5-map "2" 'make-frame-command)
154a757e 1612(define-key ctl-x-5-map "1" 'delete-other-frames)
dc6d9681 1613(define-key ctl-x-5-map "0" 'delete-frame)
ceab6935 1614(define-key ctl-x-5-map "o" 'other-frame)
49116ac0 1615
dc6d9681 1616(provide 'frame)
c88ab9ce 1617
485464c4 1618;; arch-tag: 82979c70-b8f2-4306-b2ad-ddbd6b328b56
dc6d9681 1619;;; frame.el ends here