Commit | Line | Data |
---|---|---|
dc6d9681 | 1 | ;;; frame.el --- multi-frame management independent of window systems. |
c88ab9ce | 2 | |
8f1204db | 3 | ;;;; Copyright (C) 1993, 1994 Free Software Foundation, Inc. |
3a801d0c | 4 | |
fc68affa | 5 | ;; Maintainer: FSF |
fd7fa35a | 6 | ;; Keywords: internal |
fc68affa | 7 | |
64c669bc JB |
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 | |
de49a6d3 | 12 | ;;; the Free Software Foundation; either version 2, or (at your option) |
64c669bc JB |
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 | |
22 | ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | ||
fc68affa ER |
24 | ;;; Code: |
25 | ||
dc6d9681 JB |
26 | (defvar frame-creation-function nil |
27 | "Window-system dependent function to call to create a new frame. | |
28 | The window system startup file should set this to its frame creation | |
64c669bc JB |
29 | function, which should take an alist of parameters as its argument.") |
30 | ||
7eadab74 JB |
31 | ;;; The initial value given here for this must ask for a minibuffer. |
32 | ;;; There must always exist a frame with a minibuffer, and after we | |
33 | ;;; delete the terminal frame, this will be the only frame. | |
9e2b097b | 34 | (defvar initial-frame-alist '((minibuffer . t)) |
eaa974e1 JB |
35 | "Alist of frame parameters for creating the initial X window frame. |
36 | You can set this in your `.emacs' file; for example, | |
dc6d9681 | 37 | (setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55))) |
de17da15 RS |
38 | Parameters specified here supersede the values given in `default-frame-alist'. |
39 | ||
40 | If the value calls for a frame without a minibuffer, and you have not created | |
41 | a minibuffer frame on your own, one is created according to | |
7eadab74 | 42 | `minibuffer-frame-alist'. |
de17da15 RS |
43 | |
44 | You can specify geometry-related options for just the initial frame | |
45 | by setting this variable in your `.emacs' file; however, they won't | |
46 | take affect until Emacs reads `.emacs', which happens after first creating | |
47 | the frame. If you want the frame to have the proper geometry as soon | |
48 | as it appears, you need to use this three-step process: | |
49 | * Specify X resources to give the geometry you want. | |
50 | * Set `default-frame-alist' to override these options so that they | |
51 | don't affect subsequent frames. | |
52 | * Set `initial-frame-alist' in a way that matches the X resources, | |
53 | to override what you put in `default-frame-alist'.") | |
64c669bc | 54 | |
7eadab74 | 55 | (defvar minibuffer-frame-alist '((width . 80) (height . 2)) |
eaa974e1 JB |
56 | "Alist of frame parameters for initially creating a minibuffer frame. |
57 | You can set this in your `.emacs' file; for example, | |
dc6d9681 | 58 | (setq minibuffer-frame-alist |
7eadab74 | 59 | '((top . 1) (left . 1) (width . 80) (height . 2))) |
eaa974e1 JB |
60 | Parameters specified here supersede the values given in |
61 | `default-frame-alist'.") | |
64c669bc | 62 | |
dc6d9681 | 63 | (defvar pop-up-frame-alist nil |
eaa974e1 | 64 | "Alist of frame parameters used when creating pop-up frames. |
dc6d9681 | 65 | Pop-up frames are used for completions, help, and the like. |
64c669bc | 66 | This variable can be set in your init file, like this: |
dc6d9681 | 67 | (setq pop-up-frame-alist '((width . 80) (height . 20))) |
eb8c3be9 | 68 | These supersede the values given in `default-frame-alist'.") |
64c669bc | 69 | |
dc6d9681 | 70 | (setq pop-up-frame-function |
64c669bc | 71 | (function (lambda () |
6eb018ba | 72 | (make-frame pop-up-frame-alist)))) |
64c669bc | 73 | |
8a9e86e6 RS |
74 | (defvar special-display-frame-alist |
75 | '((height . 14) (width . 80) (unsplittable . t)) | |
76 | "*Alist of frame parameters used when creating special frames. | |
77 | Special frames are used for buffers whose names are in | |
78 | `special-display-buffer-names' and for buffers whose names match | |
79 | one of the regular expressions in `special-display-regexps'. | |
80 | This variable can be set in your init file, like this: | |
81 | (setq special-display-frame-alist '((width . 80) (height . 20))) | |
82 | These supersede the values given in `default-frame-alist'.") | |
83 | ||
84 | ;; Display BUFFER in its own frame, reusing an existing window if any. | |
85 | ;; Return the window chosen. | |
86 | ;; Currently we do not insist on selecting the window within its frame. | |
42354c89 | 87 | (defun special-display-popup-frame (buffer &optional params) |
8a9e86e6 RS |
88 | (let ((window (get-buffer-window buffer t))) |
89 | (if window | |
90 | ;; If we have a window already, make it visible. | |
91 | (let ((frame (window-frame window))) | |
92 | (make-frame-visible frame) | |
93 | (raise-frame frame) | |
94 | window) | |
95 | ;; If no window yet, make one in a new frame. | |
42354c89 | 96 | (let ((frame (make-frame (append params special-display-frame-alist)))) |
8a9e86e6 RS |
97 | (set-window-buffer (frame-selected-window frame) buffer) |
98 | (set-window-dedicated-p (frame-selected-window frame) t) | |
99 | (frame-selected-window frame))))) | |
100 | ||
101 | (setq special-display-function 'special-display-popup-frame) | |
64c669bc | 102 | \f |
dc6d9681 | 103 | ;;;; Arrangement of frames at startup |
64c669bc JB |
104 | |
105 | ;;; 1) Load the window system startup file from the lisp library and read the | |
106 | ;;; high-priority arguments (-q and the like). The window system startup | |
dc6d9681 | 107 | ;;; file should create any frames specified in the window system defaults. |
64c669bc | 108 | ;;; |
dc6d9681 | 109 | ;;; 2) If no frames have been opened, we open an initial text frame. |
64c669bc JB |
110 | ;;; |
111 | ;;; 3) Once the init file is done, we apply any newly set parameters | |
dc6d9681 | 112 | ;;; in initial-frame-alist to the frame. |
64c669bc | 113 | |
fc4d4afb RS |
114 | ;; These are now called explicitly at the proper times, |
115 | ;; since that is easier to understand. | |
116 | ;; Actually using hooks within Emacs is bad for future maintenance. --rms. | |
117 | ;; (add-hook 'before-init-hook 'frame-initialize) | |
118 | ;; (add-hook 'window-setup-hook 'frame-notice-user-settings) | |
64c669bc | 119 | |
dc6d9681 JB |
120 | ;;; If we create the initial frame, this is it. |
121 | (defvar frame-initial-frame nil) | |
64c669bc | 122 | |
3f2f8c83 RS |
123 | ;; Record the parameters used in frame-initialize to make the initial frame. |
124 | (defvar frame-initial-frame-alist) | |
125 | ||
791e09d8 RS |
126 | (defvar frame-initial-geometry-arguments nil) |
127 | ||
64c669bc | 128 | ;;; startup.el calls this function before loading the user's init |
dc6d9681 | 129 | ;;; file - if there is no frame with a minibuffer open now, create |
64c669bc | 130 | ;;; one to display messages while loading the init file. |
dc6d9681 | 131 | (defun frame-initialize () |
64c669bc JB |
132 | |
133 | ;; Are we actually running under a window system at all? | |
134 | (if (and window-system (not noninteractive)) | |
7eadab74 JB |
135 | (progn |
136 | ;; If there is no frame with a minibuffer besides the terminal | |
137 | ;; frame, then we need to create the opening frame. Make sure | |
138 | ;; it has a minibuffer, but let initial-frame-alist omit the | |
139 | ;; minibuffer spec. | |
140 | (or (delq terminal-frame (minibuffer-frame-list)) | |
36fc9c9f | 141 | (progn |
3f2f8c83 RS |
142 | (setq frame-initial-frame-alist |
143 | (append initial-frame-alist default-frame-alist)) | |
a8bb5882 RS |
144 | ;; Record these with their default values |
145 | ;; if they don't have any values explicitly. | |
146 | (or (assq 'vertical-scroll-bars frame-initial-frame-alist) | |
147 | (setq frame-initial-frame-alist | |
148 | (cons '(vertical-scroll-bars . t) | |
149 | frame-initial-frame-alist))) | |
150 | (or (assq 'horizontal-scroll-bars frame-initial-frame-alist) | |
151 | (setq frame-initial-frame-alist | |
152 | (cons '(horizontal-scroll-bars . t) | |
153 | frame-initial-frame-alist))) | |
36fc9c9f RS |
154 | (setq default-minibuffer-frame |
155 | (setq frame-initial-frame | |
6eb018ba | 156 | (make-frame initial-frame-alist))) |
11281034 RS |
157 | ;; Delete any specifications for window geometry parameters |
158 | ;; so that we won't reapply them in frame-notice-user-settings. | |
159 | ;; It would be wrong to reapply them then, | |
160 | ;; because that would override explicit user resizing. | |
58bf6042 | 161 | (setq initial-frame-alist |
c2079f0a | 162 | (frame-remove-geometry-params initial-frame-alist)))) |
dc6d9681 JB |
163 | ;; At this point, we know that we have a frame open, so we |
164 | ;; can delete the terminal frame. | |
165 | (delete-frame terminal-frame) | |
166 | (setq terminal-frame nil)) | |
64c669bc JB |
167 | |
168 | ;; No, we're not running a window system. Arrange to cause errors. | |
dc6d9681 | 169 | (setq frame-creation-function |
9198945a MB |
170 | (function |
171 | (lambda (parameters) | |
172 | (error | |
8290babd | 173 | "Can't create multiple frames without a window system")))))) |
64c669bc | 174 | |
7eadab74 JB |
175 | ;;; startup.el calls this function after loading the user's init |
176 | ;;; file. Now default-frame-alist and initial-frame-alist contain | |
177 | ;;; information to which we must react; do what needs to be done. | |
dc6d9681 | 178 | (defun frame-notice-user-settings () |
7eadab74 | 179 | |
2ffa6186 RS |
180 | ;; Make menu-bar-mode and default-frame-alist consistent. |
181 | (let ((default (assq 'menu-bar-lines default-frame-alist))) | |
182 | (if default | |
183 | (setq menu-bar-mode (not (eq (cdr default) 0))) | |
184 | (setq default-frame-alist | |
185 | (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0)) | |
186 | default-frame-alist)))) | |
187 | ||
7eadab74 JB |
188 | ;; Creating and deleting frames may shift the selected frame around, |
189 | ;; and thus the current buffer. Protect against that. We don't | |
190 | ;; want to use save-excursion here, because that may also try to set | |
191 | ;; the buffer of the selected window, which fails when the selected | |
192 | ;; window is the minibuffer. | |
193 | (let ((old-buffer (current-buffer))) | |
194 | ||
195 | ;; If the initial frame is still around, apply initial-frame-alist | |
196 | ;; and default-frame-alist to it. | |
197 | (if (frame-live-p frame-initial-frame) | |
198 | ||
199 | ;; The initial frame we create above always has a minibuffer. | |
200 | ;; If the user wants to remove it, or make it a minibuffer-only | |
201 | ;; frame, then we'll have to delete the current frame and make a | |
202 | ;; new one; you can't remove or add a root window to/from an | |
203 | ;; existing frame. | |
204 | ;; | |
ec558adc JB |
205 | ;; NOTE: default-frame-alist was nil when we created the |
206 | ;; existing frame. We need to explicitly include | |
207 | ;; default-frame-alist in the parameters of the screen we | |
208 | ;; create here, so that its new value, gleaned from the user's | |
209 | ;; .emacs file, will be applied to the existing screen. | |
7eadab74 JB |
210 | (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist) |
211 | (assq 'minibuffer default-frame-alist) | |
212 | '(minibuffer . t))) | |
213 | t)) | |
214 | ;; Create the new frame. | |
b65e2f74 RS |
215 | (let (parms new) |
216 | ;; If the frame isn't visible yet, wait till it is. | |
217 | ;; If the user has to position the window, | |
218 | ;; Emacs doesn't know its real position until | |
219 | ;; the frame is seen to be visible. | |
220 | (while (not (cdr (assq 'visibility | |
221 | (frame-parameters frame-initial-frame)))) | |
222 | (sleep-for 1)) | |
223 | (setq parms (append initial-frame-alist | |
6eb018ba RS |
224 | default-frame-alist |
225 | (frame-parameters frame-initial-frame) | |
226 | nil)) | |
c1e67401 RS |
227 | ;; Get rid of `reverse', because that was handled |
228 | ;; when we first made the frame. | |
229 | (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms))) | |
230 | (if (assq 'height frame-initial-geometry-arguments) | |
5b66a32f | 231 | (setq parms (frame-delete-all 'height parms))) |
c1e67401 | 232 | (if (assq 'width frame-initial-geometry-arguments) |
5b66a32f | 233 | (setq parms (frame-delete-all 'width parms))) |
c1e67401 | 234 | (if (assq 'left frame-initial-geometry-arguments) |
5b66a32f | 235 | (setq parms (frame-delete-all 'left parms))) |
c1e67401 | 236 | (if (assq 'top frame-initial-geometry-arguments) |
5b66a32f | 237 | (setq parms (frame-delete-all 'top parms))) |
c1e67401 RS |
238 | (setq new |
239 | (make-frame | |
240 | ;; Use the geometry args that created the existing | |
241 | ;; frame, rather than the parms we get for it. | |
242 | (append frame-initial-geometry-arguments parms))) | |
7eadab74 JB |
243 | ;; The initial frame, which we are about to delete, may be |
244 | ;; the only frame with a minibuffer. If it is, create a | |
245 | ;; new one. | |
246 | (or (delq frame-initial-frame (minibuffer-frame-list)) | |
6eb018ba | 247 | (make-frame (append minibuffer-frame-alist |
7eadab74 JB |
248 | '((minibuffer . only))))) |
249 | ||
250 | ;; If the initial frame is serving as a surrogate | |
251 | ;; minibuffer frame for any frames, we need to wean them | |
252 | ;; onto a new frame. The default-minibuffer-frame | |
253 | ;; variable must be handled similarly. | |
254 | (let ((users-of-initial | |
255 | (filtered-frame-list | |
256 | (function (lambda (frame) | |
257 | (and (not (eq frame frame-initial-frame)) | |
258 | (eq (window-frame | |
259 | (minibuffer-window frame)) | |
260 | frame-initial-frame))))))) | |
261 | (if (or users-of-initial | |
262 | (eq default-minibuffer-frame frame-initial-frame)) | |
263 | ||
264 | ;; Choose an appropriate frame. Prefer frames which | |
265 | ;; are only minibuffers. | |
266 | (let* ((new-surrogate | |
267 | (car | |
268 | (or (filtered-frame-list | |
269 | (function | |
270 | (lambda (frame) | |
271 | (eq (cdr (assq 'minibuffer | |
272 | (frame-parameters frame))) | |
273 | 'only)))) | |
274 | (minibuffer-frame-list)))) | |
275 | (new-minibuffer (minibuffer-window new-surrogate))) | |
276 | ||
277 | (if (eq default-minibuffer-frame frame-initial-frame) | |
278 | (setq default-minibuffer-frame new-surrogate)) | |
279 | ||
280 | ;; Wean the frames using frame-initial-frame as | |
281 | ;; their minibuffer frame. | |
282 | (mapcar | |
283 | (function | |
284 | (lambda (frame) | |
285 | (modify-frame-parameters | |
286 | frame (list (cons 'minibuffer new-minibuffer))))) | |
287 | users-of-initial)))) | |
ec558adc JB |
288 | |
289 | ;; Redirect events enqueued at this frame to the new frame. | |
290 | ;; Is this a good idea? | |
7eadab74 | 291 | (redirect-frame-focus frame-initial-frame new) |
ec558adc | 292 | |
7eadab74 | 293 | ;; Finally, get rid of the old frame. |
0cffbbb9 | 294 | (delete-frame frame-initial-frame t)) |
7eadab74 JB |
295 | |
296 | ;; Otherwise, we don't need all that rigamarole; just apply | |
297 | ;; the new parameters. | |
3f2f8c83 RS |
298 | (let (newparms allparms tail) |
299 | (setq allparms (append initial-frame-alist | |
300 | default-frame-alist)) | |
5b66a32f RS |
301 | (if (assq 'height frame-initial-geometry-arguments) |
302 | (setq allparms (frame-delete-all 'height allparms))) | |
303 | (if (assq 'width frame-initial-geometry-arguments) | |
304 | (setq allparms (frame-delete-all 'width allparms))) | |
305 | (if (assq 'left frame-initial-geometry-arguments) | |
306 | (setq allparms (frame-delete-all 'left allparms))) | |
307 | (if (assq 'top frame-initial-geometry-arguments) | |
308 | (setq allparms (frame-delete-all 'top allparms))) | |
3f2f8c83 RS |
309 | (setq tail allparms) |
310 | ;; Find just the parms that have changed since we first | |
311 | ;; made this frame. Those are the ones actually set by | |
312 | ;; the init file. For those parms whose values we already knew | |
313 | ;; (such as those spec'd by command line options) | |
314 | ;; it is undesirable to specify the parm again | |
315 | ;; once the user has seen the frame and been able to alter it | |
316 | ;; manually. | |
317 | (while tail | |
318 | (let (newval oldval) | |
319 | (setq oldval (cdr (assq (car (car tail)) | |
320 | frame-initial-frame-alist))) | |
321 | (setq newval (cdr (assq (car (car tail)) allparms))) | |
322 | (or (eq oldval newval) | |
323 | (setq newparms | |
324 | (cons (cons (car (car tail)) newval) newparms)))) | |
325 | (setq tail (cdr tail))) | |
86e58378 | 326 | (setq newparms (nreverse newparms)) |
3f2f8c83 | 327 | (modify-frame-parameters frame-initial-frame |
86e58378 RS |
328 | newparms) |
329 | (if (assq 'font newparms) | |
330 | (frame-update-faces frame-initial-frame))))) | |
64c669bc | 331 | |
7eadab74 JB |
332 | ;; Restore the original buffer. |
333 | (set-buffer old-buffer) | |
334 | ||
335 | ;; Make sure the initial frame can be GC'd if it is ever deleted. | |
d202f1f2 JB |
336 | ;; Make sure frame-notice-user-settings does nothing if called twice. |
337 | (setq frame-initial-frame nil))) | |
64c669bc | 338 | |
5b66a32f RS |
339 | ;; Delete from ALIST all elements whose car is KEY. |
340 | ;; Return the modified alist. | |
341 | (defun frame-delete-all (key alist) | |
9759578f | 342 | (setq alist (copy-sequence alist)) |
5b66a32f RS |
343 | (let ((tail alist)) |
344 | (while tail | |
345 | (if (eq (car (car tail)) key) | |
346 | (setq alist (delq (car tail) alist))) | |
347 | (setq tail (cdr tail))) | |
348 | alist)) | |
64c669bc | 349 | \f |
7eadab74 | 350 | ;;;; Creation of additional frames, and other frame miscellanea |
dc6d9681 | 351 | |
7eadab74 | 352 | ;;; Return some frame other than the current frame, creating one if |
eb8c3be9 | 353 | ;;; necessary. Note that the minibuffer frame, if separate, is not |
7eadab74 | 354 | ;;; considered (see next-frame). |
7253d8e0 | 355 | (defun get-other-frame () |
dc6d9681 | 356 | (let ((s (if (equal (next-frame (selected-frame)) (selected-frame)) |
6eb018ba | 357 | (make-frame) |
dc6d9681 | 358 | (next-frame (selected-frame))))) |
64c669bc JB |
359 | s)) |
360 | ||
dc6d9681 JB |
361 | (defun next-multiframe-window () |
362 | "Select the next window, regardless of which frame it is on." | |
64c669bc JB |
363 | (interactive) |
364 | (select-window (next-window (selected-window) | |
365 | (> (minibuffer-depth) 0) | |
366 | t))) | |
367 | ||
dc6d9681 JB |
368 | (defun previous-multiframe-window () |
369 | "Select the previous window, regardless of which frame it is on." | |
64c669bc JB |
370 | (interactive) |
371 | (select-window (previous-window (selected-window) | |
372 | (> (minibuffer-depth) 0) | |
373 | t))) | |
374 | ||
92e443b1 | 375 | ;; Alias, kept temporarily. |
31e1d920 | 376 | (defalias 'new-frame 'make-frame) |
92e443b1 | 377 | (defun make-frame (&optional parameters) |
dc6d9681 | 378 | "Create a new frame, displaying the current buffer. |
bc93c097 | 379 | |
43a2e52c | 380 | Optional argument PARAMETERS is an alist of parameters for the new |
dc6d9681 | 381 | frame. Specifically, PARAMETERS is a list of pairs, each having one |
43a2e52c JB |
382 | of the following forms: |
383 | ||
eaa974e1 | 384 | \(name . STRING) - The frame should be named STRING. |
43a2e52c | 385 | |
eaa974e1 | 386 | \(height . NUMBER) - The frame should be NUMBER text lines high. If |
43a2e52c JB |
387 | this parameter is present, the width parameter must also be |
388 | given. | |
389 | ||
eaa974e1 | 390 | \(width . NUMBER) - The frame should be NUMBER characters in width. |
43a2e52c JB |
391 | If this parameter is present, the height parameter must also |
392 | be given. | |
393 | ||
eaa974e1 | 394 | \(minibuffer . t) - the frame should have a minibuffer |
0ca90494 | 395 | \(minibuffer . nil) - the frame should have no minibuffer |
eaa974e1 | 396 | \(minibuffer . only) - the frame should contain only a minibuffer |
8dbd5c78 | 397 | \(minibuffer . WINDOW) - the frame should use WINDOW as its minibuffer window." |
64c669bc | 398 | (interactive) |
4133ab49 RS |
399 | (let ((nframe)) |
400 | (run-hooks 'before-make-frame-hook) | |
401 | (setq nframe (funcall frame-creation-function parameters)) | |
402 | (run-hooks 'after-make-frame-hook) | |
403 | nframe)) | |
64c669bc | 404 | |
7eadab74 JB |
405 | (defun filtered-frame-list (predicate) |
406 | "Return a list of all live frames which satisfy PREDICATE." | |
407 | (let ((frames (frame-list)) | |
408 | good-frames) | |
409 | (while (consp frames) | |
410 | (if (funcall predicate (car frames)) | |
411 | (setq good-frames (cons (car frames) good-frames))) | |
412 | (setq frames (cdr frames))) | |
413 | good-frames)) | |
414 | ||
415 | (defun minibuffer-frame-list () | |
416 | "Return a list of all frames with their own minibuffers." | |
417 | (filtered-frame-list | |
418 | (function (lambda (frame) | |
419 | (eq frame (window-frame (minibuffer-window frame))))))) | |
420 | ||
58bf6042 JB |
421 | (defun frame-remove-geometry-params (param-list) |
422 | "Return the parameter list PARAM-LIST, but with geometry specs removed. | |
423 | This deletes all bindings in PARAM-LIST for `top', `left', `width', | |
791e09d8 | 424 | `height', `user-size' and `user-position' parameters. |
58bf6042 JB |
425 | Emacs uses this to avoid overriding explicit moves and resizings from |
426 | the user during startup." | |
427 | (setq param-list (cons nil param-list)) | |
428 | (let ((tail param-list)) | |
429 | (while (consp (cdr tail)) | |
430 | (if (and (consp (car (cdr tail))) | |
791e09d8 RS |
431 | (memq (car (car (cdr tail))) |
432 | '(height width top left user-position user-size))) | |
433 | (progn | |
434 | (setq frame-initial-geometry-arguments | |
435 | (cons (car (cdr tail)) frame-initial-geometry-arguments)) | |
436 | (setcdr tail (cdr (cdr tail)))) | |
58bf6042 | 437 | (setq tail (cdr tail))))) |
e11c3dc2 KH |
438 | (setq frame-initial-geometry-arguments |
439 | (nreverse frame-initial-geometry-arguments)) | |
58bf6042 JB |
440 | (cdr param-list)) |
441 | ||
442 | ||
ceab6935 | 443 | (defun other-frame (arg) |
a569dbc3 | 444 | "Select the ARG'th different visible frame, and raise it. |
ceab6935 RM |
445 | All frames are arranged in a cyclic order. |
446 | This command selects the frame ARG steps away in that order. | |
447 | A negative ARG moves in the opposite order." | |
448 | (interactive "p") | |
449 | (let ((frame (selected-frame))) | |
450 | (while (> arg 0) | |
a569dbc3 RM |
451 | (setq frame (next-frame frame)) |
452 | (while (not (eq (frame-visible-p frame) t)) | |
453 | (setq frame (next-frame frame))) | |
454 | (setq arg (1- arg))) | |
ceab6935 | 455 | (while (< arg 0) |
a569dbc3 RM |
456 | (setq frame (previous-frame frame)) |
457 | (while (not (eq (frame-visible-p frame) t)) | |
458 | (setq frame (previous-frame frame))) | |
915cfd1f | 459 | (setq arg (1+ arg))) |
ceab6935 | 460 | (raise-frame frame) |
699213bc | 461 | (select-frame frame) |
2b88f7a0 | 462 | (set-mouse-position (selected-frame) (1- (frame-width)) 0) |
699213bc | 463 | (unfocus-frame))) |
64c669bc | 464 | \f |
dc6d9681 JB |
465 | ;;;; Frame configurations |
466 | ||
467 | (defun current-frame-configuration () | |
468 | "Return a list describing the positions and states of all frames. | |
376a7584 JB |
469 | Its car is `frame-configuration'. |
470 | Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG), | |
471 | where | |
472 | FRAME is a frame object, | |
473 | ALIST is an association list specifying some of FRAME's parameters, and | |
474 | WINDOW-CONFIG is a window configuration object for FRAME." | |
475 | (cons 'frame-configuration | |
476 | (mapcar (function | |
477 | (lambda (frame) | |
478 | (list frame | |
479 | (frame-parameters frame) | |
480 | (current-window-configuration frame)))) | |
481 | (frame-list)))) | |
dc6d9681 | 482 | |
68cd265f | 483 | (defun set-frame-configuration (configuration &optional nodelete) |
dc6d9681 JB |
484 | "Restore the frames to the state described by CONFIGURATION. |
485 | Each frame listed in CONFIGURATION has its position, size, window | |
68cd265f | 486 | configuration, and other parameters set as specified in CONFIGURATION. |
a78db71c RS |
487 | Ordinarily, this function deletes all existing frames not |
488 | listed in CONFIGURATION. But if optional second argument NODELETE | |
5da841d2 | 489 | is given and non-nil, the unwanted frames are iconified instead." |
376a7584 JB |
490 | (or (frame-configuration-p configuration) |
491 | (signal 'wrong-type-argument | |
492 | (list 'frame-configuration-p configuration))) | |
493 | (let ((config-alist (cdr configuration)) | |
494 | frames-to-delete) | |
06b1a5ef | 495 | (mapcar (function |
dc6d9681 | 496 | (lambda (frame) |
376a7584 | 497 | (let ((parameters (assq frame config-alist))) |
06b1a5ef JB |
498 | (if parameters |
499 | (progn | |
98e9d14b JB |
500 | (modify-frame-parameters |
501 | frame | |
502 | ;; Since we can't set a frame's minibuffer status, | |
503 | ;; we might as well omit the parameter altogether. | |
504 | (let* ((parms (nth 1 parameters)) | |
505 | (mini (assq 'minibuffer parms))) | |
506 | (if mini (setq parms (delq mini parms))) | |
507 | parms)) | |
06b1a5ef | 508 | (set-window-configuration (nth 2 parameters))) |
dc6d9681 JB |
509 | (setq frames-to-delete (cons frame frames-to-delete)))))) |
510 | (frame-list)) | |
a78db71c | 511 | (if nodelete |
5da841d2 RS |
512 | ;; Note: making frames invisible here was tried |
513 | ;; but led to some strange behavior--each time the frame | |
514 | ;; was made visible again, the window manager asked afresh | |
515 | ;; for where to put it. | |
516 | (mapcar 'iconify-frame frames-to-delete) | |
a78db71c | 517 | (mapcar 'delete-frame frames-to-delete)))) |
64c669bc | 518 | |
376a7584 JB |
519 | (defun frame-configuration-p (object) |
520 | "Return non-nil if OBJECT seems to be a frame configuration. | |
521 | Any list whose car is `frame-configuration' is assumed to be a frame | |
522 | configuration." | |
523 | (and (consp object) | |
524 | (eq (car object) 'frame-configuration))) | |
525 | ||
64c669bc | 526 | \f |
dc6d9681 JB |
527 | ;;;; Convenience functions for accessing and interactively changing |
528 | ;;;; frame parameters. | |
64c669bc | 529 | |
151bdc83 | 530 | (defun frame-height (&optional frame) |
dc6d9681 JB |
531 | "Return number of lines available for display on FRAME. |
532 | If FRAME is omitted, describe the currently selected frame." | |
151bdc83 | 533 | (cdr (assq 'height (frame-parameters frame)))) |
dc6d9681 JB |
534 | |
535 | (defun frame-width (&optional frame) | |
536 | "Return number of columns available for display on FRAME. | |
537 | If FRAME is omitted, describe the currently selected frame." | |
151bdc83 | 538 | (cdr (assq 'width (frame-parameters frame)))) |
dc6d9681 | 539 | |
64c669bc | 540 | (defun set-default-font (font-name) |
7eadab74 JB |
541 | "Set the font of the selected frame to FONT. |
542 | When called interactively, prompt for the name of the font to use." | |
64c669bc | 543 | (interactive "sFont name: ") |
dc6d9681 | 544 | (modify-frame-parameters (selected-frame) |
4033f46b RS |
545 | (list (cons 'font font-name))) |
546 | ;; Update faces that want a bold or italic version of the default font. | |
547 | (frame-update-faces (selected-frame))) | |
64c669bc | 548 | |
8290babd | 549 | (defun set-background-color (color-name) |
7eadab74 JB |
550 | "Set the background color of the selected frame to COLOR. |
551 | When called interactively, prompt for the name of the color to use." | |
64c669bc | 552 | (interactive "sColor: ") |
dc6d9681 | 553 | (modify-frame-parameters (selected-frame) |
7eadab74 | 554 | (list (cons 'background-color color-name)))) |
64c669bc | 555 | |
8290babd | 556 | (defun set-foreground-color (color-name) |
7eadab74 JB |
557 | "Set the foreground color of the selected frame to COLOR. |
558 | When called interactively, prompt for the name of the color to use." | |
64c669bc | 559 | (interactive "sColor: ") |
dc6d9681 | 560 | (modify-frame-parameters (selected-frame) |
7eadab74 | 561 | (list (cons 'foreground-color color-name)))) |
64c669bc JB |
562 | |
563 | (defun set-cursor-color (color-name) | |
7eadab74 JB |
564 | "Set the text cursor color of the selected frame to COLOR. |
565 | When called interactively, prompt for the name of the color to use." | |
64c669bc | 566 | (interactive "sColor: ") |
dc6d9681 | 567 | (modify-frame-parameters (selected-frame) |
7eadab74 | 568 | (list (cons 'cursor-color color-name)))) |
64c669bc | 569 | |
eaa974e1 | 570 | (defun set-mouse-color (color-name) |
7eadab74 JB |
571 | "Set the color of the mouse pointer of the selected frame to COLOR. |
572 | When called interactively, prompt for the name of the color to use." | |
64c669bc | 573 | (interactive "sColor: ") |
dc6d9681 | 574 | (modify-frame-parameters (selected-frame) |
7eadab74 JB |
575 | (list (cons 'mouse-color color-name)))) |
576 | ||
eaa974e1 JB |
577 | (defun set-border-color (color-name) |
578 | "Set the color of the border of the selected frame to COLOR. | |
579 | When called interactively, prompt for the name of the color to use." | |
580 | (interactive "sColor: ") | |
581 | (modify-frame-parameters (selected-frame) | |
582 | (list (cons 'border-color color-name)))) | |
583 | ||
584 | (defun auto-raise-mode (arg) | |
7eadab74 | 585 | "Toggle whether or not the selected frame should auto-raise. |
79e6ae33 RS |
586 | With arg, turn auto-raise mode on if and only if arg is positive. |
587 | Note that this controls Emacs's own auto-raise feature. | |
588 | Some window managers allow you to enable auto-raise for certain windows. | |
589 | You can use that for Emacs windows if you wish, but if you do, | |
590 | that is beyond the control of Emacs and this command has no effect on it." | |
7eadab74 JB |
591 | (interactive "P") |
592 | (if (null arg) | |
593 | (setq arg | |
594 | (if (cdr (assq 'auto-raise (frame-parameters (selected-frame)))) | |
595 | -1 1))) | |
dc6d9681 | 596 | (modify-frame-parameters (selected-frame) |
7eadab74 JB |
597 | (list (cons 'auto-raise (> arg 0))))) |
598 | ||
eaa974e1 | 599 | (defun auto-lower-mode (arg) |
7eadab74 | 600 | "Toggle whether or not the selected frame should auto-lower. |
79e6ae33 RS |
601 | With arg, turn auto-lower mode on if and only if arg is positive. |
602 | Note that this controls Emacs's own auto-lower feature. | |
603 | Some window managers allow you to enable auto-lower for certain windows. | |
604 | You can use that for Emacs windows if you wish, but if you do, | |
605 | that is beyond the control of Emacs and this command has no effect on it." | |
7eadab74 JB |
606 | (interactive "P") |
607 | (if (null arg) | |
608 | (setq arg | |
609 | (if (cdr (assq 'auto-lower (frame-parameters (selected-frame)))) | |
610 | -1 1))) | |
dc6d9681 | 611 | (modify-frame-parameters (selected-frame) |
7eadab74 JB |
612 | (list (cons 'auto-lower (> arg 0))))) |
613 | ||
7e85c6b5 | 614 | (defun toggle-scroll-bar (arg) |
0ca90494 JB |
615 | "Toggle whether or not the selected frame has vertical scroll bars. |
616 | With arg, turn vertical scroll bars on if and only if arg is positive." | |
7eadab74 JB |
617 | (interactive "P") |
618 | (if (null arg) | |
619 | (setq arg | |
0ca90494 | 620 | (if (cdr (assq 'vertical-scroll-bars |
7eadab74 JB |
621 | (frame-parameters (selected-frame)))) |
622 | -1 1))) | |
dc6d9681 | 623 | (modify-frame-parameters (selected-frame) |
0ca90494 | 624 | (list (cons 'vertical-scroll-bars (> arg 0))))) |
7eadab74 | 625 | |
8290babd | 626 | (defun toggle-horizontal-scroll-bar (arg) |
0ca90494 JB |
627 | "Toggle whether or not the selected frame has horizontal scroll bars. |
628 | With arg, turn horizontal scroll bars on if and only if arg is positive. | |
629 | Horizontal scroll bars aren't implemented yet." | |
7eadab74 | 630 | (interactive "P") |
8290babd | 631 | (error "Horizontal scroll bars aren't implemented yet")) |
64c669bc | 632 | |
64c669bc | 633 | \f |
dc6d9681 | 634 | ;;;; Aliases for backward compatibility with Emacs 18. |
31e1d920 ER |
635 | (defalias 'screen-height 'frame-height) |
636 | (defalias 'screen-width 'frame-width) | |
9e2b097b JB |
637 | |
638 | (defun set-screen-width (cols &optional pretend) | |
639 | "Obsolete function to change the size of the screen to COLS columns.\n\ | |
640 | Optional second arg non-nil means that redisplay should use COLS columns\n\ | |
641 | but that the idea of the actual width of the frame should not be changed.\n\ | |
642 | This function is provided only for compatibility with Emacs 18; new code\n\ | |
fe668515 | 643 | should use `set-frame-width instead'." |
9e2b097b JB |
644 | (set-frame-width (selected-frame) cols pretend)) |
645 | ||
646 | (defun set-screen-height (lines &optional pretend) | |
647 | "Obsolete function to change the height of the screen to LINES lines.\n\ | |
648 | Optional second arg non-nil means that redisplay should use LINES lines\n\ | |
649 | but that the idea of the actual height of the screen should not be changed.\n\ | |
650 | This function is provided only for compatibility with Emacs 18; new code\n\ | |
fe668515 | 651 | should use `set-frame-width' instead." |
9e2b097b JB |
652 | (set-frame-height (selected-frame) lines pretend)) |
653 | ||
654 | (make-obsolete 'screen-height 'frame-height) | |
655 | (make-obsolete 'screen-width 'frame-width) | |
656 | (make-obsolete 'set-screen-width 'set-frame-width) | |
657 | (make-obsolete 'set-screen-height 'set-frame-height) | |
dc6d9681 JB |
658 | |
659 | \f | |
64c669bc | 660 | ;;;; Key bindings |
daa37602 | 661 | (defvar ctl-x-5-map (make-sparse-keymap) |
dc6d9681 | 662 | "Keymap for frame commands.") |
31e1d920 | 663 | (defalias 'ctl-x-5-prefix ctl-x-5-map) |
daa37602 | 664 | (define-key ctl-x-map "5" 'ctl-x-5-prefix) |
64c669bc | 665 | |
6eb018ba | 666 | (define-key ctl-x-5-map "2" 'make-frame) |
dc6d9681 | 667 | (define-key ctl-x-5-map "0" 'delete-frame) |
ceab6935 | 668 | (define-key ctl-x-5-map "o" 'other-frame) |
49116ac0 | 669 | |
dc6d9681 | 670 | (provide 'frame) |
c88ab9ce | 671 | |
dc6d9681 | 672 | ;;; frame.el ends here |