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