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