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