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