0
|
1 ;;; frame.el --- multi-frame management independent of window systems.
|
|
2
|
|
3 ;;;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
|
|
4 ;;;; Copyright (C) 1995, 1996 Ben Wing.
|
|
5
|
|
6 ;; Maintainer: FSF
|
|
7 ;; Keywords: internal
|
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
12 ;; 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 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 ;; General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
16
|
22 ;; along with XEmacs; 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.
|
0
|
25
|
|
26 ;;; Synched up with: FSF 19.30.
|
|
27
|
|
28 ;;; Code:
|
|
29
|
|
30 ; No need for `frame-creation-function'.
|
|
31
|
|
32 ;;; The initial value given here for this must ask for a minibuffer.
|
|
33 ;;; There must always exist a frame with a minibuffer, and after we
|
|
34 ;;; delete the terminal frame, this will be the only frame.
|
|
35 (defvar initial-frame-plist '(minibuffer t)
|
|
36 "Plist of frame properties for creating the initial X window frame.
|
|
37 You can set this in your `.emacs' file; for example,
|
|
38 (setq initial-frame-plist '(top 1 left 1 width 80 height 55))
|
|
39 Properties specified here supersede the values given in `default-frame-plist'.
|
|
40 The format of this can also be an alist for backward compatibility.
|
|
41
|
|
42 If the value calls for a frame without a minibuffer, and you have not created
|
|
43 a minibuffer frame on your own, one is created according to
|
|
44 `minibuffer-frame-plist'.
|
|
45
|
|
46 You can specify geometry-related options for just the initial frame
|
|
47 by setting this variable in your `.emacs' file; however, they won't
|
|
48 take effect until Emacs reads `.emacs', which happens after first creating
|
|
49 the frame. If you want the frame to have the proper geometry as soon
|
|
50 as it appears, you need to use this three-step process:
|
|
51 * Specify X resources to give the geometry you want.
|
|
52 * Set `default-frame-plist' to override these options so that they
|
|
53 don't affect subsequent frames.
|
|
54 * Set `initial-frame-plist' in a way that matches the X resources,
|
|
55 to override what you put in `default-frame-plist'.")
|
|
56
|
|
57 (defvar minibuffer-frame-plist '(width 80 height 2 menubar-visible-p nil
|
|
58 default-toolbar-visible-p nil)
|
|
59 "Plist of frame properties for initially creating a minibuffer frame.
|
|
60 You can set this in your `.emacs' file; for example,
|
|
61 (setq minibuffer-frame-plist '(top 1 left 1 width 80 height 2))
|
|
62 Properties specified here supersede the values given in
|
|
63 `default-frame-plist'.
|
|
64 The format of this can also be an alist for backward compatibility.")
|
|
65
|
|
66 (defvar pop-up-frame-plist nil
|
|
67 "Plist of frame properties used when creating pop-up frames.
|
|
68 Pop-up frames are used for completions, help, and the like.
|
|
69 This variable can be set in your init file, like this:
|
|
70 (setq pop-up-frame-plist '(width 80 height 20))
|
|
71 These supersede the values given in `default-frame-plist'.
|
|
72 The format of this can also be an alist for backward compatibility.")
|
|
73
|
|
74 (setq pop-up-frame-function
|
|
75 (function (lambda ()
|
|
76 (make-frame pop-up-frame-plist))))
|
|
77
|
|
78 (defvar special-display-frame-plist '(height 14 width 80 unsplittable t)
|
|
79 "*Plist of frame properties used when creating special frames.
|
|
80 Special frames are used for buffers whose names are in
|
|
81 `special-display-buffer-names' and for buffers whose names match
|
|
82 one of the regular expressions in `special-display-regexps'.
|
|
83 This variable can be set in your init file, like this:
|
|
84 (setq special-display-frame-plist '(width 80 height 20))
|
|
85 These supersede the values given in `default-frame-plist'.
|
|
86 The format of this can also be an alist for backward compatibility.")
|
|
87
|
|
88 (defun safe-alist-to-plist (cruftiness)
|
|
89 (if (consp (car cruftiness))
|
|
90 (alist-to-plist cruftiness)
|
|
91 cruftiness))
|
|
92
|
|
93 ;; Display BUFFER in its own frame, reusing an existing window if any.
|
|
94 ;; Return the window chosen.
|
|
95 ;; Currently we do not insist on selecting the window within its frame.
|
|
96 ;; If ARGS is a plist, use it as a list of frame property specs.
|
|
97 ;; #### Change, not compatible with FSF: This stuff is all so incredibly
|
|
98 ;; junky anyway that I doubt it makes any difference.
|
|
99 ;; If ARGS is a list whose car is t,
|
|
100 ;; use (cadr ARGS) as a function to do the work.
|
|
101 ;; Pass it BUFFER as first arg, and (cddr ARGS) gives the rest of the args.
|
|
102 (defun special-display-popup-frame (buffer &optional args)
|
|
103 ;; if we can't display simultaneous multiple frames, just return
|
|
104 ;; nil and let the normal behavior take over.
|
|
105 (and (device-on-window-system-p)
|
|
106 (if (and args (eq t (car args)))
|
|
107 (apply (cadr args) buffer (cddr args))
|
|
108 (let ((window (get-buffer-window buffer t)))
|
|
109 (if window
|
|
110 ;; If we have a window already, make it visible.
|
|
111 (let ((frame (window-frame window)))
|
|
112 (make-frame-visible frame)
|
|
113 (raise-frame frame)
|
|
114 window)
|
|
115 ;; If no window yet, make one in a new frame.
|
|
116 (let ((frame
|
|
117 (make-frame (append (safe-alist-to-plist args)
|
|
118 (safe-alist-to-plist
|
|
119 special-display-frame-plist)))))
|
|
120 (set-window-buffer (frame-selected-window frame) buffer)
|
|
121 (set-window-dedicated-p (frame-selected-window frame) t)
|
|
122 (frame-selected-window frame)))))))
|
|
123
|
|
124 (setq special-display-function 'special-display-popup-frame)
|
|
125
|
|
126 ;;; Handle delete-frame events from the X server.
|
|
127 ;(defun handle-delete-frame (event)
|
|
128 ; (interactive "e")
|
|
129 ; (let ((frame (posn-window (event-start event)))
|
|
130 ; (i 0)
|
|
131 ; (tail (frame-list)))
|
|
132 ; (while tail
|
|
133 ; (and (frame-visible-p (car tail))
|
|
134 ; (not (eq (car tail) frame))
|
|
135 ; (setq i (1+ i)))
|
|
136 ; (setq tail (cdr tail)))
|
|
137 ; (if (> i 0)
|
|
138 ; (delete-frame frame t)
|
|
139 ; (kill-emacs))))
|
|
140
|
|
141
|
|
142 ;;;; Arrangement of frames at startup
|
|
143
|
|
144 ;;; 1) Load the window system startup file from the lisp library and read the
|
|
145 ;;; high-priority arguments (-q and the like). The window system startup
|
|
146 ;;; file should create any frames specified in the window system defaults.
|
|
147 ;;;
|
|
148 ;;; 2) If no frames have been opened, we open an initial text frame.
|
|
149 ;;;
|
|
150 ;;; 3) Once the init file is done, we apply any newly set properties
|
|
151 ;;; in initial-frame-plist to the frame.
|
|
152
|
|
153 ;; These are now called explicitly at the proper times,
|
|
154 ;; since that is easier to understand.
|
|
155 ;; Actually using hooks within Emacs is bad for future maintenance. --rms.
|
|
156 ;; (add-hook 'before-init-hook 'frame-initialize)
|
|
157 ;; (add-hook 'window-setup-hook 'frame-notice-user-settings)
|
|
158
|
|
159 ;;; If we create the initial frame, this is it.
|
|
160 (defvar frame-initial-frame nil)
|
|
161
|
|
162 ;; Record the properties used in frame-initialize to make the initial frame.
|
|
163 (defvar frame-initial-frame-plist)
|
|
164
|
|
165 (defvar frame-initial-geometry-arguments nil)
|
|
166
|
|
167 (defun canonicalize-frame-plists ()
|
|
168 (setq initial-frame-plist (safe-alist-to-plist initial-frame-plist))
|
|
169 (setq default-frame-plist (safe-alist-to-plist default-frame-plist)))
|
|
170
|
|
171 ;;; startup.el calls this function before loading the user's init
|
|
172 ;;; file - if there is no frame with a minibuffer open now, create
|
|
173 ;;; one to display messages while loading the init file.
|
|
174 (defun frame-initialize ()
|
|
175 ;; In batch mode, we actually use the initial terminal device for output.
|
|
176 (canonicalize-frame-plists)
|
|
177 (if (not (noninteractive))
|
|
178 (progn
|
|
179 ;; Don't call select-frame here - focus is a matter of WM policy.
|
|
180
|
|
181 ;; If there is no frame with a minibuffer besides the terminal
|
|
182 ;; frame, then we need to create the opening frame. Make sure
|
|
183 ;; it has a minibuffer, but let initial-frame-plist omit the
|
|
184 ;; minibuffer spec.
|
|
185 (or (delq terminal-frame (minibuffer-frame-list))
|
|
186 (progn
|
|
187 (setq frame-initial-frame-plist
|
|
188 (append initial-frame-plist default-frame-plist))
|
|
189 ;; FSFmacs has scroll-bar junk here that we don't need.
|
|
190 (setq default-minibuffer-frame
|
|
191 (setq frame-initial-frame
|
|
192 (make-frame initial-frame-plist
|
|
193 (car (delq terminal-device
|
|
194 (device-list))))))
|
|
195 ;; Delete any specifications for window geometry properties
|
|
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.
|
|
199 (setq initial-frame-plist
|
|
200 (frame-remove-geometry-props initial-frame-plist))))
|
|
201 ;; At this point, we know that we have a frame open, so we
|
|
202 ;; can delete the terminal device.
|
|
203 (delete-device terminal-device)
|
|
204 (setq terminal-frame nil)
|
|
205
|
|
206 ;; FSFmacs sets frame-creation-function here, but no need.
|
|
207 )))
|
|
208
|
|
209 ;;; startup.el calls this function after loading the user's init
|
|
210 ;;; file. Now default-frame-plist and initial-frame-plist contain
|
|
211 ;;; information to which we must react; do what needs to be done.
|
|
212 (defun frame-notice-user-settings ()
|
|
213
|
|
214 ;; FSFmacs has menu-bar junk here that we don't need.
|
|
215
|
|
216 (canonicalize-frame-plists)
|
|
217
|
|
218 ;; Creating and deleting frames may shift the selected frame around,
|
|
219 ;; and thus the current buffer. Protect against that. We don't
|
|
220 ;; want to use save-excursion here, because that may also try to set
|
|
221 ;; the buffer of the selected window, which fails when the selected
|
|
222 ;; window is the minibuffer.
|
|
223 (let ((old-buffer (current-buffer)))
|
|
224
|
|
225 ;; If the initial frame is still around, apply initial-frame-plist
|
|
226 ;; and default-frame-plist to it.
|
|
227 (if (frame-live-p frame-initial-frame)
|
|
228
|
|
229 ;; The initial frame we create above always has a minibuffer.
|
|
230 ;; If the user wants to remove it, or make it a minibuffer-only
|
|
231 ;; frame, then we'll have to delete the current frame and make a
|
|
232 ;; new one; you can't remove or add a root window to/from an
|
|
233 ;; existing frame.
|
|
234 ;;
|
|
235 ;; NOTE: default-frame-plist was nil when we created the
|
|
236 ;; existing frame. We need to explicitly include
|
|
237 ;; default-frame-plist in the properties of the screen we
|
|
238 ;; create here, so that its new value, gleaned from the user's
|
|
239 ;; .emacs file, will be applied to the existing screen.
|
|
240 (if (not (eq (car
|
|
241 (or (and (lax-plist-member
|
|
242 initial-frame-plist 'minibuffer)
|
|
243 (list (lax-plist-get initial-frame-plist
|
|
244 'minibuffer)))
|
|
245 (and (lax-plist-member default-frame-plist
|
|
246 'minibuffer)
|
|
247 (list (lax-plist-get default-frame-plist
|
|
248 'minibuffer)))
|
|
249 '(t)))
|
|
250 t))
|
|
251 ;; Create the new frame.
|
|
252 (let (props
|
|
253 )
|
|
254 ;; If the frame isn't visible yet, wait till it is.
|
|
255 ;; If the user has to position the window,
|
|
256 ;; Emacs doesn't know its real position until
|
|
257 ;; the frame is seen to be visible.
|
|
258
|
|
259 (if (frame-property frame-initial-frame 'initially-unmapped)
|
|
260 nil
|
|
261 (while (not (frame-visible-p frame-initial-frame))
|
|
262 (sleep-for 1)))
|
|
263 (setq props (frame-properties frame-initial-frame))
|
|
264 ;; Get rid of `name' unless it was specified explicitly before.
|
|
265 (or (lax-plist-member frame-initial-frame-plist 'name)
|
|
266 (setq props (lax-plist-remprop props 'name)))
|
|
267 (setq props (append initial-frame-plist default-frame-plist
|
|
268 props
|
|
269 nil))
|
|
270 ;; Get rid of `reverse', because that was handled
|
|
271 ;; when we first made the frame.
|
|
272 (laxputf props 'reverse nil)
|
|
273 ;; Get rid of `window-id', otherwise make-frame will
|
|
274 ;; think we're trying to setup an external widget.
|
|
275 (laxremf props 'window-id)
|
|
276 (if (lax-plist-member frame-initial-geometry-arguments 'height)
|
|
277 (laxremf props 'height))
|
|
278 (if (lax-plist-member frame-initial-geometry-arguments 'width)
|
|
279 (laxremf props 'width))
|
|
280 (if (lax-plist-member frame-initial-geometry-arguments 'left)
|
|
281 (laxremf props 'left))
|
|
282 (if (lax-plist-member frame-initial-geometry-arguments 'top)
|
|
283 (laxremf props 'top))
|
|
284
|
|
285 ;; Now create the replacement initial frame.
|
|
286 (make-frame
|
|
287 ;; Use the geometry args that created the existing
|
|
288 ;; frame, rather than the props we get for it.
|
|
289 (append '(user-size t user-position t)
|
|
290 frame-initial-geometry-arguments
|
|
291 props))
|
|
292 ;; The initial frame, which we are about to delete, may be
|
|
293 ;; the only frame with a minibuffer. If it is, create a
|
|
294 ;; new one.
|
|
295 (or (delq frame-initial-frame (minibuffer-frame-list))
|
|
296 (make-initial-minibuffer-frame nil))
|
|
297
|
|
298 ;; If the initial frame is serving as a surrogate
|
|
299 ;; minibuffer frame for any frames, we need to wean them
|
|
300 ;; onto a new frame. The default-minibuffer-frame
|
|
301 ;; variable must be handled similarly.
|
|
302 (let ((users-of-initial
|
|
303 (filtered-frame-list
|
|
304 #'(lambda (frame)
|
|
305 (and (not (eq frame frame-initial-frame))
|
|
306 (eq (window-frame
|
|
307 (minibuffer-window frame))
|
|
308 frame-initial-frame))))))
|
|
309 (if (or users-of-initial
|
|
310 (eq default-minibuffer-frame frame-initial-frame))
|
|
311
|
|
312 ;; Choose an appropriate frame. Prefer frames which
|
|
313 ;; are only minibuffers.
|
|
314 (let* ((new-surrogate
|
|
315 (car
|
|
316 (or (filtered-frame-list
|
|
317 #'(lambda (frame)
|
|
318 (eq 'only
|
|
319 (frame-property frame 'minibuffer))))
|
|
320 (minibuffer-frame-list))))
|
|
321 (new-minibuffer (minibuffer-window new-surrogate)))
|
|
322
|
|
323 (if (eq default-minibuffer-frame frame-initial-frame)
|
|
324 (setq default-minibuffer-frame new-surrogate))
|
|
325
|
|
326 ;; Wean the frames using frame-initial-frame as
|
|
327 ;; their minibuffer frame.
|
|
328 (mapcar
|
|
329 #'
|
|
330 (lambda (frame)
|
|
331 (set-frame-property frame 'minibuffer
|
|
332 new-minibuffer))
|
|
333 users-of-initial))))
|
|
334
|
|
335 ;; Redirect events enqueued at this frame to the new frame.
|
|
336 ;; Is this a good idea?
|
|
337 ;; Probably not, since this whole redirect-frame-focus
|
|
338 ;; stuff is a load of trash, and so is this function we're in.
|
|
339 ;; --ben
|
|
340 ;(redirect-frame-focus frame-initial-frame new)
|
|
341
|
|
342 ;; Finally, get rid of the old frame.
|
|
343 (delete-frame frame-initial-frame t))
|
|
344
|
|
345 ;; Otherwise, we don't need all that rigamarole; just apply
|
|
346 ;; the new properties.
|
|
347 (let (newprops allprops tail)
|
|
348 (setq allprops (append initial-frame-plist
|
|
349 default-frame-plist))
|
|
350 (if (lax-plist-member frame-initial-geometry-arguments 'height)
|
|
351 (laxremf allprops 'height))
|
|
352 (if (lax-plist-member frame-initial-geometry-arguments 'width)
|
|
353 (remf allprops 'width))
|
|
354 (if (lax-plist-member frame-initial-geometry-arguments 'left)
|
|
355 (laxremf allprops 'left))
|
|
356 (if (lax-plist-member frame-initial-geometry-arguments 'top)
|
|
357 (laxremf allprops 'top))
|
|
358 (setq tail allprops)
|
|
359 ;; Find just the props that have changed since we first
|
|
360 ;; made this frame. Those are the ones actually set by
|
|
361 ;; the init file. For those props whose values we already knew
|
|
362 ;; (such as those spec'd by command line options)
|
|
363 ;; it is undesirable to specify the parm again
|
|
364 ;; once the user has seen the frame and been able to alter it
|
|
365 ;; manually.
|
|
366 (while tail
|
|
367 (let (newval oldval)
|
|
368 (setq oldval (lax-plist-get frame-initial-frame-plist
|
|
369 (car tail)))
|
|
370 (setq newval (lax-plist-get allprops (car tail)))
|
|
371 (or (eq oldval newval)
|
|
372 (laxputf newprops (car tail) newval)))
|
|
373 (setq tail (cddr tail)))
|
|
374 (set-frame-properties frame-initial-frame newprops)
|
|
375 ;silly FSFmacs junk
|
|
376 ;if (lax-plist-member newprops 'font)
|
|
377 ; (frame-update-faces frame-initial-frame))
|
|
378
|
|
379 )))
|
|
380
|
|
381 ;; Restore the original buffer.
|
|
382 (set-buffer old-buffer)
|
|
383
|
|
384 ;; Make sure the initial frame can be GC'd if it is ever deleted.
|
|
385 ;; Make sure frame-notice-user-settings does nothing if called twice.
|
|
386 (setq frame-initial-frame nil)))
|
|
387
|
|
388 (defun make-initial-minibuffer-frame (device)
|
|
389 (let ((props (append '(minibuffer only)
|
|
390 (safe-alist-to-plist minibuffer-frame-plist))))
|
|
391 (make-frame props device)))
|
|
392
|
|
393
|
|
394 ;;;; Creation of additional frames, and other frame miscellanea
|
|
395
|
|
396 (defun get-other-frame ()
|
|
397 "Return some frame other than the current frame, creating one if necessary."
|
|
398 (let* ((this (selected-frame))
|
|
399 ;; search visible frames first
|
|
400 (next (next-frame this 'visible-nomini)))
|
|
401 ;; then search iconified frames
|
|
402 (if (eq this next)
|
|
403 (setq next (next-frame 'visible-iconic-nomini)))
|
|
404 (if (eq this next)
|
|
405 ;; otherwise, make a new frame
|
|
406 (make-frame)
|
|
407 next)))
|
|
408
|
|
409 (defun next-multiframe-window ()
|
|
410 "Select the next window, regardless of which frame it is on."
|
|
411 (interactive)
|
|
412 (select-window (next-window (selected-window)
|
|
413 (> (minibuffer-depth) 0)
|
|
414 t)))
|
|
415
|
|
416 (defun previous-multiframe-window ()
|
|
417 "Select the previous window, regardless of which frame it is on."
|
|
418 (interactive)
|
|
419 (select-window (previous-window (selected-window)
|
|
420 (> (minibuffer-depth) 0)
|
|
421 t)))
|
|
422
|
|
423 (defun make-frame-on-device (type connection &optional props)
|
|
424 "Create a frame of type TYPE on CONNECTION.
|
|
425 TYPE should be a symbol naming the device type, i.e. one of
|
|
426
|
|
427 x An X display. CONNECTION should be a standard display string
|
|
428 such as \"unix:0\", or nil for the display specified on the
|
|
429 command line or in the DISPLAY environment variable. Only if
|
|
430 support for X was compiled into XEmacs.
|
|
431 tty A standard TTY connection or terminal. CONNECTION should be
|
|
432 a TTY device name such as \"/dev/ttyp2\" (as determined by
|
|
433 the Unix command `tty') or nil for XEmacs' standard input
|
|
434 and output (usually the TTY in which XEmacs started). Only
|
|
435 if support for TTY's was compiled into XEmacs.
|
|
436 ns A connection to a machine running the NeXTstep windowing
|
|
437 system. Not currently implemented.
|
|
438 win32 A connection to a machine running Microsoft Windows NT or
|
|
439 Windows 95. Not currently implemented.
|
|
440 pc A direct-write MS-DOS frame. Not currently implemented.
|
|
441
|
|
442 PROPS should be an plist of properties, as in the call to `make-frame'.
|
|
443
|
|
444 If a connection to CONNECTION already exists, it is reused; otherwise,
|
|
445 a new connection is opened."
|
|
446 (make-frame props (make-device type connection props)))
|
|
447
|
|
448 ;; Alias, kept temporarily.
|
|
449 (defalias 'new-frame 'make-frame)
|
|
450
|
|
451 ; FSFmacs has make-frame here. We have it in C, so no need for
|
|
452 ; frame-creation-function.
|
|
453
|
|
454 (defun filtered-frame-list (predicate &optional device)
|
|
455 "Return a list of all live frames which satisfy PREDICATE.
|
|
456 If optional second arg DEVICE is non-nil, restrict the frames
|
|
457 returned to that device."
|
|
458 (let ((frames (if device (device-frame-list device)
|
|
459 (frame-list)))
|
|
460 good-frames)
|
|
461 (while (consp frames)
|
|
462 (if (funcall predicate (car frames))
|
|
463 (setq good-frames (cons (car frames) good-frames)))
|
|
464 (setq frames (cdr frames)))
|
|
465 good-frames))
|
|
466
|
|
467 (defun minibuffer-frame-list (&optional device)
|
|
468 "Return a list of all frames with their own minibuffers.
|
|
469 If optional second arg DEVICE is non-nil, restrict the frames
|
|
470 returned to that device."
|
|
471 (filtered-frame-list
|
|
472 #'(lambda (frame)
|
|
473 (eq frame (window-frame (minibuffer-window frame))))
|
|
474 device))
|
|
475
|
|
476 (defun frame-minibuffer-only-p (frame)
|
|
477 "Return non-nil if FRAME is a minibuffer-only frame."
|
|
478 (eq (frame-root-window frame) (minibuffer-window frame)))
|
|
479
|
|
480 (defun frame-remove-geometry-props (plist)
|
|
481 "Return the property list PLIST, but with geometry specs removed.
|
|
482 This deletes all bindings in PLIST for `top', `left', `width',
|
|
483 `height', `user-size' and `user-position' properties.
|
|
484 Emacs uses this to avoid overriding explicit moves and resizings from
|
|
485 the user during startup."
|
|
486 (setq plist (canonicalize-lax-plist (copy-sequence plist)))
|
|
487 (mapcar #'(lambda (propname)
|
|
488 (if (lax-plist-member plist propname)
|
|
489 (progn
|
|
490 (setq frame-initial-geometry-arguments
|
|
491 (cons propname
|
|
492 (cons (lax-plist-get plist propname)
|
|
493 frame-initial-geometry-arguments)))
|
|
494 (setq plist (lax-plist-remprop plist propname)))))
|
|
495 '(height width top left user-size user-position))
|
|
496 plist)
|
|
497
|
|
498 (defun other-frame (arg)
|
|
499 "Select the ARG'th different visible frame, and raise it.
|
|
500 All frames are arranged in a cyclic order.
|
|
501 This command selects the frame ARG steps away in that order.
|
|
502 A negative ARG moves in the opposite order."
|
|
503 (interactive "p")
|
|
504 (let ((frame (selected-frame)))
|
|
505 (while (> arg 0)
|
|
506 (setq frame (next-frame frame 'visible-nomini))
|
|
507 (setq arg (1- arg)))
|
|
508 (while (< arg 0)
|
|
509 (setq frame (previous-frame frame 'visible-nomini))
|
|
510 (setq arg (1+ arg)))
|
|
511 (raise-frame frame)
|
|
512 (select-frame frame)
|
|
513 ;this is a bad idea; you should in general never warp the
|
|
514 ;pointer unless the user asks for this. Furthermore,
|
|
515 ;our version of `set-mouse-position' takes a window,
|
|
516 ;not a frame.
|
|
517 ;(set-mouse-position (selected-frame) (1- (frame-width)) 0)
|
|
518 ;some weird FSFmacs randomness
|
|
519 ;(if (fboundp 'unfocus-frame)
|
|
520 ; (unfocus-frame))))
|
|
521 ))
|
|
522
|
|
523 ;; XEmacs-added utility functions
|
|
524
|
|
525 ; this is in C in FSFmacs
|
|
526 (defun frame-list ()
|
|
527 "Return a list of all frames on all devices/consoles."
|
|
528 (apply 'append (mapcar 'device-frame-list (device-list))))
|
|
529
|
|
530 (defun frame-type (&optional frame)
|
|
531 "Return the type of the specified frame (e.g. `x' or `tty').
|
|
532 This is equivalent to the type of the frame's device.
|
|
533 Value is `tty' for a tty frame (a character-only terminal),
|
|
534 `x' for a frame that is an X window,
|
30
|
535 `ns' for a frame that is a NeXTstep window (not yet implemented),
|
0
|
536 `win32' for a frame that is a Windows or Windows NT window (not yet
|
|
537 implemented),
|
|
538 `pc' for a frame that is a direct-write MS-DOS frame (not yet implemented),
|
|
539 `stream' for a stream frame (which acts like a stdio stream), and
|
|
540 `dead' for a deleted frame."
|
|
541 (or frame (setq frame (selected-frame)))
|
|
542 (if (not (frame-live-p frame)) 'dead
|
|
543 (device-type (frame-device frame))))
|
|
544
|
|
545 (defun device-or-frame-p (object)
|
|
546 "Return non-nil if OBJECT is a device or frame."
|
|
547 (or (devicep object)
|
|
548 (framep object)))
|
|
549
|
|
550 (defun device-or-frame-type (device-or-frame)
|
|
551 "Return the type (e.g. `x' or `tty') of DEVICE-OR-FRAME.
|
|
552 DEVICE-OR-FRAME should be a device or a frame object. See `device-type'
|
|
553 for a description of the possible types."
|
|
554 (if (devicep device-or-frame)
|
|
555 (device-type device-or-frame)
|
|
556 (frame-type device-or-frame)))
|
|
557
|
|
558 (defun fw-frame (obj)
|
|
559 "Given a frame or window, return the associated frame.
|
|
560 Return nil otherwise."
|
|
561 (cond ((windowp obj) (window-frame obj))
|
|
562 ((framep obj) obj)
|
|
563 (t nil)))
|
|
564
|
|
565
|
|
566 ;;;; Frame configurations
|
|
567
|
|
568 (defun current-frame-configuration ()
|
|
569 "Return a list describing the positions and states of all frames.
|
|
570 Its car is `frame-configuration'.
|
|
571 Each element of the cdr is a list of the form (FRAME PLIST WINDOW-CONFIG),
|
|
572 where
|
|
573 FRAME is a frame object,
|
|
574 PLIST is a property list specifying some of FRAME's properties, and
|
|
575 WINDOW-CONFIG is a window configuration object for FRAME."
|
|
576 (cons 'frame-configuration
|
|
577 (mapcar (function
|
|
578 (lambda (frame)
|
|
579 (list frame
|
|
580 (frame-properties frame)
|
|
581 (current-window-configuration frame))))
|
|
582 (frame-list))))
|
|
583
|
|
584 (defun set-frame-configuration (configuration &optional nodelete)
|
|
585 "Restore the frames to the state described by CONFIGURATION.
|
|
586 Each frame listed in CONFIGURATION has its position, size, window
|
|
587 configuration, and other properties set as specified in CONFIGURATION.
|
|
588 Ordinarily, this function deletes all existing frames not
|
|
589 listed in CONFIGURATION. But if optional second argument NODELETE
|
|
590 is given and non-nil, the unwanted frames are iconified instead."
|
|
591 (or (frame-configuration-p configuration)
|
|
592 (signal 'wrong-type-argument
|
|
593 (list 'frame-configuration-p configuration)))
|
|
594 (let ((config-plist (cdr configuration))
|
|
595 frames-to-delete)
|
|
596 (mapcar (function
|
|
597 (lambda (frame)
|
|
598 (let ((properties (assq frame config-plist)))
|
|
599 (if properties
|
|
600 (progn
|
|
601 (set-frame-properties
|
|
602 frame
|
|
603 ;; Since we can't set a frame's minibuffer status,
|
|
604 ;; we might as well omit the parameter altogether.
|
|
605 (lax-plist-remprop (nth 1 properties) 'minibuffer))
|
|
606 (set-window-configuration (nth 2 properties)))
|
|
607 (setq frames-to-delete (cons frame frames-to-delete))))))
|
|
608 (frame-list))
|
|
609 (if nodelete
|
|
610 ;; Note: making frames invisible here was tried
|
|
611 ;; but led to some strange behavior--each time the frame
|
|
612 ;; was made visible again, the window manager asked afresh
|
|
613 ;; for where to put it.
|
|
614 (mapcar 'iconify-frame frames-to-delete)
|
|
615 (mapcar 'delete-frame frames-to-delete))))
|
|
616
|
|
617 ; this function is in subr.el in FSFmacs.
|
|
618 ; that's because they don't always include frame.el, while we do.
|
|
619
|
|
620 (defun frame-configuration-p (object)
|
|
621 "Return non-nil if OBJECT seems to be a frame configuration.
|
|
622 Any list whose car is `frame-configuration' is assumed to be a frame
|
|
623 configuration."
|
|
624 (and (consp object)
|
|
625 (eq (car object) 'frame-configuration)))
|
|
626
|
|
627
|
|
628 ;; FSFmacs has functions `frame-width', `frame-height' here.
|
|
629 ;; We have them in C.
|
|
630
|
|
631 ;; FSFmacs has weird functions `set-default-font', `set-background-color',
|
|
632 ;; `set-foreground-color' here. They don't do sensible things like
|
|
633 ;; set faces; instead they set frame properties (??!!) and call
|
|
634 ;; useless functions such as `frame-update-faces' and
|
|
635 ;; `frame-update-face-colors'.
|
|
636
|
|
637 ;; FSFmacs has functions `set-cursor-color', `set-mouse-color', and
|
|
638 ;; `set-border-color', which refer to frame properties.
|
|
639 ;; #### We need to use specifiers here.
|
|
640
|
|
641 ;(defun auto-raise-mode (arg)
|
|
642 ; "Toggle whether or not the selected frame should auto-raise.
|
|
643 ;With arg, turn auto-raise mode on if and only if arg is positive.
|
|
644 ;Note that this controls Emacs's own auto-raise feature.
|
|
645 ;Some window managers allow you to enable auto-raise for certain windows.
|
|
646 ;You can use that for Emacs windows if you wish, but if you do,
|
|
647 ;that is beyond the control of Emacs and this command has no effect on it."
|
|
648 ; (interactive "P")
|
|
649 ; (if (null arg)
|
|
650 ; (setq arg
|
|
651 ; (if (frame-property (selected-frame) 'auto-raise)
|
|
652 ; -1 1)))
|
|
653 ; (set-frame-property (selected-frame) 'auto-raise (> arg 0)))
|
|
654
|
|
655 ;(defun auto-lower-mode (arg)
|
|
656 ; "Toggle whether or not the selected frame should auto-lower.
|
|
657 ;With arg, turn auto-lower mode on if and only if arg is positive.
|
|
658 ;Note that this controls Emacs's own auto-lower feature.
|
|
659 ;Some window managers allow you to enable auto-lower for certain windows.
|
|
660 ;You can use that for Emacs windows if you wish, but if you do,
|
|
661 ;that is beyond the control of Emacs and this command has no effect on it."
|
|
662 ; (interactive "P")
|
|
663 ; (if (null arg)
|
|
664 ; (setq arg
|
|
665 ; (if (frame-property (selected-frame) 'auto-lower)
|
|
666 ; -1 1)))
|
|
667 ; (set-frame-property (selected-frame) 'auto-lower (> arg 0)))
|
|
668
|
|
669 ;; FSFmacs has silly functions `toggle-scroll-bar',
|
|
670 ;; `toggle-horizontal-scrollbar'
|
|
671
|
|
672 ;;; Iconifying emacs.
|
|
673 ;;;
|
|
674 ;;; The function iconify-emacs replaces every non-iconified emacs window
|
|
675 ;;; with a *single* icon. Iconified emacs windows are left alone. When
|
|
676 ;;; emacs is in this globally-iconified state, de-iconifying any emacs icon
|
|
677 ;;; will uniconify all frames that were visible, and iconify all frames
|
|
678 ;;; that were not. This is done by temporarily changing the value of
|
|
679 ;;; `map-frame-hook' to `deiconify-emacs' (which should never be called
|
|
680 ;;; except from the map-frame-hook while emacs is iconified).
|
|
681 ;;;
|
|
682 ;;; The title of the icon representing all emacs frames is controlled by
|
|
683 ;;; the variable `icon-name'. This is done by temporarily changing the
|
|
684 ;;; value of `frame-icon-title-format'. Unfortunately, this changes the
|
|
685 ;;; titles of all emacs icons, not just the "big" icon.
|
|
686 ;;;
|
|
687 ;;; It would be nice if existing icons were removed and restored by
|
|
688 ;;; iconifying the emacs process, but I couldn't make that work yet.
|
|
689
|
|
690 (defvar icon-name nil) ; set this at run time, not load time.
|
|
691
|
|
692 (defvar iconification-data nil)
|
|
693
|
|
694 (defun iconify-emacs ()
|
|
695 "Replace every non-iconified FRAME with a *single* icon.
|
|
696 Iconified frames are left alone. When XEmacs is in this
|
|
697 globally-iconified state, de-iconifying any emacs icon will uniconify
|
|
698 all frames that were visible, and iconify all frames that were not."
|
|
699 (interactive)
|
|
700 (if iconification-data (error "already iconified?"))
|
|
701 (let* ((frames (frame-list))
|
|
702 (rest frames)
|
|
703 (me (selected-frame))
|
|
704 frame)
|
|
705 (while rest
|
|
706 (setq frame (car rest))
|
|
707 (setcar rest (cons frame (frame-visible-p frame)))
|
|
708 ; (if (memq (cdr (car rest)) '(icon nil))
|
|
709 ; (progn
|
|
710 ; (make-frame-visible frame) ; deiconify, and process the X event
|
|
711 ; (sleep-for 500 t) ; process X events; I really want to XSync() here
|
|
712 ; ))
|
|
713 (or (eq frame me) (make-frame-invisible frame))
|
|
714 (setq rest (cdr rest)))
|
|
715 (or (boundp 'map-frame-hook) (setq map-frame-hook nil))
|
|
716 (or icon-name
|
|
717 (setq icon-name (concat invocation-name " @ " (system-name))))
|
|
718 (setq iconification-data
|
|
719 (list frame-icon-title-format map-frame-hook frames)
|
|
720 frame-icon-title-format icon-name
|
|
721 map-frame-hook 'deiconify-emacs)
|
|
722 (iconify-frame me)))
|
|
723
|
48
|
724
|
0
|
725 (defun deiconify-emacs (&optional ignore)
|
|
726 (or iconification-data (error "not iconified?"))
|
|
727 (setq frame-icon-title-format (car iconification-data)
|
|
728 map-frame-hook (car (cdr iconification-data))
|
|
729 iconification-data (car (cdr (cdr iconification-data))))
|
|
730 (while iconification-data
|
|
731 (let ((visibility (cdr (car iconification-data))))
|
48
|
732 (cond (visibility ;; JV (Note non-nil means visible in XEmacs)
|
0
|
733 (make-frame-visible (car (car iconification-data))))
|
48
|
734 ; (t ;; (eq visibility 'icon) ;; JV Not in XEmacs!!!
|
0
|
735 ; (make-frame-visible (car (car iconification-data)))
|
|
736 ; (sleep-for 500 t) ; process X events; I really want to XSync() here
|
|
737 ; (iconify-frame (car (car iconification-data))))
|
|
738 ;; (t nil)
|
|
739 ))
|
|
740 (setq iconification-data (cdr iconification-data))))
|
|
741
|
|
742 (defun suspend-or-iconify-emacs ()
|
|
743 "Calls iconify-emacs if frame is an X frame, otherwise calls suspend-emacs"
|
|
744 (interactive)
|
30
|
745 (cond
|
|
746 ((eq (frame-type (selected-frame)) 'x) (iconify-emacs))
|
|
747 ((and (eq (frame-type (selected-frame)) 'tty)
|
|
748 (console-tty-controlling-process (selected-console)))
|
|
749 (suspend-console (selected-console)))
|
|
750 (t
|
|
751 (suspend-emacs))))
|
0
|
752
|
|
753
|
|
754 ;;; auto-raise and auto-lower
|
|
755
|
|
756 (defvar auto-raise-frame nil
|
|
757 "*If true, frames will be raised to the top when selected.
|
|
758 Under X, most ICCCM-compliant window managers will have an option to do this
|
|
759 for you, but this variable is provided in case you're using a broken WM.")
|
|
760
|
|
761 (defvar auto-lower-frame nil
|
|
762 "*If true, frames will be lowered to the bottom when no longer selected.
|
|
763 Under X, most ICCCM-compliant window managers will have an option to do this
|
|
764 for you, but this variable is provided in case you're using a broken WM.")
|
|
765
|
|
766 (defun default-select-frame-hook ()
|
|
767 "Implements the `auto-raise-frame' variable.
|
|
768 For use as the value of `select-frame-hook'."
|
|
769 (if auto-raise-frame (raise-frame (selected-frame))))
|
|
770
|
|
771 (defun default-deselect-frame-hook ()
|
|
772 "Implements the `auto-lower-frame' variable.
|
|
773 For use as the value of `deselect-frame-hook'."
|
|
774 (if auto-lower-frame (lower-frame (selected-frame))))
|
|
775
|
|
776 (or select-frame-hook
|
|
777 (add-hook 'select-frame-hook 'default-select-frame-hook))
|
|
778
|
|
779 (or deselect-frame-hook
|
|
780 (add-hook 'deselect-frame-hook 'default-deselect-frame-hook))
|
|
781
|
2
|
782 (defun default-drag-and-drop-functions (frame filepath &optional data)
|
0
|
783 "Implements the `drag-and-drop-functions' variable.
|
|
784 For use as the value of `drag-and-drop-functions'.
|
2
|
785 This default simply pops up the file in the selected frame or,
|
|
786 if the dragged object is a buffer, inserts it at point."
|
|
787 (if data
|
|
788 (insert data)
|
|
789 (let ((x pop-up-windows))
|
|
790 (setq pop-up-windows nil)
|
|
791 (pop-to-buffer (find-file-noselect filepath) nil frame)
|
|
792 (make-frame-visible frame)
|
|
793 (setq pop-up-windows x))))
|
0
|
794
|
|
795 (and (boundp 'drag-and-drop-functions)
|
|
796 (or drag-and-drop-functions
|
|
797 (add-hook 'drag-and-drop-functions 'default-drag-and-drop-functions)))
|
|
798
|
|
799
|
|
800 ;;; Application-specific frame-management
|
|
801
|
|
802 (defvar get-frame-for-buffer-default-frame-name nil
|
|
803 "The default frame to select; see doc of `get-frame-for-buffer'.")
|
|
804
|
|
805 (defvar get-frame-for-buffer-default-instance-limit nil)
|
|
806
|
|
807 (defun get-frame-name-for-buffer (buffer)
|
|
808 (let ((mode (and (get-buffer buffer)
|
|
809 (save-excursion (set-buffer buffer)
|
|
810 major-mode))))
|
|
811 (or (get mode 'frame-name)
|
|
812 get-frame-for-buffer-default-frame-name)))
|
|
813
|
48
|
814 (defun get-frame-for-buffer-make-new-frame (buffer &optional frame-name plist)
|
|
815 (let* ((fr (make-frame plist))
|
0
|
816 (w (frame-root-window fr)))
|
|
817 ;;
|
|
818 ;; Make the one buffer being displayed in this newly created
|
|
819 ;; frame be the buffer of interest, instead of something
|
|
820 ;; random, so that it won't be shown in two-window mode.
|
|
821 ;; Avoid calling switch-to-buffer here, since that's something
|
|
822 ;; people might want to call this routine from.
|
|
823 ;;
|
|
824 ;; (If the root window doesn't have a buffer, then that means
|
|
825 ;; there is more than one window on the frame, which can only
|
|
826 ;; happen if the user has done something funny on the frame-
|
|
827 ;; creation-hook. If that's the case, leave it alone.)
|
|
828 ;;
|
|
829 (if (window-buffer w)
|
|
830 (set-window-buffer w buffer))
|
|
831 fr))
|
|
832
|
|
833 (defun get-frame-for-buffer-noselect (buffer
|
|
834 &optional not-this-window-p on-frame)
|
|
835 "Return a frame in which to display BUFFER.
|
|
836 This is a subroutine of `get-frame-for-buffer' (which see)."
|
|
837 (let (name limit)
|
|
838 (cond
|
|
839 ((or on-frame (eq (selected-window) (minibuffer-window)))
|
|
840 ;; don't switch frames if a frame was specified, or to list
|
|
841 ;; completions from the minibuffer, etc.
|
|
842 nil)
|
|
843
|
|
844 ((setq name (get-frame-name-for-buffer buffer))
|
|
845 ;;
|
|
846 ;; This buffer's mode expressed a preference for a frame of a particular
|
|
847 ;; name. That always takes priority.
|
|
848 ;;
|
|
849 (let ((limit (get name 'instance-limit))
|
48
|
850 (defaults (get name 'frame-defaults))
|
0
|
851 (matching-frames '())
|
|
852 frames frame already-visible)
|
|
853 ;; Sort the list so that iconic frames will be found last. They
|
|
854 ;; will be used too, but mapped frames take precedence. And
|
|
855 ;; fully visible frames come before occluded frames.
|
30
|
856 ;; Hidden frames come after really visible ones
|
0
|
857 (setq frames
|
|
858 (sort (frame-list)
|
|
859 #'(lambda (s1 s2)
|
|
860 (cond ((frame-totally-visible-p s2)
|
|
861 nil)
|
|
862 ((not (frame-visible-p s2))
|
|
863 (frame-visible-p s1))
|
30
|
864 ((eq (frame-visible-p s2) 'hidden)
|
|
865 (eq (frame-visible-p s1) t ))
|
0
|
866 ((not (frame-totally-visible-p s2))
|
|
867 (and (frame-visible-p s1)
|
|
868 (frame-totally-visible-p s1)))))))
|
|
869 ;; but the selected frame should come first, even if it's occluded,
|
|
870 ;; to minimize thrashing.
|
|
871 (setq frames (cons (selected-frame)
|
|
872 (delq (selected-frame) frames)))
|
|
873
|
|
874 (setq name (symbol-name name))
|
|
875 (while frames
|
|
876 (setq frame (car frames))
|
|
877 (if (equal name (frame-name frame))
|
|
878 (if (get-buffer-window buffer frame)
|
|
879 (setq already-visible frame
|
|
880 frames nil)
|
|
881 (setq matching-frames (cons frame matching-frames))))
|
|
882 (setq frames (cdr frames)))
|
|
883 (cond (already-visible
|
|
884 already-visible)
|
|
885 ((or (null matching-frames)
|
|
886 (eq limit 0) ; means create with reckless abandon
|
|
887 (and limit (< (length matching-frames) limit)))
|
48
|
888 (get-frame-for-buffer-make-new-frame
|
|
889 buffer
|
|
890 name
|
|
891 (alist-to-plist (acons 'name name
|
|
892 (plist-to-alist defaults)))))
|
0
|
893 (t
|
|
894 ;; do not switch any of the window/buffer associations in an
|
|
895 ;; existing frame; this function only picks a frame; the
|
|
896 ;; determination of which windows on it get reused is up to
|
|
897 ;; display-buffer itself.
|
|
898 ;; (or (window-dedicated-p (selected-window))
|
|
899 ;; (switch-to-buffer buffer))
|
|
900 (car matching-frames)))))
|
|
901
|
|
902 ((setq limit get-frame-for-buffer-default-instance-limit)
|
|
903 ;;
|
|
904 ;; This buffer's mode did not express a preference for a frame of a
|
|
905 ;; particular name, but the user wants a new frame rather than
|
|
906 ;; reusing the existing one.
|
|
907 (let* ((defname
|
|
908 (or (plist-get default-frame-plist 'name)
|
|
909 default-frame-name))
|
|
910 (frames
|
|
911 (sort (filtered-frame-list #'(lambda (x)
|
|
912 (or (frame-visible-p x)
|
|
913 (frame-iconified-p x))))
|
|
914 #'(lambda (s1 s2)
|
|
915 (cond ((and (frame-visible-p s1)
|
|
916 (not (frame-visible-p s2))))
|
30
|
917 ((and (eq (frame-visible-p s1) t)
|
|
918 (eq (frame-visible-p s2) 'hidden)))
|
0
|
919 ((and (frame-visible-p s2)
|
|
920 (not (frame-visible-p s1)))
|
|
921 nil)
|
|
922 ((and (equal (frame-name s1) defname)
|
|
923 (not (equal (frame-name s2) defname))))
|
|
924 ((and (equal (frame-name s2) defname)
|
|
925 (not (equal (frame-name s1) defname)))
|
|
926 nil)
|
|
927 ((frame-totally-visible-p s2)
|
|
928 nil)
|
|
929 (t))))))
|
|
930 ;; put the selected frame last. The user wants a new frame,
|
|
931 ;; so don't reuse the existing one unless forced to.
|
|
932 (setq frames (append (delq (selected-frame) frames) (list frames)))
|
|
933 (if (or (eq limit 0) ; means create with reckless abandon
|
|
934 (< (length frames) limit))
|
|
935 (get-frame-for-buffer-make-new-frame buffer)
|
|
936 (car frames))))
|
|
937
|
|
938 (t
|
|
939 ;;
|
|
940 ;; This buffer's mode did not express a preference for a frame of a
|
|
941 ;; particular name. So try to find a frame already displaying this
|
|
942 ;; buffer.
|
|
943 ;;
|
|
944 (let ((w (or (get-buffer-window buffer 'visible) ; check visible first
|
|
945 (get-buffer-window buffer 0)))) ; then iconic
|
|
946 (cond ((null w)
|
|
947 ;; It's not in any window - return nil, meaning no frame has
|
|
948 ;; preference.
|
|
949 nil)
|
|
950 ((and not-this-window-p
|
|
951 (eq (selected-frame) (window-frame w)))
|
|
952 ;; It's in a window, but on this frame, and we have been
|
|
953 ;; asked to pick another window. Return nil, meaning no
|
|
954 ;; frame has preference.
|
|
955 nil)
|
|
956 (t
|
|
957 ;; Otherwise, return the frame of the buffer's window.
|
|
958 (window-frame w))))))))
|
|
959
|
|
960
|
|
961 ;; The pre-display-buffer-function is called for effect, so this needs to
|
|
962 ;; actually select the frame it wants. Fdisplay_buffer() takes notice of
|
|
963 ;; changes to the selected frame.
|
|
964 (defun get-frame-for-buffer (buffer &optional not-this-window-p on-frame)
|
|
965 "Select and return a frame in which to display BUFFER.
|
|
966 Normally, the buffer will simply be displayed in the current frame.
|
|
967 But if the symbol naming the major-mode of the buffer has a 'frame-name
|
|
968 property (which should be a symbol), then the buffer will be displayed in
|
|
969 a frame of that name. If there is no frame of that name, then one is
|
|
970 created.
|
|
971
|
|
972 If the major-mode doesn't have a 'frame-name property, then the frame
|
|
973 named by `get-frame-for-buffer-default-frame-name' will be used. If
|
|
974 that is nil (the default) then the currently selected frame will used.
|
|
975
|
|
976 If the frame-name symbol has an 'instance-limit property (an integer)
|
|
977 then each time a buffer of the mode in question is displayed, a new frame
|
|
978 with that name will be created, until there are `instance-limit' of them.
|
|
979 If instance-limit is 0, then a new frame will be created each time.
|
|
980
|
|
981 If a buffer is already displayed in a frame, then `instance-limit' is
|
|
982 ignored, and that frame is used.
|
|
983
|
|
984 If the frame-name symbol has a 'frame-defaults property, then that is
|
|
985 prepended to the `default-frame-plist' when creating a frame for the
|
|
986 first time.
|
|
987
|
|
988 This function may be used as the value of `pre-display-buffer-function',
|
|
989 to cause the display-buffer function and its callers to exhibit the above
|
|
990 behavior."
|
|
991 (let ((frame (get-frame-for-buffer-noselect
|
|
992 buffer not-this-window-p on-frame)))
|
|
993 (if (not (eq frame (selected-frame)))
|
|
994 frame
|
|
995 (select-frame frame)
|
|
996 (or (frame-visible-p frame)
|
|
997 ;; If the frame was already visible, just focus on it.
|
|
998 ;; If it wasn't visible (it was just created, or it used
|
|
999 ;; to be iconified) then uniconify, raise, etc.
|
|
1000 (make-frame-visible frame))
|
|
1001 frame)))
|
|
1002
|
|
1003 (defun frames-of-buffer (&optional buffer visible-only)
|
|
1004 "Return list of frames that BUFFER is currently being displayed on.
|
|
1005 If the buffer is being displayed on the currently selected frame, that frame
|
|
1006 is first in the list. VISIBLE-ONLY will only list non-iconified frames."
|
|
1007 (let ((list (windows-of-buffer buffer))
|
|
1008 (cur-frame (selected-frame))
|
|
1009 next-frame frames save-frame)
|
|
1010
|
|
1011 (while list
|
|
1012 (if (memq (setq next-frame (window-frame (car list)))
|
|
1013 frames)
|
|
1014 nil
|
|
1015 (if (eq cur-frame next-frame)
|
|
1016 (setq save-frame next-frame)
|
|
1017 (and
|
|
1018 (or (not visible-only)
|
30
|
1019 (frame-visible-p next-frame))
|
0
|
1020 (setq frames (append frames (list next-frame))))))
|
|
1021 (setq list (cdr list)))
|
|
1022
|
|
1023 (if save-frame
|
|
1024 (append (list save-frame) frames)
|
|
1025 frames)))
|
|
1026
|
22
|
1027 (defvar temp-buffer-shrink-to-fit t
|
|
1028 "*When non-nil resize temporary output buffers to minimize blank lines.")
|
|
1029
|
44
|
1030 (defvar temp-buffer-max-height .5
|
|
1031 "*Proportion of frame to use for temp windows.")
|
|
1032
|
0
|
1033 (defun show-temp-buffer-in-current-frame (buffer)
|
|
1034 "For use as the value of temp-buffer-show-function:
|
|
1035 always displays the buffer in the current frame, regardless of the behavior
|
|
1036 that would otherwise be introduced by the `pre-display-buffer-function', which
|
|
1037 is normally set to `get-frame-for-buffer' (which see)."
|
|
1038 (let ((pre-display-buffer-function nil)) ; turn it off, whatever it is
|
|
1039 (let ((window (display-buffer buffer)))
|
|
1040 (if (not (eq (last-nonminibuf-frame) (window-frame window)))
|
|
1041 ;; only the pre-display-buffer-function should ever do this.
|
|
1042 (error "display-buffer switched frames on its own!!"))
|
|
1043 (setq minibuffer-scroll-window window)
|
|
1044 (set-window-start window 1) ; obeys narrowing
|
|
1045 (set-window-point window 1)
|
22
|
1046 (when temp-buffer-shrink-to-fit
|
44
|
1047 (let* ((temp-window-size (round (* temp-buffer-max-height
|
|
1048 (frame-height (window-frame window)))))
|
|
1049 (size (window-displayed-height window)))
|
|
1050 (when (< size temp-window-size)
|
|
1051 (enlarge-window (- temp-window-size size) nil window)))
|
|
1052 (shrink-window-if-larger-than-buffer window))
|
0
|
1053 nil)))
|
|
1054
|
|
1055 (setq pre-display-buffer-function 'get-frame-for-buffer)
|
|
1056 (setq temp-buffer-show-function 'show-temp-buffer-in-current-frame)
|
|
1057
|
|
1058
|
|
1059 ;; from Bob Weiner <bweiner@pts.mot.com>, modified by Ben Wing
|
|
1060 (defun delete-other-frames (&optional frame)
|
|
1061 "Delete all but FRAME (or the selected frame)."
|
|
1062 (interactive)
|
|
1063 (mapcar 'delete-frame (delq (or frame (selected-frame)) (frame-list))))
|
|
1064
|
|
1065 ;; By adding primitives to directly access the window hierarchy,
|
|
1066 ;; we can move many functions into Lisp. We do it this way
|
|
1067 ;; because the implementations are simpler in Lisp, and because
|
|
1068 ;; new functions like this can be added without requiring C
|
|
1069 ;; additions.
|
|
1070
|
|
1071 (defun frame-utmost-window-2 (window position left-right-p major-end-p
|
|
1072 minor-end-p)
|
|
1073 ;; LEFT-RIGHT-P means we're looking for the leftmost or rightmost
|
|
1074 ;; window, instead of the highest or lowest. In this case, we
|
|
1075 ;; say that the "major axis" goes left-to-right instead of top-to-
|
|
1076 ;; bottom. The "minor axis" always goes perpendicularly.
|
|
1077 ;;
|
|
1078 ;; If MAJOR-END-P is t, we're looking for a windows that abut the
|
|
1079 ;; end (i.e. right or bottom) of the major axis, instead of the
|
|
1080 ;; start.
|
|
1081 ;;
|
|
1082 ;; If MINOR-END-P is t, then we want to start counting from the
|
|
1083 ;; end of the minor axis instead of the beginning.
|
|
1084 ;;
|
|
1085 ;; Here's the general idea: Imagine we're trying to count the number
|
|
1086 ;; of windows that abut the top; call this function foo(). So, we
|
|
1087 ;; start with the root window. If this is a vertical combination
|
|
1088 ;; window, then foo() applied to the root window is the same as
|
|
1089 ;; foo() applied to the first child. If the root is a horizontal
|
|
1090 ;; combination window, then foo() applied to the root is the
|
|
1091 ;; same as the sum of foo() applied to each of the children.
|
|
1092 ;; Otherwise, the root window is a leaf window, and foo() is 1.
|
|
1093 ;; Now it's clear that, each time foo() encounters a leaf window,
|
|
1094 ;; it's encountering a different window that abuts the top.
|
|
1095 ;; With a little examining, you can see that foo encounters the
|
|
1096 ;; top-abutting windows in order from left to right. We can
|
|
1097 ;; modify foo() to return the nth top-abutting window by simply
|
|
1098 ;; keeping a global variable that is decremented each time
|
|
1099 ;; foo() encounters a leaf window and would return 1. If the
|
|
1100 ;; global counter gets to zero, we've encountered the window
|
|
1101 ;; we were looking for, so we exit right away using a `throw'.
|
|
1102 ;; Otherwise, we make sure that all normal paths return nil.
|
|
1103
|
|
1104 (let (child)
|
|
1105 (cond ((setq child (if left-right-p
|
|
1106 (window-first-hchild window)
|
|
1107 (window-first-vchild window)))
|
|
1108 (if major-end-p
|
|
1109 (while (window-next-child child)
|
|
1110 (setq child (window-next-child child))))
|
|
1111 (frame-utmost-window-2 child position left-right-p major-end-p
|
|
1112 minor-end-p))
|
|
1113 ((setq child (if left-right-p
|
|
1114 (window-first-vchild window)
|
|
1115 (window-first-hchild window)))
|
|
1116 (if minor-end-p
|
|
1117 (while (window-next-child child)
|
|
1118 (setq child (window-next-child child))))
|
|
1119 (while child
|
|
1120 (frame-utmost-window-2 child position left-right-p major-end-p
|
|
1121 minor-end-p)
|
|
1122 (setq child (if minor-end-p
|
|
1123 (window-previous-child child)
|
|
1124 (window-next-child child))))
|
|
1125 nil)
|
|
1126 (t
|
|
1127 (setcar position (1- (car position)))
|
|
1128 (if (= (car position) 0)
|
|
1129 (throw 'fhw-exit window)
|
|
1130 nil)))))
|
|
1131
|
|
1132 (defun frame-utmost-window-1 (frame position left-right-p major-end-p)
|
|
1133 (let (minor-end-p)
|
|
1134 (or frame (setq frame (selected-frame)))
|
|
1135 (or position (setq position 0))
|
|
1136 (if (>= position 0)
|
|
1137 (setq position (1+ position))
|
|
1138 (setq minor-end-p t)
|
|
1139 (setq position (- position)))
|
|
1140 (catch 'fhw-exit
|
|
1141 ;; we use a cons here as a simple form of call-by-reference.
|
|
1142 ;; scheme has "boxes" for the same purpose.
|
|
1143 (frame-utmost-window-2 (frame-root-window frame) (list position)
|
|
1144 left-right-p major-end-p minor-end-p))))
|
|
1145
|
|
1146
|
|
1147 (defun frame-highest-window (&optional frame position)
|
|
1148 "Return the highest window on FRAME which is at POSITION.
|
|
1149 If omitted, FRAME defaults to the currently selected frame.
|
|
1150 POSITION is used to distinguish between multiple windows that abut
|
|
1151 the top of the frame: 0 means the leftmost window abutting the
|
|
1152 top of the frame, 1 the next-leftmost, etc. POSITION can also
|
|
1153 be less than zero: -1 means the rightmost window abutting the
|
|
1154 top of the frame, -2 the next-rightmost, etc.
|
|
1155 If omitted, POSITION defaults to 0, i.e. the leftmost highest window.
|
|
1156 If there is no window at the given POSITION, return nil."
|
|
1157 (frame-utmost-window-1 frame position nil nil))
|
|
1158
|
|
1159 (defun frame-lowest-window (&optional frame position)
|
|
1160 "Return the lowest window on FRAME which is at POSITION.
|
|
1161 If omitted, FRAME defaults to the currently selected frame.
|
|
1162 POSITION is used to distinguish between multiple windows that abut
|
|
1163 the bottom of the frame: 0 means the leftmost window abutting the
|
|
1164 bottom of the frame, 1 the next-leftmost, etc. POSITION can also
|
|
1165 be less than zero: -1 means the rightmost window abutting the
|
|
1166 bottom of the frame, -2 the next-rightmost, etc.
|
|
1167 If omitted, POSITION defaults to 0, i.e. the leftmost lowest window.
|
|
1168 If there is no window at the given POSITION, return nil."
|
|
1169 (frame-utmost-window-1 frame position nil t))
|
|
1170
|
|
1171 (defun frame-leftmost-window (&optional frame position)
|
|
1172 "Return the leftmost window on FRAME which is at POSITION.
|
|
1173 If omitted, FRAME defaults to the currently selected frame.
|
|
1174 POSITION is used to distinguish between multiple windows that abut
|
|
1175 the left edge of the frame: 0 means the highest window abutting the
|
|
1176 left edge of the frame, 1 the next-highest, etc. POSITION can also
|
|
1177 be less than zero: -1 means the lowest window abutting the
|
|
1178 left edge of the frame, -2 the next-lowest, etc.
|
|
1179 If omitted, POSITION defaults to 0, i.e. the highest leftmost window.
|
|
1180 If there is no window at the given POSITION, return nil."
|
|
1181 (frame-utmost-window-1 frame position t nil))
|
|
1182
|
|
1183 (defun frame-rightmost-window (&optional frame position)
|
|
1184 "Return the rightmost window on FRAME which is at POSITION.
|
|
1185 If omitted, FRAME defaults to the currently selected frame.
|
|
1186 POSITION is used to distinguish between multiple windows that abut
|
|
1187 the right edge of the frame: 0 means the highest window abutting the
|
|
1188 right edge of the frame, 1 the next-highest, etc. POSITION can also
|
|
1189 be less than zero: -1 means the lowest window abutting the
|
|
1190 right edge of the frame, -2 the next-lowest, etc.
|
|
1191 If omitted, POSITION defaults to 0, i.e. the highest rightmost window.
|
|
1192 If there is no window at the given POSITION, return nil."
|
|
1193 (frame-utmost-window-1 frame position t t))
|
|
1194
|
|
1195
|
|
1196
|
|
1197 ;; frame properties.
|
|
1198
|
|
1199 (defun set-frame-property (frame prop val)
|
|
1200 "Set property PROP of FRAME to VAL. See `set-frame-properties'."
|
|
1201 (set-frame-properties frame (list prop val)))
|
|
1202
|
|
1203 (defun frame-height (&optional frame)
|
|
1204 "Return number of lines available for display on FRAME."
|
|
1205 (or frame (setq frame (selected-frame)))
|
|
1206 (frame-property frame 'height))
|
|
1207
|
|
1208 (defun frame-width (&optional frame)
|
|
1209 "Return number of columns available for display on FRAME."
|
|
1210 (or frame (setq frame (selected-frame)))
|
|
1211 (frame-property frame 'width))
|
|
1212
|
|
1213 (put 'cursor-color 'frame-property-alias [text-cursor background])
|
|
1214 (put 'modeline 'frame-property-alias 'has-modeline-p)
|
|
1215
|
|
1216
|
|
1217 (provide 'frame)
|
|
1218
|
|
1219 ;;; frame.el ends here
|