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