(proced-sort-header): New face.
[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,
409cc4a3 4;; 2004, 2005, 2006, 2007, 2008 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
eb3fa2cf 11;; GNU Emacs is free software: you can redistribute it and/or modify
b578f267 12;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
b578f267
EN
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
eb3fa2cf 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
64c669bc 23
55535639
PJ
24;;; Commentary:
25
fc68affa
ER
26;;; Code:
27
2246281f
KL
28(defvar frame-creation-function-alist
29 (list (cons nil
30 (if (fboundp 'tty-create-frame-with-faces)
31 'tty-create-frame-with-faces
371fed4e
SM
32 (lambda (parameters)
33 (error "Can't create multiple frames without a window system")))))
2246281f
KL
34 "Alist of window-system dependent functions to call to create a new frame.
35The window system startup file should add its frame creation
36function to this list, which should take an alist of parameters
37as its argument.")
114a8b8c 38
bf1ba39f
KL
39(defvar window-system-default-frame-alist nil
40 "Alist of window-system dependent default frame parameters.
095fe281 41You can set this in your `.emacs' file; for example,
bf1ba39f
KL
42
43 ;; Disable menubar and toolbar on the console, but enable them under X.
44 (setq window-system-default-frame-alist
45 '((x (menu-bar-lines . 1) (tool-bar-lines . 1))
46 (nil (menu-bar-lines . 0) (tool-bar-lines . 0))))
47
095fe281 48Parameters specified here supersede the values given in `default-frame-alist'.")
bf1ba39f 49
7e573c4a
SM
50;; The initial value given here used to ask for a minibuffer.
51;; But that's not necessary, because the default is to have one.
52;; By not specifying it here, we let an X resource specify it.
0c966f88 53(defcustom initial-frame-alist nil
0b9d32af 54 "*Alist of frame parameters for creating the initial X window frame.
eaa974e1 55You can set this in your `.emacs' file; for example,
dc6d9681 56 (setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55)))
de17da15
RS
57Parameters specified here supersede the values given in `default-frame-alist'.
58
59If the value calls for a frame without a minibuffer, and you have not created
60a minibuffer frame on your own, one is created according to
7eadab74 61`minibuffer-frame-alist'.
de17da15
RS
62
63You can specify geometry-related options for just the initial frame
64by setting this variable in your `.emacs' file; however, they won't
85557d7e 65take effect until Emacs reads `.emacs', which happens after first creating
de17da15
RS
66the frame. If you want the frame to have the proper geometry as soon
67as it appears, you need to use this three-step process:
68* Specify X resources to give the geometry you want.
69* Set `default-frame-alist' to override these options so that they
70 don't affect subsequent frames.
71* Set `initial-frame-alist' in a way that matches the X resources,
0c966f88
RS
72 to override what you put in `default-frame-alist'."
73 :type '(repeat (cons :format "%v"
74 (symbol :tag "Parameter")
75 (sexp :tag "Value")))
76 :group 'frames)
64c669bc 77
0b9d32af
RS
78(defcustom minibuffer-frame-alist '((width . 80) (height . 2))
79 "*Alist of frame parameters for initially creating a minibuffer frame.
eaa974e1 80You can set this in your `.emacs' file; for example,
dc6d9681 81 (setq minibuffer-frame-alist
7eadab74 82 '((top . 1) (left . 1) (width . 80) (height . 2)))
eaa974e1 83Parameters specified here supersede the values given in
0b9d32af
RS
84`default-frame-alist', for a minibuffer frame."
85 :type '(repeat (cons :format "%v"
86 (symbol :tag "Parameter")
87 (sexp :tag "Value")))
88 :group 'frames)
64c669bc 89
0b9d32af
RS
90(defcustom pop-up-frame-alist nil
91 "*Alist of frame parameters used when creating pop-up frames.
dc6d9681 92Pop-up frames are used for completions, help, and the like.
64c669bc 93This variable can be set in your init file, like this:
dc6d9681 94 (setq pop-up-frame-alist '((width . 80) (height . 20)))
0b9d32af
RS
95These supersede the values given in `default-frame-alist',
96for pop-up frames."
97 :type '(repeat (cons :format "%v"
98 (symbol :tag "Parameter")
99 (sexp :tag "Value")))
100 :group 'frames)
64c669bc 101
25831d66
MR
102(defcustom pop-up-frame-function
103 (lambda () (make-frame pop-up-frame-alist))
104 "Function to call to handle automatic new frame creation.
105It is called with no arguments and should return a newly created frame."
106 :type '(choice (const nil) (function :tag "function"))
107 :group 'frames)
64c669bc 108
30e19aee 109(defcustom special-display-frame-alist
8a9e86e6
RS
110 '((height . 14) (width . 80) (unsplittable . t))
111 "*Alist of frame parameters used when creating special frames.
112Special frames are used for buffers whose names are in
113`special-display-buffer-names' and for buffers whose names match
114one of the regular expressions in `special-display-regexps'.
115This variable can be set in your init file, like this:
116 (setq special-display-frame-alist '((width . 80) (height . 20)))
30e19aee
RS
117These supersede the values given in `default-frame-alist'."
118 :type '(repeat (cons :format "%v"
119 (symbol :tag "Parameter")
120 (sexp :tag "Value")))
121 :group 'frames)
8a9e86e6 122
95e6cf39 123(defun special-display-popup-frame (buffer &optional args)
40d34803
DL
124 "Display BUFFER in its own frame, reusing an existing window if any.
125Return the window chosen.
126Currently we do not insist on selecting the window within its frame.
127If ARGS is an alist, use it as a list of frame parameter specs.
128If ARGS is a list whose car is a symbol,
129use (car ARGS) as a function to do the work.
130Pass it BUFFER as first arg, and (cdr ARGS) gives the rest of the args."
95e6cf39
RS
131 (if (and args (symbolp (car args)))
132 (apply (car args) buffer (cdr args))
bb2c34b1 133 (let ((window (get-buffer-window buffer 0)))
7e573c4a
SM
134 (or
135 ;; If we have a window already, make it visible.
136 (when window
137 (let ((frame (window-frame window)))
138 (make-frame-visible frame)
139 (raise-frame frame)
140 window))
141 ;; Reuse the current window if the user requested it.
142 (when (cdr (assq 'same-window args))
143 (condition-case nil
144 (progn (switch-to-buffer buffer) (selected-window))
145 (error nil)))
146 ;; Stay on the same frame if requested.
147 (when (or (cdr (assq 'same-frame args)) (cdr (assq 'same-window args)))
148 (let* ((pop-up-frames nil) (pop-up-windows t)
149 special-display-regexps special-display-buffer-names
150 (window (display-buffer buffer)))
bb2c34b1 151 ;; Only do it if this is a new window:
7e573c4a
SM
152 ;; (set-window-dedicated-p window t)
153 window))
154 ;; If no window yet, make one in a new frame.
bf247b6e 155 (let ((frame
86bd482f
RS
156 (with-current-buffer buffer
157 (make-frame (append args special-display-frame-alist)))))
7e573c4a
SM
158 (set-window-buffer (frame-selected-window frame) buffer)
159 (set-window-dedicated-p (frame-selected-window frame) t)
160 (frame-selected-window frame))))))
8a9e86e6 161
924be53a 162(defun handle-delete-frame (event)
40d34803 163 "Handle delete-frame events from the X server."
924be53a
RS
164 (interactive "e")
165 (let ((frame (posn-window (event-start event)))
166 (i 0)
167 (tail (frame-list)))
168 (while tail
169 (and (frame-visible-p (car tail))
170 (not (eq (car tail) frame))
171 (setq i (1+ i)))
172 (setq tail (cdr tail)))
173 (if (> i 0)
174 (delete-frame frame t)
a9562d19
RS
175 ;; Gildea@x.org says it is ok to ask questions before terminating.
176 (save-buffers-kill-emacs))))
64c669bc 177\f
dc6d9681 178;;;; Arrangement of frames at startup
64c669bc 179
7e573c4a
SM
180;; 1) Load the window system startup file from the lisp library and read the
181;; high-priority arguments (-q and the like). The window system startup
182;; file should create any frames specified in the window system defaults.
183;;
184;; 2) If no frames have been opened, we open an initial text frame.
185;;
186;; 3) Once the init file is done, we apply any newly set parameters
187;; in initial-frame-alist to the frame.
64c669bc 188
85557d7e 189;; These are now called explicitly at the proper times,
fc4d4afb
RS
190;; since that is easier to understand.
191;; Actually using hooks within Emacs is bad for future maintenance. --rms.
192;; (add-hook 'before-init-hook 'frame-initialize)
193;; (add-hook 'window-setup-hook 'frame-notice-user-settings)
64c669bc 194
7e573c4a 195;; If we create the initial frame, this is it.
dc6d9681 196(defvar frame-initial-frame nil)
64c669bc 197
3f2f8c83
RS
198;; Record the parameters used in frame-initialize to make the initial frame.
199(defvar frame-initial-frame-alist)
200
791e09d8
RS
201(defvar frame-initial-geometry-arguments nil)
202
7e573c4a
SM
203;; startup.el calls this function before loading the user's init
204;; file - if there is no frame with a minibuffer open now, create
205;; one to display messages while loading the init file.
dc6d9681 206(defun frame-initialize ()
ff2a1c79 207 "Create an initial frame if necessary."
64c669bc 208 ;; Are we actually running under a window system at all?
2246281f
KL
209 (if (and initial-window-system
210 (not noninteractive)
211 (not (eq initial-window-system 'pc)))
7eadab74 212 (progn
62642af9
RS
213 ;; Turn on special-display processing only if there's a window system.
214 (setq special-display-function 'special-display-popup-frame)
215
7eadab74
JB
216 ;; If there is no frame with a minibuffer besides the terminal
217 ;; frame, then we need to create the opening frame. Make sure
218 ;; it has a minibuffer, but let initial-frame-alist omit the
219 ;; minibuffer spec.
220 (or (delq terminal-frame (minibuffer-frame-list))
36fc9c9f 221 (progn
3f2f8c83 222 (setq frame-initial-frame-alist
9688894d 223 (append initial-frame-alist default-frame-alist nil))
a8bb5882
RS
224 (or (assq 'horizontal-scroll-bars frame-initial-frame-alist)
225 (setq frame-initial-frame-alist
226 (cons '(horizontal-scroll-bars . t)
227 frame-initial-frame-alist)))
2246281f
KL
228 (setq frame-initial-frame-alist
229 (cons (cons 'window-system initial-window-system)
230 frame-initial-frame-alist))
36fc9c9f
RS
231 (setq default-minibuffer-frame
232 (setq frame-initial-frame
96a84970 233 (make-frame frame-initial-frame-alist)))
11281034
RS
234 ;; Delete any specifications for window geometry parameters
235 ;; so that we won't reapply them in frame-notice-user-settings.
236 ;; It would be wrong to reapply them then,
237 ;; because that would override explicit user resizing.
58bf6042 238 (setq initial-frame-alist
c2079f0a 239 (frame-remove-geometry-params initial-frame-alist))))
a13f8f50
KL
240 ;; Copy the environment of the Emacs process into the new frame.
241 (set-frame-parameter frame-initial-frame 'environment
242 (frame-parameter terminal-frame 'environment))
85557d7e 243 ;; At this point, we know that we have a frame open, so we
dc6d9681
JB
244 ;; can delete the terminal frame.
245 (delete-frame terminal-frame)
2246281f 246 (setq terminal-frame nil))))
85557d7e 247
8f2a992b
GM
248(defvar frame-notice-user-settings t
249 "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
250
aa360da1
GM
251(declare-function tool-bar-mode "tool-bar" (&optional arg))
252
7e573c4a
SM
253;; startup.el calls this function after loading the user's init
254;; file. Now default-frame-alist and initial-frame-alist contain
255;; information to which we must react; do what needs to be done.
dc6d9681 256(defun frame-notice-user-settings ()
40d34803 257 "Act on user's init file settings of frame parameters.
0e1bfc78
KL
258React to settings of `initial-frame-alist',
259`window-system-default-frame-alist' and `default-frame-alist'
260there (in decreasing order of priority)."
2ffa6186 261 ;; Make menu-bar-mode and default-frame-alist consistent.
61f2bcd7
GM
262 (when (boundp 'menu-bar-mode)
263 (let ((default (assq 'menu-bar-lines default-frame-alist)))
264 (if default
265 (setq menu-bar-mode (not (eq (cdr default) 0)))
266 (setq default-frame-alist
267 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
268 default-frame-alist)))))
f39784dd 269
33a33c06
GM
270 ;; Make tool-bar-mode and default-frame-alist consistent. Don't do
271 ;; it in batch mode since that would leave a tool-bar-lines
272 ;; parameter in default-frame-alist in a dumped Emacs, which is not
9688894d 273 ;; what we want.
33a33c06 274 (when (and (boundp 'tool-bar-mode)
095fe281 275 (not noninteractive))
61f2bcd7
GM
276 (let ((default (assq 'tool-bar-lines default-frame-alist)))
277 (if default
095fe281
KL
278 (setq tool-bar-mode (not (eq (cdr default) 0)))
279 ;; If Emacs was started on a tty, changing default-frame-alist
280 ;; would disable the toolbar on X frames created later. We
281 ;; want to keep the default of showing a toolbar under X even
282 ;; in this case.
283 ;;
284 ;; If the user explicitly called `tool-bar-mode' in .emacs,
285 ;; then default-frame-alist is already changed anyway.
286 (when initial-window-system
287 (setq default-frame-alist
288 (cons (cons 'tool-bar-lines (if tool-bar-mode 1 0))
289 default-frame-alist))))))
2ffa6186 290
7eadab74
JB
291 ;; Creating and deleting frames may shift the selected frame around,
292 ;; and thus the current buffer. Protect against that. We don't
293 ;; want to use save-excursion here, because that may also try to set
294 ;; the buffer of the selected window, which fails when the selected
295 ;; window is the minibuffer.
0e1bfc78 296 (let ((old-buffer (current-buffer))
cb01ce3f
SM
297 (window-system-frame-alist
298 (cdr (assq initial-window-system
299 window-system-default-frame-alist))))
7eadab74 300
8f2a992b
GM
301 (when (and frame-notice-user-settings
302 (null frame-initial-frame))
42002db5
EZ
303 ;; This case happens when we don't have a window system, and
304 ;; also for MS-DOS frames.
8f2a992b
GM
305 (let ((parms (frame-parameters frame-initial-frame)))
306 ;; Don't change the frame names.
307 (setq parms (delq (assq 'name parms) parms))
308 ;; Can't modify the minibuffer parameter, so don't try.
309 (setq parms (delq (assq 'minibuffer parms) parms))
310 (modify-frame-parameters nil
2246281f 311 (if (null initial-window-system)
42002db5 312 (append initial-frame-alist
0e1bfc78 313 window-system-frame-alist
42002db5
EZ
314 default-frame-alist
315 parms
316 nil)
317 ;; initial-frame-alist and
318 ;; default-frame-alist were already
319 ;; applied in pc-win.el.
320 parms))
2246281f 321 (if (null initial-window-system) ;; MS-DOS does this differently in pc-win.el
42002db5
EZ
322 (let ((newparms (frame-parameters))
323 (frame (selected-frame)))
324 (tty-handle-reverse-video frame newparms)
325 ;; If we changed the background color, we need to update
326 ;; the background-mode parameter, and maybe some faces,
327 ;; too.
328 (when (assq 'background-color newparms)
329 (unless (or (assq 'background-mode initial-frame-alist)
330 (assq 'background-mode default-frame-alist))
331 (frame-set-background-mode frame))
332 (face-set-after-frame-default frame))))))
8f2a992b 333
7eadab74
JB
334 ;; If the initial frame is still around, apply initial-frame-alist
335 ;; and default-frame-alist to it.
9688894d
GM
336 (when (frame-live-p frame-initial-frame)
337
338 ;; When tool-bar has been switched off, correct the frame size
339 ;; by the lines added in x-create-frame for the tool-bar and
340 ;; switch `tool-bar-mode' off.
085ef9b3
GM
341 (when (display-graphic-p)
342 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
0e1bfc78 343 (assq 'tool-bar-lines window-system-frame-alist)
085ef9b3 344 (assq 'tool-bar-lines default-frame-alist))))
5c39a60f
JR
345 (when (and tool-bar-originally-present
346 (or (null tool-bar-lines)
347 (null (cdr tool-bar-lines))
348 (eq 0 (cdr tool-bar-lines))))
085ef9b3 349 (let* ((char-height (frame-char-height frame-initial-frame))
5c39a60f 350 (image-height tool-bar-images-pixel-height)
085ef9b3
GM
351 (margin (cond ((and (consp tool-bar-button-margin)
352 (integerp (cdr tool-bar-button-margin))
353 (> tool-bar-button-margin 0))
354 (cdr tool-bar-button-margin))
355 ((and (integerp tool-bar-button-margin)
356 (> tool-bar-button-margin 0))
357 tool-bar-button-margin)
358 (t 0)))
359 (relief (if (and (integerp tool-bar-button-relief)
360 (> tool-bar-button-relief 0))
361 tool-bar-button-relief 3))
f39784dd 362 (lines (/ (+ image-height
085ef9b3
GM
363 (* 2 margin)
364 (* 2 relief)
365 (1- char-height))
366 char-height))
367 (height (frame-parameter frame-initial-frame 'height))
368 (newparms (list (cons 'height (- height lines))))
f39784dd 369 (initial-top (cdr (assq 'top
085ef9b3
GM
370 frame-initial-geometry-arguments)))
371 (top (frame-parameter frame-initial-frame 'top)))
372 (when (and (consp initial-top) (eq '- (car initial-top)))
7f18ce22
RS
373 (let ((adjusted-top
374 (cond ((and (consp top)
375 (eq '+ (car top)))
376 (list '+
377 (+ (cadr top)
378 (* lines char-height))))
379 ((and (consp top)
380 (eq '- (car top)))
381 (list '-
382 (- (cadr top)
383 (* lines char-height))))
384 (t (+ top (* lines char-height))))))
385 (setq newparms
386 (append newparms
387 `((top . ,adjusted-top))
388 nil))))
085ef9b3
GM
389 (modify-frame-parameters frame-initial-frame newparms)
390 (tool-bar-mode -1)))))
9688894d
GM
391
392 ;; The initial frame we create above always has a minibuffer.
393 ;; If the user wants to remove it, or make it a minibuffer-only
394 ;; frame, then we'll have to delete the current frame and make a
395 ;; new one; you can't remove or add a root window to/from an
396 ;; existing frame.
397 ;;
398 ;; NOTE: default-frame-alist was nil when we created the
399 ;; existing frame. We need to explicitly include
400 ;; default-frame-alist in the parameters of the screen we
401 ;; create here, so that its new value, gleaned from the user's
402 ;; .emacs file, will be applied to the existing screen.
de2f5dbe 403 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
0e1bfc78 404 (assq 'minibuffer window-system-frame-alist)
de2f5dbe
GM
405 (assq 'minibuffer default-frame-alist)
406 '(minibuffer . t)))
407 t))
408 ;; Create the new frame.
409 (let (parms new)
410 ;; If the frame isn't visible yet, wait till it is.
411 ;; If the user has to position the window,
412 ;; Emacs doesn't know its real position until
413 ;; the frame is seen to be visible.
414 (while (not (cdr (assq 'visibility
415 (frame-parameters frame-initial-frame))))
416 (sleep-for 1))
417 (setq parms (frame-parameters frame-initial-frame))
9688894d 418
f39784dd 419 ;; Get rid of `name' unless it was specified explicitly before.
de2f5dbe
GM
420 (or (assq 'name frame-initial-frame-alist)
421 (setq parms (delq (assq 'name parms) parms)))
2f5bb432
SM
422 ;; An explicit parent-id is a request to XEmbed the frame.
423 (or (assq 'parent-id frame-initial-frame-alist)
424 (setq parms (delq (assq 'parent-id parms) parms)))
de2f5dbe
GM
425
426 (setq parms (append initial-frame-alist
0e1bfc78 427 window-system-frame-alist
de2f5dbe
GM
428 default-frame-alist
429 parms
430 nil))
431
432 ;; Get rid of `reverse', because that was handled
433 ;; when we first made the frame.
434 (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
435
436 (if (assq 'height frame-initial-geometry-arguments)
437 (setq parms (assq-delete-all 'height parms)))
438 (if (assq 'width frame-initial-geometry-arguments)
439 (setq parms (assq-delete-all 'width parms)))
440 (if (assq 'left frame-initial-geometry-arguments)
441 (setq parms (assq-delete-all 'left parms)))
442 (if (assq 'top frame-initial-geometry-arguments)
443 (setq parms (assq-delete-all 'top parms)))
444 (setq new
445 (make-frame
446 ;; Use the geometry args that created the existing
447 ;; frame, rather than the parms we get for it.
448 (append frame-initial-geometry-arguments
449 '((user-size . t) (user-position . t))
450 parms)))
451 ;; The initial frame, which we are about to delete, may be
452 ;; the only frame with a minibuffer. If it is, create a
453 ;; new one.
454 (or (delq frame-initial-frame (minibuffer-frame-list))
455 (make-initial-minibuffer-frame nil))
456
457 ;; If the initial frame is serving as a surrogate
458 ;; minibuffer frame for any frames, we need to wean them
459 ;; onto a new frame. The default-minibuffer-frame
460 ;; variable must be handled similarly.
461 (let ((users-of-initial
462 (filtered-frame-list
b7de6024
SM
463 (lambda (frame)
464 (and (not (eq frame frame-initial-frame))
465 (eq (window-frame
466 (minibuffer-window frame))
467 frame-initial-frame))))))
468 (if (or users-of-initial
de2f5dbe
GM
469 (eq default-minibuffer-frame frame-initial-frame))
470
471 ;; Choose an appropriate frame. Prefer frames which
472 ;; are only minibuffers.
473 (let* ((new-surrogate
474 (car
475 (or (filtered-frame-list
b7de6024
SM
476 (lambda (frame)
477 (eq (cdr (assq 'minibuffer
478 (frame-parameters frame)))
479 'only)))
de2f5dbe
GM
480 (minibuffer-frame-list))))
481 (new-minibuffer (minibuffer-window new-surrogate)))
482
483 (if (eq default-minibuffer-frame frame-initial-frame)
484 (setq default-minibuffer-frame new-surrogate))
485
486 ;; Wean the frames using frame-initial-frame as
487 ;; their minibuffer frame.
b7de6024
SM
488 (dolist (frame users-of-initial)
489 (modify-frame-parameters
490 frame (list (cons 'minibuffer new-minibuffer)))))))
491
492 ;; Redirect events enqueued at this frame to the new frame.
de2f5dbe
GM
493 ;; Is this a good idea?
494 (redirect-frame-focus frame-initial-frame new)
495
496 ;; Finally, get rid of the old frame.
497 (delete-frame frame-initial-frame t))
9688894d
GM
498
499 ;; Otherwise, we don't need all that rigamarole; just apply
500 ;; the new parameters.
501 (let (newparms allparms tail)
502 (setq allparms (append initial-frame-alist
0e1bfc78 503 window-system-frame-alist
9688894d
GM
504 default-frame-alist nil))
505 (if (assq 'height frame-initial-geometry-arguments)
506 (setq allparms (assq-delete-all 'height allparms)))
507 (if (assq 'width frame-initial-geometry-arguments)
508 (setq allparms (assq-delete-all 'width allparms)))
509 (if (assq 'left frame-initial-geometry-arguments)
510 (setq allparms (assq-delete-all 'left allparms)))
511 (if (assq 'top frame-initial-geometry-arguments)
512 (setq allparms (assq-delete-all 'top allparms)))
513 (setq tail allparms)
514 ;; Find just the parms that have changed since we first
515 ;; made this frame. Those are the ones actually set by
f39784dd 516 ;; the init file. For those parms whose values we already knew
9688894d
GM
517 ;; (such as those spec'd by command line options)
518 ;; it is undesirable to specify the parm again
f39784dd 519 ;; once the user has seen the frame and been able to alter it
9688894d
GM
520 ;; manually.
521 (while tail
522 (let (newval oldval)
523 (setq oldval (assq (car (car tail))
524 frame-initial-frame-alist))
525 (setq newval (cdr (assq (car (car tail)) allparms)))
526 (or (and oldval (eq (cdr oldval) newval))
527 (setq newparms
528 (cons (cons (car (car tail)) newval) newparms))))
529 (setq tail (cdr tail)))
530 (setq newparms (nreverse newparms))
531 (modify-frame-parameters frame-initial-frame
532 newparms)
533 ;; If we changed the background color,
534 ;; we need to update the background-mode parameter
535 ;; and maybe some faces too.
536 (when (assq 'background-color newparms)
537 (unless (assq 'background-mode newparms)
538 (frame-set-background-mode frame-initial-frame))
539 (face-set-after-frame-default frame-initial-frame)))))
64c669bc 540
7eadab74
JB
541 ;; Restore the original buffer.
542 (set-buffer old-buffer)
543
544 ;; Make sure the initial frame can be GC'd if it is ever deleted.
d202f1f2 545 ;; Make sure frame-notice-user-settings does nothing if called twice.
8f2a992b 546 (setq frame-notice-user-settings nil)
d202f1f2 547 (setq frame-initial-frame nil)))
64c669bc 548
746bd265
KH
549(defun make-initial-minibuffer-frame (display)
550 (let ((parms (append minibuffer-frame-alist '((minibuffer . only)))))
551 (if display
552 (make-frame-on-display display parms)
553 (make-frame parms))))
554
7eadab74 555;;;; Creation of additional frames, and other frame miscellanea
dc6d9681 556
63019bad 557(defun modify-all-frames-parameters (alist)
d398de43 558 "Modify all current and future frames' parameters according to ALIST.
63019bad 559This changes `default-frame-alist' and possibly `initial-frame-alist'.
095fe281
KL
560Furthermore, this function removes all parameters in ALIST from
561`window-system-default-frame-alist'.
63019bad 562See help of `modify-frame-parameters' for more information."
095fe281
KL
563 (dolist (frame (frame-list))
564 (modify-frame-parameters frame alist))
565
566 (dolist (pair alist) ;; conses to add/replace
567 ;; initial-frame-alist needs setting only when
568 ;; frame-notice-user-settings is true.
569 (and frame-notice-user-settings
570 (setq initial-frame-alist
571 (assq-delete-all (car pair) initial-frame-alist)))
572 (setq default-frame-alist
573 (assq-delete-all (car pair) default-frame-alist))
574 ;; Remove any similar settings from the window-system specific
575 ;; parameters---they would override default-frame-alist.
576 (dolist (w window-system-default-frame-alist)
577 (setcdr w (assq-delete-all (car pair) (cdr w)))))
578
63019bad
JB
579 (and frame-notice-user-settings
580 (setq initial-frame-alist (append initial-frame-alist alist)))
581 (setq default-frame-alist (append default-frame-alist alist)))
582
7253d8e0 583(defun get-other-frame ()
40d34803
DL
584 "Return some frame other than the current frame.
585Create one if necessary. Note that the minibuffer frame, if separate,
586is not considered (see `next-frame')."
dc6d9681 587 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
6eb018ba 588 (make-frame)
dc6d9681 589 (next-frame (selected-frame)))))
64c669bc
JB
590 s))
591
dc6d9681
JB
592(defun next-multiframe-window ()
593 "Select the next window, regardless of which frame it is on."
64c669bc
JB
594 (interactive)
595 (select-window (next-window (selected-window)
596 (> (minibuffer-depth) 0)
bb2c34b1 597 0))
030f4537 598 (select-frame-set-input-focus (selected-frame)))
64c669bc 599
dc6d9681
JB
600(defun previous-multiframe-window ()
601 "Select the previous window, regardless of which frame it is on."
64c669bc
JB
602 (interactive)
603 (select-window (previous-window (selected-window)
604 (> (minibuffer-depth) 0)
bb2c34b1 605 0))
030f4537 606 (select-frame-set-input-focus (selected-frame)))
64c669bc 607
bbf6ef44 608(declare-function x-initialize-window-system "term/x-win" ())
4c1863cd 609(declare-function ns-initialize-window-system "term/ns-win" ())
5f9214ee 610(defvar x-display-name) ; term/x-win
bbf6ef44 611
6d73e337 612(defun make-frame-on-display (display &optional parameters)
b6660415 613 "Make a frame on X display DISPLAY.
6d73e337
RS
614The optional second argument PARAMETERS specifies additional frame parameters."
615 (interactive "sMake frame on display: ")
601fb9b8 616 (if (featurep 'ns)
edfda783
AR
617 (progn
618 (when (and (boundp 'ns-initialized) (not ns-initialized))
5f2aebc0 619 (setq x-display-name display)
edfda783
AR
620 (ns-initialize-window-system))
621 (make-frame `((window-system . ns) (display . ,display) . ,parameters)))
622 (progn
5f2aebc0
DN
623 (unless (string-match "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display)
624 (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
edfda783
AR
625 (when (and (boundp 'x-initialized) (not x-initialized))
626 (setq x-display-name display)
627 (x-initialize-window-system))
628 (make-frame `((window-system . x) (display . ,display) . ,parameters)))))
6d73e337 629
f35ca2fe
KL
630(defun make-frame-on-tty (tty type &optional parameters)
631 "Make a frame on terminal device TTY.
632TTY should be the file name of the tty device to use. TYPE
633should be the terminal type string of TTY, for example \"xterm\"
634or \"vt100\". The optional third argument PARAMETERS specifies
635additional frame parameters."
428a555e 636 (interactive "fOpen frame on tty device: \nsTerminal type of %s: ")
f35ca2fe 637 (unless tty
fca177d4
KL
638 (error "Invalid terminal device"))
639 (unless type
640 (error "Invalid terminal type"))
f35ca2fe 641 (make-frame `((window-system . nil) (tty . ,tty) (tty-type . ,type) . ,parameters)))
fca177d4 642
aa360da1
GM
643(declare-function x-close-connection "xfns.c" (terminal))
644
b7de6024
SM
645(defun close-display-connection (display)
646 "Close the connection to a display, deleting all its associated frames.
647For DISPLAY, specify either a frame or a display name (a string).
648If DISPLAY is nil, that stands for the selected frame's display."
649 (interactive
650 (list
651 (let* ((default (frame-parameter nil 'display))
652 (display (completing-read
653 (format "Close display (default %s): " default)
654 (delete-dups
655 (mapcar (lambda (frame)
656 (frame-parameter frame 'display))
657 (frame-list)))
658 nil t nil nil
659 default)))
660 (if (zerop (length display)) default display))))
661 (let ((frames (delq nil
662 (mapcar (lambda (frame)
663 (if (equal display
664 (frame-parameter frame 'display))
665 frame))
666 (frame-list)))))
667 (if (and (consp frames)
668 (not (y-or-n-p (if (cdr frames)
669 (format "Delete %s frames? " (length frames))
670 (format "Delete %s ? " (car frames))))))
671 (error "Abort!")
672 (mapc 'delete-frame frames)
673 (x-close-connection display))))
674
6238bfaf
RS
675(defun make-frame-command ()
676 "Make a new frame, and select it if the terminal displays only one frame."
677 (interactive)
c1b1350b 678 (if (and window-system (not (eq window-system 'pc)))
6238bfaf
RS
679 (make-frame)
680 (select-frame (make-frame))))
681
45c4fdeb
SM
682(defvar before-make-frame-hook nil
683 "Functions to run before a frame is created.")
684
685(defvar after-make-frame-functions nil
686 "Functions to run after a frame is created.
687The functions are run with one arg, the newly created frame.")
688
72bf1a8b 689(defvar after-setting-font-hook nil
81b99826
GM
690 "Functions to run after a frame's font has been changed.")
691
92e443b1 692;; Alias, kept temporarily.
84ed1560 693(define-obsolete-function-alias 'new-frame 'make-frame "22.1")
bc93c097 694
9e483377 695(defvar frame-inherited-parameters '()
ab6198b2
SM
696 ;; FIXME: Shouldn't we add `font' here as well?
697 "Parameters `make-frame' copies from the `selected-frame' to the new frame.")
698
45c4fdeb
SM
699(defun make-frame (&optional parameters)
700 "Return a newly created frame displaying the current buffer.
701Optional argument PARAMETERS is an alist of parameters for the new frame.
702Each element of PARAMETERS should have the form (NAME . VALUE), for example:
a105105a 703
45c4fdeb 704 (name . STRING) The frame should be named STRING.
43a2e52c 705
45c4fdeb
SM
706 (width . NUMBER) The frame should be NUMBER characters in width.
707 (height . NUMBER) The frame should be NUMBER text lines high.
43a2e52c 708
45c4fdeb 709You cannot specify either `width' or `height', you must use neither or both.
43a2e52c 710
45c4fdeb
SM
711 (minibuffer . t) The frame should have a minibuffer.
712 (minibuffer . nil) The frame should have no minibuffer.
713 (minibuffer . only) The frame should contain only a minibuffer.
714 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
43a2e52c 715
2246281f
KL
716 (window-system . nil) The frame should be displayed on a terminal device.
717 (window-system . x) The frame should be displayed in an X window.
718
6ed8eeff 719 (terminal . ID) The frame should use the terminal identified by ID.
b6660415 720
2246281f 721Before the frame is created (via `frame-creation-function-alist'), functions on the
45c4fdeb 722hook `before-make-frame-hook' are run. After the frame is created, functions
8de9d3f6
LT
723on `after-make-frame-functions' are run with one arg, the newly created frame.
724
725This function itself does not make the new frame the selected frame.
726The previously selected frame remains selected. However, the
727window system may select the new frame for its own reasons, for
728instance if the frame appears under the mouse pointer and your
729setup is for focus to follow the pointer."
64c669bc 730 (interactive)
b6660415 731 (let* ((w (cond
6ed8eeff
KL
732 ((assq 'terminal parameters)
733 (let ((type (terminal-live-p (cdr (assq 'terminal parameters)))))
b6660415
KL
734 (cond
735 ((eq type t) nil)
cb01ce3f
SM
736 ((eq type nil) (error "Terminal %s does not exist"
737 (cdr (assq 'terminal parameters))))
b6660415
KL
738 (t type))))
739 ((assq 'window-system parameters)
740 (cdr (assq 'window-system parameters)))
741 (t window-system)))
2246281f 742 (frame-creation-function (cdr (assq w frame-creation-function-alist)))
da8e8fc1 743 (oldframe (selected-frame))
2246281f
KL
744 frame)
745 (unless frame-creation-function
746 (error "Don't know how to create a frame on window system %s" w))
747 (run-hooks 'before-make-frame-hook)
cb01ce3f
SM
748 (setq frame
749 (funcall frame-creation-function
750 (append parameters
751 (cdr (assq w window-system-default-frame-alist)))))
30a2fded 752 (normal-erase-is-backspace-setup-frame frame)
ab6198b2
SM
753 ;; Inherit the original frame's parameters.
754 (dolist (param frame-inherited-parameters)
755 (unless (assq param parameters) ;Overridden by explicit parameters.
756 (let ((val (frame-parameter oldframe param)))
757 (when val (set-frame-parameter frame param val)))))
45c4fdeb
SM
758 (run-hook-with-args 'after-make-frame-functions frame)
759 frame))
64c669bc 760
7eadab74
JB
761(defun filtered-frame-list (predicate)
762 "Return a list of all live frames which satisfy PREDICATE."
047bc928
GM
763 (let* ((frames (frame-list))
764 (list frames))
7eadab74 765 (while (consp frames)
047bc928
GM
766 (unless (funcall predicate (car frames))
767 (setcar frames nil))
7eadab74 768 (setq frames (cdr frames)))
047bc928 769 (delq nil list)))
7eadab74
JB
770
771(defun minibuffer-frame-list ()
772 "Return a list of all frames with their own minibuffers."
773 (filtered-frame-list
b7de6024
SM
774 (lambda (frame)
775 (eq frame (window-frame (minibuffer-window frame))))))
7eadab74 776
371fed4e
SM
777;; Used to be called `terminal-id' in termdev.el.
778(defun get-device-terminal (device)
779 "Return the terminal corresponding to DEVICE.
780DEVICE can be a terminal, a frame, nil (meaning the selected frame's terminal),
781the name of an X display device (HOST.SERVER.SCREEN) or a tty device file."
782 (cond
783 ((or (null device) (framep device))
784 (frame-terminal device))
785 ((stringp device)
786 (let ((f (car (filtered-frame-list
787 (lambda (frame)
788 (or (equal (frame-parameter frame 'display) device)
789 (equal (frame-parameter frame 'tty) device)))))))
790 (or f (error "Display %s does not exist" device))
791 (frame-terminal f)))
792 ((terminal-live-p device) device)
793 (t
794 (error "Invalid argument %s in `get-device-terminal'" device))))
795
796(defun frames-on-display-list (&optional device)
797 "Return a list of all frames on DEVICE.
798
799DEVICE should be a terminal, a frame,
800or a name of an X display or tty (a string of the form
9684e4c9 801HOST:SERVER.SCREEN).
b6660415 802
371fed4e 803If DEVICE is omitted or nil, it defaults to the selected
9684e4c9 804frame's terminal device."
371fed4e 805 (let* ((terminal (get-device-terminal device))
047bc928 806 (func #'(lambda (frame)
6ed8eeff 807 (eq (frame-terminal frame) terminal))))
9911648b
EZ
808 (filtered-frame-list func)))
809
f35ca2fe
KL
810(defun framep-on-display (&optional terminal)
811 "Return the type of frames on TERMINAL.
812TERMINAL may be a terminal id, a display name or a frame. If it
813is a frame, its type is returned. If TERMINAL is omitted or nil,
814it defaults to the selected frame's terminal device. All frames
815on a given display are of the same type."
6ed8eeff 816 (or (terminal-live-p terminal)
f35ca2fe
KL
817 (framep terminal)
818 (framep (car (frames-on-display-list terminal)))))
9911648b 819
58bf6042
JB
820(defun frame-remove-geometry-params (param-list)
821 "Return the parameter list PARAM-LIST, but with geometry specs removed.
822This deletes all bindings in PARAM-LIST for `top', `left', `width',
791e09d8 823`height', `user-size' and `user-position' parameters.
58bf6042
JB
824Emacs uses this to avoid overriding explicit moves and resizings from
825the user during startup."
826 (setq param-list (cons nil param-list))
827 (let ((tail param-list))
828 (while (consp (cdr tail))
829 (if (and (consp (car (cdr tail)))
791e09d8
RS
830 (memq (car (car (cdr tail)))
831 '(height width top left user-position user-size)))
832 (progn
833 (setq frame-initial-geometry-arguments
834 (cons (car (cdr tail)) frame-initial-geometry-arguments))
835 (setcdr tail (cdr (cdr tail))))
58bf6042 836 (setq tail (cdr tail)))))
e11c3dc2
KH
837 (setq frame-initial-geometry-arguments
838 (nreverse frame-initial-geometry-arguments))
58bf6042
JB
839 (cdr param-list))
840
aa360da1
GM
841(declare-function x-focus-frame "xfns.c" (frame))
842
030f4537
GM
843(defun select-frame-set-input-focus (frame)
844 "Select FRAME, raise it, and set input focus, if possible."
845 (select-frame frame)
846 (raise-frame frame)
847 ;; Ensure, if possible, that frame gets input focus.
9e2a2647 848 (when (memq (window-system frame) '(x w32 ns))
de30d842
DN
849 (x-focus-frame frame))
850 (when focus-follows-mouse
851 (set-mouse-position (selected-frame) (1- (frame-width)) 0)))
030f4537 852
ceab6935 853(defun other-frame (arg)
c2c93894 854 "Select the ARGth different visible frame on current display, and raise it.
ceab6935
RM
855All frames are arranged in a cyclic order.
856This command selects the frame ARG steps away in that order.
bb578a72
RS
857A negative ARG moves in the opposite order.
858
859To make this command work properly, you must tell Emacs
860how the system (or the window manager) generally handles
861focus-switching between windows. If moving the mouse onto a window
862selects it (gives it focus), set `focus-follows-mouse' to t.
863Otherwise, that variable should be nil."
ceab6935
RM
864 (interactive "p")
865 (let ((frame (selected-frame)))
866 (while (> arg 0)
a569dbc3
RM
867 (setq frame (next-frame frame))
868 (while (not (eq (frame-visible-p frame) t))
869 (setq frame (next-frame frame)))
870 (setq arg (1- arg)))
ceab6935 871 (while (< arg 0)
a569dbc3
RM
872 (setq frame (previous-frame frame))
873 (while (not (eq (frame-visible-p frame) t))
874 (setq frame (previous-frame frame)))
915cfd1f 875 (setq arg (1+ arg)))
030f4537 876 (select-frame-set-input-focus frame)))
845cde06 877
3db7df06
SM
878(defun iconify-or-deiconify-frame ()
879 "Iconify the selected frame, or deiconify if it's currently an icon."
880 (interactive)
881 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
882 (iconify-frame)
883 (make-frame-visible)))
884
0b0d3e0b
KL
885(defun suspend-frame ()
886 "Do whatever is right to suspend the current frame.
f35ca2fe
KL
887Calls `suspend-emacs' if invoked from the controlling tty device,
888`suspend-tty' from a secondary tty device, and
0b0d3e0b
KL
889`iconify-or-deiconify-frame' from an X frame."
890 (interactive)
891 (let ((type (framep (selected-frame))))
892 (cond
edfda783 893 ((memq type '(x ns w32)) (iconify-or-deiconify-frame))
0b0d3e0b 894 ((eq type t)
6ed8eeff 895 (if (controlling-tty-p)
4a933ef8
KL
896 (suspend-emacs)
897 (suspend-tty)))
0b0d3e0b
KL
898 (t (suspend-emacs)))))
899
845cde06
EZ
900(defun make-frame-names-alist ()
901 (let* ((current-frame (selected-frame))
902 (falist
903 (cons
904 (cons (frame-parameter current-frame 'name) current-frame) nil))
905 (frame (next-frame nil t)))
906 (while (not (eq frame current-frame))
907 (progn
908 (setq falist (cons (cons (frame-parameter frame 'name) frame) falist))
909 (setq frame (next-frame frame t))))
910 falist))
911
912(defvar frame-name-history nil)
845cde06 913(defun select-frame-by-name (name)
563283b1 914 "Select the frame on the current terminal whose name is NAME and raise it.
845cde06
EZ
915If there is no frame by that name, signal an error."
916 (interactive
716ff1c9
RS
917 (let* ((frame-names-alist (make-frame-names-alist))
918 (default (car (car frame-names-alist)))
919 (input (completing-read
920 (format "Select Frame (default %s): " default)
921 frame-names-alist nil t nil 'frame-name-history)))
845cde06
EZ
922 (if (= (length input) 0)
923 (list default)
924 (list input))))
716ff1c9
RS
925 (let* ((frame-names-alist (make-frame-names-alist))
926 (frame (cdr (assoc name frame-names-alist))))
845cde06
EZ
927 (or frame
928 (error "There is no frame named `%s'" name))
929 (make-frame-visible frame)
930 (raise-frame frame)
880a9ae1
AI
931 (select-frame frame)
932 ;; Ensure, if possible, that frame gets input focus.
edfda783 933 (cond ((memq (window-system frame) '(x w32 ns))
31e0520c 934 (x-focus-frame frame)))
80c39c38
RS
935 (when focus-follows-mouse
936 (set-mouse-position frame (1- (frame-width frame)) 0))))
64c669bc 937\f
dc6d9681
JB
938;;;; Frame configurations
939
940(defun current-frame-configuration ()
941 "Return a list describing the positions and states of all frames.
376a7584
JB
942Its car is `frame-configuration'.
943Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
944where
945 FRAME is a frame object,
946 ALIST is an association list specifying some of FRAME's parameters, and
947 WINDOW-CONFIG is a window configuration object for FRAME."
948 (cons 'frame-configuration
b7de6024
SM
949 (mapcar (lambda (frame)
950 (list frame
951 (frame-parameters frame)
952 (current-window-configuration frame)))
376a7584 953 (frame-list))))
dc6d9681 954
68cd265f 955(defun set-frame-configuration (configuration &optional nodelete)
dc6d9681
JB
956 "Restore the frames to the state described by CONFIGURATION.
957Each frame listed in CONFIGURATION has its position, size, window
68cd265f 958configuration, and other parameters set as specified in CONFIGURATION.
d398de43
LT
959However, this function does not restore deleted frames.
960
a78db71c
RS
961Ordinarily, this function deletes all existing frames not
962listed in CONFIGURATION. But if optional second argument NODELETE
5da841d2 963is given and non-nil, the unwanted frames are iconified instead."
376a7584
JB
964 (or (frame-configuration-p configuration)
965 (signal 'wrong-type-argument
966 (list 'frame-configuration-p configuration)))
967 (let ((config-alist (cdr configuration))
968 frames-to-delete)
b7de6024
SM
969 (dolist (frame (frame-list))
970 (let ((parameters (assq frame config-alist)))
971 (if parameters
972 (progn
973 (modify-frame-parameters
974 frame
975 ;; Since we can't set a frame's minibuffer status,
976 ;; we might as well omit the parameter altogether.
977 (let* ((parms (nth 1 parameters))
b2529d56
MB
978 (mini (assq 'minibuffer parms))
979 (name (assq 'name parms))
980 (explicit-name (cdr (assq 'explicit-name parms))))
981 (when mini (setq parms (delq mini parms)))
982 ;; Leave name in iff it was set explicitly.
983 ;; This should fix the behavior reported in
984 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg01632.html
985 (when (and name (not explicit-name))
986 (setq parms (delq name parms)))
b7de6024
SM
987 parms))
988 (set-window-configuration (nth 2 parameters)))
989 (setq frames-to-delete (cons frame frames-to-delete)))))
990 (mapc (if nodelete
991 ;; Note: making frames invisible here was tried
992 ;; but led to some strange behavior--each time the frame
993 ;; was made visible again, the window manager asked afresh
994 ;; for where to put it.
995 'iconify-frame
996 'delete-frame)
997 frames-to-delete)))
64c669bc 998\f
dc6d9681
JB
999;;;; Convenience functions for accessing and interactively changing
1000;;;; frame parameters.
64c669bc 1001
151bdc83 1002(defun frame-height (&optional frame)
dc6d9681
JB
1003 "Return number of lines available for display on FRAME.
1004If FRAME is omitted, describe the currently selected frame."
151bdc83 1005 (cdr (assq 'height (frame-parameters frame))))
dc6d9681
JB
1006
1007(defun frame-width (&optional frame)
1008 "Return number of columns available for display on FRAME.
1009If FRAME is omitted, describe the currently selected frame."
151bdc83 1010 (cdr (assq 'width (frame-parameters frame))))
dc6d9681 1011
aa360da1
GM
1012(declare-function x-list-fonts "xfaces.c"
1013 (pattern &optional face frame maximum width))
1014
889611f0 1015(defalias 'set-default-font 'set-frame-font)
1cef6541 1016(defun set-frame-font (font-name &optional keep-size)
40d34803 1017 "Set the font of the selected frame to FONT-NAME.
61298010 1018When called interactively, prompt for the name of the font to use.
1cef6541
JB
1019To get the frame's current default font, use `frame-parameters'.
1020
1021The default behavior is to keep the numbers of lines and columns in
84ed1560 1022the frame, thus may change its pixel size. If optional KEEP-SIZE is
1cef6541
JB
1023non-nil (interactively, prefix argument) the current frame size (in
1024pixels) is kept by adjusting the numbers of the lines and columns."
f39784dd 1025 (interactive
1cef6541
JB
1026 (let* ((completion-ignore-case t)
1027 (font (completing-read "Font name: "
1cef6541
JB
1028 ;; x-list-fonts will fail with an error
1029 ;; if this frame doesn't support fonts.
b7de6024
SM
1030 (x-list-fonts "*" nil (selected-frame))
1031 nil nil nil nil
1032 (frame-parameter nil 'font))))
1cef6541
JB
1033 (list font current-prefix-arg)))
1034 (let (fht fwd)
1035 (if keep-size
1036 (setq fht (* (frame-parameter nil 'height) (frame-char-height))
1037 fwd (* (frame-parameter nil 'width) (frame-char-width))))
1038 (modify-frame-parameters (selected-frame)
1039 (list (cons 'font font-name)))
1040 (if keep-size
1041 (modify-frame-parameters
1042 (selected-frame)
1043 (list (cons 'height (round fht (frame-char-height)))
1044 (cons 'width (round fwd (frame-char-width)))))))
72bf1a8b 1045 (run-hooks 'after-setting-font-hook 'after-setting-font-hooks))
64c669bc 1046
7e573c4a 1047(defun set-frame-parameter (frame parameter value)
0dac35b8
KL
1048 "Set frame parameter PARAMETER to VALUE on FRAME.
1049If FRAME is nil, it defaults to the selected frame.
c2c93894 1050See `modify-frame-parameters'."
7e573c4a
SM
1051 (modify-frame-parameters frame (list (cons parameter value))))
1052
8290babd 1053(defun set-background-color (color-name)
40d34803 1054 "Set the background color of the selected frame to COLOR-NAME.
61298010
RS
1055When called interactively, prompt for the name of the color to use.
1056To get the frame's current background color, use `frame-parameters'."
63ec4f94 1057 (interactive (list (facemenu-read-color "Background color: ")))
dc6d9681 1058 (modify-frame-parameters (selected-frame)
528e1416
EZ
1059 (list (cons 'background-color color-name)))
1060 (or window-system
1061 (face-set-after-frame-default (selected-frame))))
64c669bc 1062
8290babd 1063(defun set-foreground-color (color-name)
40d34803 1064 "Set the foreground color of the selected frame to COLOR-NAME.
61298010
RS
1065When called interactively, prompt for the name of the color to use.
1066To get the frame's current foreground color, use `frame-parameters'."
63ec4f94 1067 (interactive (list (facemenu-read-color "Foreground color: ")))
dc6d9681 1068 (modify-frame-parameters (selected-frame)
528e1416
EZ
1069 (list (cons 'foreground-color color-name)))
1070 (or window-system
1071 (face-set-after-frame-default (selected-frame))))
64c669bc
JB
1072
1073(defun set-cursor-color (color-name)
40d34803 1074 "Set the text cursor color of the selected frame to COLOR-NAME.
61298010
RS
1075When called interactively, prompt for the name of the color to use.
1076To get the frame's current cursor color, use `frame-parameters'."
63ec4f94 1077 (interactive (list (facemenu-read-color "Cursor color: ")))
dc6d9681 1078 (modify-frame-parameters (selected-frame)
7eadab74 1079 (list (cons 'cursor-color color-name))))
64c669bc 1080
eaa974e1 1081(defun set-mouse-color (color-name)
40d34803 1082 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
61298010
RS
1083When called interactively, prompt for the name of the color to use.
1084To get the frame's current mouse color, use `frame-parameters'."
63ec4f94 1085 (interactive (list (facemenu-read-color "Mouse color: ")))
dc6d9681 1086 (modify-frame-parameters (selected-frame)
ec6d4463
KH
1087 (list (cons 'mouse-color
1088 (or color-name
1089 (cdr (assq 'mouse-color
1090 (frame-parameters))))))))
7eadab74 1091
eaa974e1 1092(defun set-border-color (color-name)
40d34803 1093 "Set the color of the border 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 border color, use `frame-parameters'."
63ec4f94 1096 (interactive (list (facemenu-read-color "Border color: ")))
eaa974e1
JB
1097 (modify-frame-parameters (selected-frame)
1098 (list (cons 'border-color color-name))))
1099
1100(defun auto-raise-mode (arg)
7eadab74 1101 "Toggle whether or not the selected frame should auto-raise.
79e6ae33
RS
1102With arg, turn auto-raise mode on if and only if arg is positive.
1103Note that this controls Emacs's own auto-raise feature.
1104Some window managers allow you to enable auto-raise for certain windows.
1105You can use that for Emacs windows if you wish, but if you do,
1106that is beyond the control of Emacs and this command has no effect on it."
7eadab74
JB
1107 (interactive "P")
1108 (if (null arg)
1109 (setq arg
1110 (if (cdr (assq 'auto-raise (frame-parameters (selected-frame))))
1111 -1 1)))
9626b928
GM
1112 (if (> arg 0)
1113 (raise-frame (selected-frame)))
dc6d9681 1114 (modify-frame-parameters (selected-frame)
7eadab74
JB
1115 (list (cons 'auto-raise (> arg 0)))))
1116
eaa974e1 1117(defun auto-lower-mode (arg)
7eadab74 1118 "Toggle whether or not the selected frame should auto-lower.
79e6ae33
RS
1119With arg, turn auto-lower mode on if and only if arg is positive.
1120Note that this controls Emacs's own auto-lower feature.
1121Some window managers allow you to enable auto-lower for certain windows.
1122You can use that for Emacs windows if you wish, but if you do,
1123that is beyond the control of Emacs and this command has no effect on it."
7eadab74
JB
1124 (interactive "P")
1125 (if (null arg)
1126 (setq arg
1127 (if (cdr (assq 'auto-lower (frame-parameters (selected-frame))))
1128 -1 1)))
dc6d9681 1129 (modify-frame-parameters (selected-frame)
7eadab74 1130 (list (cons 'auto-lower (> arg 0)))))
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
EZ
1358(defun display-visual-class (&optional display)
1359 "Returns the visual class of DISPLAY.
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
dc6d9681 1435;;;; Aliases for backward compatibility with Emacs 18.
8d91bd0a
JB
1436(define-obsolete-function-alias 'screen-height 'frame-height "19.7")
1437(define-obsolete-function-alias 'screen-width 'frame-width "19.7")
9e2b097b
JB
1438
1439(defun set-screen-width (cols &optional pretend)
84ed1560 1440 "Change the size of the screen to COLS columns.
40d34803
DL
1441Optional second arg non-nil means that redisplay should use COLS columns
1442but that the idea of the actual width of the frame should not be changed.
84ed1560 1443This function is provided only for compatibility with Emacs 18."
9e2b097b
JB
1444 (set-frame-width (selected-frame) cols pretend))
1445
1446(defun set-screen-height (lines &optional pretend)
84ed1560 1447 "Change the height of the screen to LINES lines.
40d34803
DL
1448Optional second arg non-nil means that redisplay should use LINES lines
1449but that the idea of the actual height of the screen should not be changed.
84ed1560 1450This function is provided only for compatibility with Emacs 18."
9e2b097b
JB
1451 (set-frame-height (selected-frame) lines pretend))
1452
154a757e
GM
1453(defun delete-other-frames (&optional frame)
1454 "Delete all frames except FRAME.
a2125918
GM
1455If FRAME uses another frame's minibuffer, the minibuffer frame is
1456left untouched. FRAME nil or omitted means use the selected frame."
154a757e
GM
1457 (interactive)
1458 (unless frame
1459 (setq frame (selected-frame)))
a2125918
GM
1460 (let* ((mini-frame (window-frame (minibuffer-window frame)))
1461 (frames (delq mini-frame (delq frame (frame-list)))))
1462 ;; Delete mon-minibuffer-only frames first, because `delete-frame'
1463 ;; signals an error when trying to delete a mini-frame that's
1464 ;; still in use by another frame.
1465 (dolist (frame frames)
1466 (unless (eq (frame-parameter frame 'minibuffer) 'only)
1467 (delete-frame frame)))
1468 ;; Delete minibuffer-only frames.
1469 (dolist (frame frames)
1470 (when (eq (frame-parameter frame 'minibuffer) 'only)
1471 (delete-frame frame)))))
154a757e 1472
8d91bd0a
JB
1473(make-obsolete 'set-screen-width 'set-frame-width "19.7")
1474(make-obsolete 'set-screen-height 'set-frame-height "19.7")
dc6d9681 1475
da7829a3 1476;; miscellaneous obsolescence declarations
84ed1560
JB
1477(define-obsolete-variable-alias 'delete-frame-hook
1478 'delete-frame-functions "22.1")
da7829a3 1479
dc6d9681 1480\f
7e573c4a 1481;; Highlighting trailing whitespace.
81b99826
GM
1482
1483(make-variable-buffer-local 'show-trailing-whitespace)
1484
1485(defcustom show-trailing-whitespace nil
e6c45c29
LT
1486 "*Non-nil means highlight trailing whitespace.
1487This is done in the face `trailing-whitespace'."
81b99826 1488 :type 'boolean
b4aefb19 1489 :group 'whitespace-faces)
81b99826
GM
1490
1491
1492\f
7e573c4a 1493;; Scrolling
79b14b94
GM
1494
1495(defgroup scrolling nil
1496 "Scrolling windows."
1497 :version "21.1"
1498 :group 'frames)
1499
968ecc28 1500(defcustom auto-hscroll-mode t
310e9a21 1501 "*Allow or disallow automatic scrolling windows horizontally.
9ea60c46 1502If non-nil, windows are automatically scrolled horizontally to make
79b14b94
GM
1503point visible."
1504 :version "21.1"
1505 :type 'boolean
1506 :group 'scrolling)
968ecc28 1507(defvaralias 'automatic-hscrolling 'auto-hscroll-mode)
79b14b94
GM
1508
1509\f
7e573c4a 1510;; Blinking cursor
81b99826
GM
1511
1512(defgroup cursor nil
ca693be8 1513 "Displaying text cursors."
40d34803 1514 :version "21.1"
81b99826
GM
1515 :group 'frames)
1516
1517(defcustom blink-cursor-delay 0.5
ca693be8 1518 "*Seconds of idle time after which cursor starts to blink."
81b99826
GM
1519 :type 'number
1520 :group 'cursor)
1521
1522(defcustom blink-cursor-interval 0.5
1523 "*Length of cursor blink interval in seconds."
81b99826
GM
1524 :type 'number
1525 :group 'cursor)
1526
1527(defvar blink-cursor-idle-timer nil
ca693be8
GM
1528 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
1529The function `blink-cursor-start' is called when the timer fires.")
81b99826
GM
1530
1531(defvar blink-cursor-timer nil
ca693be8 1532 "Timer started from `blink-cursor-start'.
a795e09a
LT
1533This timer calls `blink-cursor-timer-function' every
1534`blink-cursor-interval' seconds.")
1535
81b99826 1536(defun blink-cursor-start ()
ca693be8
GM
1537 "Timer function called from the timer `blink-cursor-idle-timer'.
1538This starts the timer `blink-cursor-timer', which makes the cursor blink
1539if appropriate. It also arranges to cancel that timer when the next
1540command starts, by installing a pre-command hook."
81b99826 1541 (when (null blink-cursor-timer)
f9ac92c5
CY
1542 ;; Set up the timer first, so that if this signals an error,
1543 ;; blink-cursor-end is not added to pre-command-hook.
81b99826
GM
1544 (setq blink-cursor-timer
1545 (run-with-timer blink-cursor-interval blink-cursor-interval
f9ac92c5
CY
1546 'blink-cursor-timer-function))
1547 (add-hook 'pre-command-hook 'blink-cursor-end)
1548 (internal-show-cursor nil nil)))
0a5ebe4b
GM
1549
1550(defun blink-cursor-timer-function ()
1551 "Timer function of timer `blink-cursor-timer'."
1552 (internal-show-cursor nil (not (internal-show-cursor-p))))
81b99826
GM
1553
1554(defun blink-cursor-end ()
1555 "Stop cursor blinking.
ca693be8 1556This is installed as a pre-command hook by `blink-cursor-start'.
f39784dd 1557When run, it cancels the timer `blink-cursor-timer' and removes
ca693be8 1558itself as a pre-command hook."
81b99826 1559 (remove-hook 'pre-command-hook 'blink-cursor-end)
0a5ebe4b 1560 (internal-show-cursor nil t)
8ec94c16
SM
1561 (when blink-cursor-timer
1562 (cancel-timer blink-cursor-timer)
1563 (setq blink-cursor-timer nil)))
81b99826 1564
8ec94c16
SM
1565(define-minor-mode blink-cursor-mode
1566 "Toggle blinking cursor mode.
4837b516
GM
1567With a numeric argument, turn blinking cursor mode on if ARG is positive,
1568otherwise turn it off. When blinking cursor mode is enabled, the
1569cursor of the selected window blinks.
81b99826 1570
8ec94c16
SM
1571Note that this command is effective only when Emacs
1572displays through a window system, because then Emacs does its own
1573cursor display. On a text-only terminal, this is not implemented."
1574 :init-value (not (or noninteractive
1575 no-blinking-cursor
1576 (eq system-type 'ms-dos)
9e2a2647 1577 (not (memq window-system '(x w32)))))
8ec94c16
SM
1578 :initialize 'custom-initialize-safe-default
1579 :group 'cursor
1580 :global t
1581 (if blink-cursor-idle-timer (cancel-timer blink-cursor-idle-timer))
1582 (setq blink-cursor-idle-timer nil)
1583 (blink-cursor-end)
1584 (when blink-cursor-mode
1585 ;; Hide the cursor.
1586 ;;(internal-show-cursor nil nil)
1587 (setq blink-cursor-idle-timer
1588 (run-with-idle-timer blink-cursor-delay
1589 blink-cursor-delay
1590 'blink-cursor-start))))
81b99826 1591
8ec94c16 1592(define-obsolete-variable-alias 'blink-cursor 'blink-cursor-mode "22.1")
81b99826 1593\f
7e573c4a 1594;; Hourglass pointer
81b99826 1595
a6c411ff 1596(defcustom display-hourglass t
088e75cc
RS
1597 "*Non-nil means show an hourglass pointer, when Emacs is busy.
1598This feature only works when on a window system that can change
1599cursor shapes."
81b99826 1600 :type 'boolean
a6c411ff 1601 :group 'cursor)
81b99826 1602
a6c411ff 1603(defcustom hourglass-delay 1
63ec4f94 1604 "*Seconds to wait before displaying an hourglass pointer when Emacs is busy."
0a86e779 1605 :type 'number
a6c411ff 1606 :group 'cursor)
1d0a3ef4 1607
5b2c5477 1608\f
c0eb3c10 1609(defcustom cursor-in-non-selected-windows t
84ed1560 1610 "*Non-nil means show a hollow box cursor in non-selected windows.
e053c60f 1611If nil, don't show a cursor except in the selected window.
772e490c
RS
1612If t, display a cursor related to the usual cursor type
1613 \(a solid box becomes hollow, a bar becomes a narrower bar).
1614You can also specify the cursor type as in the `cursor-type' variable.
f39784dd 1615Use Custom to set this variable to get the display updated."
63ec4f94 1616 :tag "Cursor In Non-selected Windows"
5b2c5477
GM
1617 :type 'boolean
1618 :group 'cursor
5b2c5477
GM
1619 :set #'(lambda (symbol value)
1620 (set-default symbol value)
5b2c5477 1621 (force-mode-line-update t)))
f39784dd 1622
81b99826 1623\f
64c669bc 1624;;;; Key bindings
64c669bc 1625
6238bfaf 1626(define-key ctl-x-5-map "2" 'make-frame-command)
154a757e 1627(define-key ctl-x-5-map "1" 'delete-other-frames)
dc6d9681 1628(define-key ctl-x-5-map "0" 'delete-frame)
ceab6935 1629(define-key ctl-x-5-map "o" 'other-frame)
49116ac0 1630
dc6d9681 1631(provide 'frame)
c88ab9ce 1632
485464c4 1633;; arch-tag: 82979c70-b8f2-4306-b2ad-ddbd6b328b56
dc6d9681 1634;;; frame.el ends here