0
|
1 ;;; Window management code for VM
|
98
|
2 ;;; Copyright (C) 1989-1997 Kyle E. Jones
|
0
|
3 ;;;
|
|
4 ;;; This program is free software; you can redistribute it and/or modify
|
|
5 ;;; it under the terms of the GNU General Public License as published by
|
|
6 ;;; the Free Software Foundation; either version 1, or (at your option)
|
|
7 ;;; any later version.
|
|
8 ;;;
|
|
9 ;;; This program is distributed in the hope that it will be useful,
|
|
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 ;;; GNU General Public License for more details.
|
|
13 ;;;
|
|
14 ;;; You should have received a copy of the GNU General Public License
|
|
15 ;;; along with this program; if not, write to the Free Software
|
|
16 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
17
|
|
18 (provide 'vm-window)
|
|
19
|
98
|
20 (defun vm-display (buffer display commands configs
|
|
21 &optional do-not-raise)
|
0
|
22 ;; the clearinghouse VM display function.
|
|
23 ;;
|
|
24 ;; First arg BUFFER non-nil is a buffer to display or undisplay.
|
|
25 ;; nil means there is no request to display or undisplay a
|
|
26 ;; buffer.
|
|
27 ;;
|
|
28 ;; Second arg DISPLAY non-nil means to display the buffer, nil means
|
|
29 ;; to undisplay it. This function guarantees to display the
|
|
30 ;; buffer if requested. Undisplay is not guaranteed.
|
|
31 ;;
|
|
32 ;; Third arg COMMANDS is a list of symbols. this-command must
|
|
33 ;; match one of these symbols for a window configuration to be
|
|
34 ;; applied.
|
|
35 ;;
|
|
36 ;; Fourth arg CONFIGS is a list of window configurations to try.
|
|
37 ;; vm-set-window-configuration will step through the list looking
|
|
38 ;; for an existing configuration, and apply the one it finds.
|
|
39 ;;
|
|
40 ;; Display is done this way:
|
|
41 ;; 1. if the buffer is visible in an invisible frame, make that frame visible
|
|
42 ;; 2. if the buffer is already displayed, quit
|
|
43 ;; 3. if vm-display-buffer-hook in non-nil
|
|
44 ;; run the hooks
|
|
45 ;; use the selected window/frame to display the buffer
|
|
46 ;; quit
|
|
47 ;; 4. apply a window configuration
|
|
48 ;; if the buffer is displayed now, quit
|
|
49 ;; 5. call vm-display-buffer which will display the buffer.
|
|
50 ;;
|
|
51 ;; Undisplay is done this way:
|
|
52 ;; 1. if the buffer is not displayed, quit
|
|
53 ;; 2. if vm-undisplay-buffer-hook is non-nil
|
|
54 ;; run the hooks
|
|
55 ;; quit
|
|
56 ;; 3. apply a window configuration
|
|
57 ;; 4, if a window configuration was applied
|
|
58 ;; quit
|
|
59 ;; 5. call vm-undisplay-buffer which will make the buffer
|
|
60 ;; disappear from at least one window/frame.
|
|
61 ;;
|
|
62 ;; If display/undisplay is not requested, only window
|
|
63 ;; configuration is done, and only then if the value of
|
|
64 ;; this-command is found in the COMMANDS list.
|
|
65 (vm-save-buffer-excursion
|
98
|
66 (let* ((w (and buffer (vm-get-buffer-window buffer)))
|
|
67 (wf (and w (vm-window-frame w))))
|
0
|
68 (and buffer (set-buffer buffer))
|
98
|
69 (if (and w display (not do-not-raise))
|
|
70 (vm-raise-frame wf))
|
|
71 (if (and w display (not (eq (vm-selected-frame) wf)))
|
|
72 (vm-select-frame wf))
|
0
|
73 (cond ((and buffer display)
|
|
74 (if (and vm-display-buffer-hook
|
|
75 (null (vm-get-visible-buffer-window buffer)))
|
|
76 (progn (run-hooks 'vm-display-buffer-hook)
|
70
|
77 (switch-to-buffer buffer)
|
|
78 (vm-record-current-window-configuration nil))
|
0
|
79 (if (not (and (memq this-command commands)
|
|
80 (apply 'vm-set-window-configuration configs)
|
|
81 (vm-get-visible-buffer-window buffer)))
|
|
82 (vm-display-buffer buffer))))
|
|
83 ((and buffer (not display))
|
|
84 (if (and vm-undisplay-buffer-hook
|
|
85 (vm-get-visible-buffer-window buffer))
|
70
|
86 (progn (run-hooks 'vm-undisplay-buffer-hook)
|
|
87 (vm-record-current-window-configuration nil))
|
0
|
88 (if (not (and (memq this-command commands)
|
|
89 (apply 'vm-set-window-configuration configs)))
|
|
90 (vm-undisplay-buffer buffer))))
|
|
91 ((memq this-command commands)
|
|
92 (apply 'vm-set-window-configuration configs))))))
|
|
93
|
|
94 (defun vm-display-buffer (buffer)
|
|
95 (let ((pop-up-windows (eq vm-mutable-windows t))
|
70
|
96 (pop-up-frames vm-mutable-frames))
|
|
97 (vm-record-current-window-configuration nil)
|
0
|
98 (if (or pop-up-frames
|
|
99 (and (eq vm-mutable-windows t)
|
|
100 (symbolp
|
|
101 (vm-buffer-to-label
|
|
102 (window-buffer
|
|
103 (selected-window))))))
|
|
104 (select-window (display-buffer buffer))
|
|
105 (switch-to-buffer buffer))))
|
|
106
|
|
107 (defun vm-undisplay-buffer (buffer)
|
|
108 (vm-save-buffer-excursion
|
70
|
109 (vm-delete-windows-or-frames-on buffer)
|
|
110 (let ((w (vm-get-buffer-window buffer)))
|
|
111 (and w (set-window-buffer w (other-buffer))))))
|
0
|
112
|
|
113 (defun vm-load-window-configurations (file)
|
|
114 (save-excursion
|
|
115 (let ((work-buffer nil))
|
|
116 (unwind-protect
|
|
117 (progn
|
|
118 (set-buffer (setq work-buffer (get-buffer-create "*vm-wconfig*")))
|
|
119 (erase-buffer)
|
|
120 (setq vm-window-configurations
|
|
121 (condition-case ()
|
|
122 (progn
|
|
123 (insert-file-contents file)
|
|
124 (read (current-buffer)))
|
|
125 (error nil))))
|
|
126 (and work-buffer (kill-buffer work-buffer))))))
|
|
127
|
|
128 (defun vm-store-window-configurations (file)
|
|
129 (save-excursion
|
|
130 (let ((work-buffer nil))
|
|
131 (unwind-protect
|
|
132 (progn
|
|
133 (set-buffer (setq work-buffer (get-buffer-create "*vm-wconfig*")))
|
100
|
134 ;; for XEmacs/MULE
|
|
135 (and (fboundp 'set-file-coding-system)
|
|
136 (set-file-coding-system 'no-conversion))
|
0
|
137 (erase-buffer)
|
|
138 (print vm-window-configurations (current-buffer))
|
|
139 (write-region (point-min) (point-max) file nil 0))
|
|
140 (and work-buffer (kill-buffer work-buffer))))))
|
|
141
|
|
142 (defun vm-set-window-configuration (&rest tags)
|
|
143 (catch 'done
|
|
144 (if (not vm-mutable-windows)
|
|
145 (throw 'done nil))
|
|
146 (let ((nonexistent " *vm-nonexistent*")
|
|
147 (nonexistent-summary " *vm-nonexistent-summary*")
|
|
148 (selected-frame (vm-selected-frame))
|
|
149 summary message composition edit config)
|
|
150 (while (and tags (null config))
|
|
151 (setq config (assq (car tags) vm-window-configurations)
|
|
152 tags (cdr tags)))
|
|
153 (or config (setq config (assq 'default vm-window-configurations)))
|
|
154 (or config (throw 'done nil))
|
|
155 (setq config (vm-copy config))
|
|
156 (setq composition (vm-find-composition-buffer t))
|
|
157 (cond ((eq major-mode 'vm-summary-mode)
|
|
158 (if (or (null vm-mail-buffer) (null (buffer-name vm-mail-buffer)))
|
|
159 (throw 'done nil)
|
|
160 (setq summary (current-buffer))
|
|
161 (setq message vm-mail-buffer)))
|
|
162 ((eq major-mode 'vm-mode)
|
|
163 (setq message (current-buffer)))
|
98
|
164 ((eq major-mode 'vm-presentation-mode)
|
|
165 (setq message vm-mail-buffer))
|
0
|
166 ((eq major-mode 'vm-virtual-mode)
|
|
167 (setq message (current-buffer)))
|
|
168 ((eq major-mode 'mail-mode)
|
|
169 (if (or (null vm-mail-buffer) (null (buffer-name vm-mail-buffer)))
|
|
170 (throw 'done nil)
|
98
|
171 (setq message vm-mail-buffer
|
|
172 ;; assume that the proximity implies affinity
|
|
173 composition (current-buffer))))
|
0
|
174 ((eq vm-system-state 'editing)
|
|
175 (if (or (null vm-mail-buffer) (null (buffer-name vm-mail-buffer)))
|
|
176 (throw 'done nil)
|
|
177 (setq edit (current-buffer))
|
|
178 (setq message vm-mail-buffer)))
|
|
179 ;; not in a VM related buffer, bail...
|
|
180 (t (throw 'done nil)))
|
|
181 (set-buffer message)
|
98
|
182 (vm-check-for-killed-presentation)
|
|
183 (if vm-presentation-buffer
|
|
184 (setq message vm-presentation-buffer))
|
70
|
185 ;; if this configuration is already the current one, don't
|
|
186 ;; set it up again.
|
|
187 (if (or (and vm-mutable-frames (eq (car config) vm-window-configuration))
|
|
188 (and (not vm-mutable-frames)
|
|
189 (listp vm-window-configuration)
|
|
190 (eq (car config)
|
|
191 (cdr (assq selected-frame vm-window-configuration)))))
|
|
192 (throw 'done nil))
|
0
|
193 (vm-check-for-killed-summary)
|
|
194 (or summary (setq summary (or vm-summary-buffer nonexistent-summary)))
|
|
195 (or composition (setq composition nonexistent))
|
|
196 (or edit (setq edit nonexistent))
|
|
197 (tapestry-replace-tapestry-element (nth 1 config) 'buffer-name
|
|
198 (function
|
|
199 (lambda (x)
|
|
200 (if (symbolp x)
|
|
201 (symbol-value x)
|
|
202 x ))))
|
|
203 (set-tapestry (nth 1 config) 1)
|
|
204 (and (get-buffer nonexistent)
|
70
|
205 (vm-delete-windows-or-frames-on nonexistent))
|
0
|
206 (if (and (vm-get-buffer-window nonexistent-summary)
|
|
207 (not (vm-get-buffer-window message)))
|
|
208 ;; user asked for summary to be displayed but doesn't
|
|
209 ;; have one, nor is the folder buffer displayed. Help
|
|
210 ;; the user not to lose here.
|
|
211 (vm-replace-buffer-in-windows nonexistent-summary message)
|
|
212 (and (get-buffer nonexistent-summary)
|
70
|
213 (vm-delete-windows-or-frames-on nonexistent-summary)))
|
|
214 (vm-record-current-window-configuration config)
|
0
|
215 config )))
|
|
216
|
70
|
217 (defun vm-record-current-window-configuration (config)
|
|
218 ;; this function continues to be a no-op.
|
|
219 ;;
|
|
220 ;; the idea behind this function is that VM can remember what
|
|
221 ;; the current window configuration is and not rebuild the
|
|
222 ;; configuration for the next command if it matches what we
|
|
223 ;; have recorded.
|
|
224 ;;
|
|
225 ;; the problem with this idea is that the user can do things
|
|
226 ;; like C-x 0 and VM has no way of knowing. So VM thinks the
|
|
227 ;; right configuration is displayed when in fact it is not,
|
|
228 ;; which can cause incorrect displays.
|
|
229 '(let (cell)
|
|
230 (if (and (listp vm-window-configuration)
|
|
231 (setq cell (assq (vm-selected-frame) vm-window-configuration)))
|
|
232 (setcdr cell (car config))
|
|
233 (setq vm-window-configuration
|
|
234 (cons
|
|
235 (cons (vm-selected-frame) (car config))
|
|
236 vm-window-configuration)))))
|
|
237
|
0
|
238 (defun vm-save-window-configuration (tag)
|
|
239 "Name and save the current window configuration.
|
|
240 With this command you associate the current window setup with an
|
|
241 action. Each time you perform this action VM will duplicate this
|
|
242 window setup.
|
|
243
|
|
244 Nearly every VM command can have a window configuration
|
|
245 associated with it. VM also allows some category configurations,
|
|
246 `startup', `reading-message', `composing-message', `editing-message',
|
|
247 `marking-message' and `searching-message' for the commands that
|
|
248 do these things. There is also a `default' configuration that VM
|
|
249 will use if no other configuration is applicable. Command
|
|
250 specific configurations are searched for first, then the category
|
|
251 configurations and then the default configuration. The first
|
|
252 configuration found is the one that is applied.
|
|
253
|
|
254 The value of vm-mutable-windows must be non-nil for VM to use
|
70
|
255 window configurations.
|
|
256
|
|
257 If vm-mutable-frames is non-nil and Emacs is running under X
|
|
258 windows, then VM will use all existing frames. Otherwise VM will
|
|
259 restrict its changes to the frame in which it was started."
|
0
|
260 (interactive
|
|
261 (let ((last-command last-command)
|
|
262 (this-command this-command))
|
|
263 (if (null vm-window-configuration-file)
|
|
264 (error "Configurable windows not enabled. Set vm-window-configuration-file to enable."))
|
|
265 (list
|
|
266 (intern
|
|
267 (completing-read "Name this window configuration: "
|
|
268 vm-supported-window-configurations
|
|
269 'identity t)))))
|
|
270 (if (null vm-window-configuration-file)
|
|
271 (error "Configurable windows not enabled. Set vm-window-configuration-file to enable."))
|
|
272 (let (map p)
|
|
273 (setq map (tapestry (list (vm-selected-frame))))
|
|
274 ;; set frame map to nil since we don't use it. this prevents
|
|
275 ;; cursor objects and any other objects that have an
|
|
276 ;; "unreadable" read syntax appearing in the window
|
|
277 ;; configuration file by way of frame-parameters.
|
|
278 (setcar map nil)
|
|
279 (tapestry-replace-tapestry-element map 'buffer-name 'vm-buffer-to-label)
|
|
280 (tapestry-nullify-tapestry-elements map t nil t t t nil)
|
|
281 (setq p (assq tag vm-window-configurations))
|
|
282 (if p
|
|
283 (setcar (cdr p) map)
|
|
284 (setq vm-window-configurations
|
|
285 (cons (list tag map) vm-window-configurations)))
|
|
286 (vm-store-window-configurations vm-window-configuration-file)
|
|
287 (message "%s configuration recorded" tag)))
|
|
288
|
|
289 (defun vm-buffer-to-label (buf)
|
|
290 (save-excursion
|
|
291 (set-buffer buf)
|
|
292 (cond ((eq major-mode 'vm-summary-mode)
|
|
293 'summary)
|
|
294 ((eq major-mode 'mail-mode)
|
|
295 'composition)
|
|
296 ((eq major-mode 'vm-mode)
|
|
297 'message)
|
|
298 ((eq major-mode 'vm-virtual-mode)
|
|
299 'message)
|
|
300 ((eq vm-system-state 'editing)
|
|
301 'edit)
|
|
302 (t buf))))
|
|
303
|
|
304 (defun vm-delete-window-configuration (tag)
|
|
305 "Delete the configuration saved for a particular action.
|
|
306 This action will no longer have an associated window configuration.
|
|
307 The action will be read from the minibuffer."
|
|
308 (interactive
|
|
309 (let ((last-command last-command)
|
|
310 (this-command this-command))
|
|
311 (if (null vm-window-configuration-file)
|
|
312 (error "Configurable windows not enabled. Set vm-window-configuration-file to enable."))
|
|
313 (list
|
|
314 (intern
|
|
315 (completing-read "Delete window configuration: "
|
|
316 (mapcar (function
|
|
317 (lambda (x)
|
|
318 (list (symbol-name (car x)))))
|
|
319 vm-window-configurations)
|
|
320 'identity t)))))
|
|
321 (if (null vm-window-configuration-file)
|
|
322 (error "Configurable windows not enabled. Set vm-window-configuration-file to enable."))
|
|
323 (let (p)
|
|
324 (setq p (assq tag vm-window-configurations))
|
|
325 (if p
|
|
326 (if (eq p (car vm-window-configurations))
|
|
327 (setq vm-window-configurations (cdr vm-window-configurations))
|
|
328 (setq vm-window-configurations (delq p vm-window-configurations)))
|
|
329 (error "No window configuration set for %s" tag)))
|
|
330 (vm-store-window-configurations vm-window-configuration-file)
|
|
331 (message "%s configuration deleted" tag))
|
|
332
|
|
333 (defun vm-apply-window-configuration (tag)
|
|
334 "Change the current window configuration to be one
|
|
335 associated with a particular action. The action will be read
|
|
336 from the minibuffer."
|
|
337 (interactive
|
|
338 (let ((last-command last-command)
|
|
339 (this-command this-command))
|
|
340 (list
|
|
341 (intern
|
|
342 (completing-read "Apply window configuration: "
|
|
343 (mapcar (function
|
|
344 (lambda (x)
|
|
345 (list (symbol-name (car x)))))
|
|
346 vm-window-configurations)
|
|
347 'identity t)))))
|
|
348 (vm-set-window-configuration tag))
|
|
349
|
|
350 (defun vm-window-help ()
|
|
351 (interactive)
|
|
352 (message "WS = save configuration, WD = delete configuration, WW = apply configuration"))
|
|
353
|
|
354 (defun vm-iconify-frame ()
|
|
355 "Iconify the current frame.
|
|
356 Run the hooks in vm-iconify-frame-hook before doing so."
|
|
357 (interactive)
|
|
358 (vm-check-for-killed-summary)
|
|
359 (vm-select-folder-buffer)
|
|
360 (if (vm-multiple-frames-possible-p)
|
|
361 (progn
|
|
362 (run-hooks 'vm-iconify-frame-hook)
|
|
363 (vm-iconify-frame-xxx))))
|
|
364
|
|
365 (defun vm-window-loop (action obj-1 &optional obj-2)
|
|
366 (let ((delete-me nil)
|
|
367 (done nil)
|
70
|
368 (all-frames (if vm-mutable-frames t nil))
|
0
|
369 start w)
|
|
370 (setq start (next-window (selected-window) 'nomini all-frames)
|
|
371 w start)
|
|
372 (and obj-1 (setq obj-1 (get-buffer obj-1)))
|
|
373 (while (not done)
|
|
374 (if (and delete-me (not (eq delete-me (next-window delete-me 'nomini))))
|
|
375 (progn
|
|
376 (delete-window delete-me)
|
|
377 (if (eq delete-me start)
|
|
378 (setq start nil))
|
|
379 (setq delete-me nil)))
|
|
380 (cond ((and (eq action 'delete) (eq obj-1 (window-buffer w)))
|
|
381 ;; a deleted window has no next window, so we
|
|
382 ;; defer the deletion until after we've moved
|
|
383 ;; to the next window.
|
|
384 (setq delete-me w))
|
|
385 ((and (eq action 'replace) (eq obj-1 (window-buffer w)))
|
|
386 (set-window-buffer w obj-2)))
|
|
387 (setq done (eq start
|
|
388 (setq w
|
|
389 (condition-case nil
|
|
390 (next-window w 'nomini all-frames)
|
|
391 (wrong-number-of-arguments
|
|
392 (next-window w 'nomini))))))
|
|
393 (if (null start)
|
|
394 (setq start w)))
|
|
395 (if (and delete-me (not (eq delete-me (next-window delete-me 'nomini))))
|
|
396 (delete-window delete-me))))
|
|
397
|
|
398 (defun vm-frame-loop (action obj-1)
|
|
399 (if (fboundp 'vm-next-frame)
|
|
400 (let ((start (vm-next-frame (vm-selected-frame)))
|
|
401 (delete-me nil)
|
|
402 (done nil)
|
|
403 f)
|
|
404 (setq f start)
|
|
405 (and obj-1 (setq obj-1 (get-buffer obj-1)))
|
|
406 (while (not done)
|
|
407 (if delete-me
|
|
408 (progn
|
|
409 (condition-case nil
|
|
410 (progn
|
98
|
411 (if (vm-created-this-frame-p delete-me)
|
|
412 (vm-delete-frame delete-me))
|
0
|
413 (if (eq delete-me start)
|
|
414 (setq start nil)))
|
|
415 (error nil))
|
|
416 (setq delete-me nil)))
|
|
417 (cond ((and (eq action 'delete)
|
|
418 ;; one-window-p doesn't take a frame argument
|
|
419 (eq (next-window (vm-frame-selected-window f) 'nomini)
|
|
420 (previous-window (vm-frame-selected-window f)
|
|
421 'nomini))
|
|
422 ;; the next-window call is to avoid looking
|
|
423 ;; at the minibuffer window
|
|
424 (eq obj-1 (window-buffer
|
|
425 (next-window
|
|
426 (vm-frame-selected-window f)
|
|
427 'nomini))))
|
|
428 ;; a deleted frame has no next frame, so we
|
|
429 ;; defer the deletion until after we've moved
|
|
430 ;; to the next frame.
|
|
431 (setq delete-me f))
|
|
432 ((eq action 'bury)
|
|
433 (bury-buffer obj-1)))
|
|
434 (setq done (eq start (setq f (vm-next-frame f))))
|
|
435 (if (null start)
|
|
436 (setq start f)))
|
|
437 (if delete-me
|
|
438 (progn
|
|
439 (vm-error-free-call 'vm-delete-frame delete-me)
|
|
440 (setq delete-me nil))))))
|
|
441
|
70
|
442 (defun vm-delete-windows-or-frames-on (buffer)
|
0
|
443 (and (eq vm-mutable-windows t) (vm-window-loop 'delete buffer))
|
|
444 (and vm-mutable-frames (vm-frame-loop 'delete buffer)))
|
|
445
|
|
446 (defun vm-replace-buffer-in-windows (old new)
|
|
447 (vm-window-loop 'replace old new))
|
|
448
|
|
449 (defun vm-bury-buffer (&optional buffer)
|
|
450 (or buffer (setq buffer (current-buffer)))
|
70
|
451 (if (vm-xemacs-p)
|
0
|
452 (if (vm-multiple-frames-possible-p)
|
|
453 (vm-frame-loop 'bury buffer)
|
|
454 (bury-buffer buffer))
|
|
455 (bury-buffer buffer)))
|
|
456
|
|
457 (defun vm-unbury-buffer (buffer)
|
|
458 (save-excursion
|
|
459 (save-window-excursion
|
|
460 (switch-to-buffer buffer))))
|
|
461
|
|
462 (defun vm-get-buffer-window (buffer)
|
|
463 (condition-case nil
|
|
464 (or (get-buffer-window buffer nil nil)
|
|
465 (and vm-search-other-frames
|
|
466 (get-buffer-window buffer t t)))
|
|
467 (wrong-number-of-arguments
|
|
468 (condition-case nil
|
|
469 (or (get-buffer-window buffer nil)
|
|
470 (and vm-search-other-frames
|
|
471 (get-buffer-window buffer t)))
|
|
472 (wrong-number-of-arguments
|
|
473 (get-buffer-window buffer))))))
|
|
474
|
|
475 (defun vm-get-visible-buffer-window (buffer)
|
|
476 (condition-case nil
|
|
477 (or (get-buffer-window buffer nil nil)
|
|
478 (and vm-search-other-frames
|
|
479 (get-buffer-window buffer t nil)))
|
|
480 (wrong-number-of-arguments
|
|
481 (condition-case nil
|
|
482 (or (get-buffer-window buffer nil)
|
|
483 (and vm-search-other-frames
|
|
484 (get-buffer-window buffer 'visible)))
|
|
485 (wrong-number-of-arguments
|
|
486 (get-buffer-window buffer))))))
|
|
487
|
|
488 (defun vm-set-hooks-for-frame-deletion ()
|
|
489 (make-local-variable 'vm-undisplay-buffer-hook)
|
|
490 (add-hook 'vm-undisplay-buffer-hook 'vm-delete-buffer-frame)
|
|
491 (add-hook 'kill-buffer-hook 'vm-delete-buffer-frame))
|
|
492
|
98
|
493 (defun vm-created-this-frame-p (&optional frame)
|
|
494 (memq (or frame (vm-selected-frame)) vm-frame-list))
|
|
495
|
0
|
496 (defun vm-delete-buffer-frame ()
|
98
|
497 ;; kludge. we only want to this to run on VM related buffers
|
|
498 ;; but this function is generally on a global hook. Check for
|
|
499 ;; vm-undisplay-buffer-hook set; this is a good sign that this
|
|
500 ;; is a VM buffer.
|
|
501 (if vm-undisplay-buffer-hook
|
|
502 (save-excursion
|
|
503 ;; run once only per buffer.
|
|
504 (remove-hook 'vm-undisplay-buffer-hook 'vm-delete-buffer-frame)
|
|
505 (let* ((w (vm-get-visible-buffer-window (current-buffer)))
|
|
506 (b (current-buffer))
|
|
507 (wf (and w (vm-window-frame w))))
|
|
508 (and w (eq (vm-selected-frame) wf) (vm-created-this-frame-p wf)
|
|
509 (vm-error-free-call 'vm-delete-frame wf))
|
|
510 (and w (let ((vm-mutable-frames t))
|
|
511 (vm-delete-windows-or-frames-on b)))))))
|
|
512
|
|
513 (defun vm-register-frame (frame)
|
|
514 (setq vm-frame-list (cons frame vm-frame-list)))
|
0
|
515
|
|
516 (defun vm-goto-new-frame (&rest types)
|
|
517 (let ((params nil))
|
|
518 (while (and types (null params))
|
|
519 (setq params (car (cdr (assq (car types) vm-frame-parameter-alist)))
|
|
520 types (cdr types)))
|
|
521 ;; these functions might be defined in an Emacs that isn't
|
|
522 ;; running under a window system, but VM always checks for
|
|
523 ;; multi-frame support before calling this function.
|
|
524 (cond ((fboundp 'make-frame)
|
|
525 (select-frame (make-frame params)))
|
|
526 ((fboundp 'make-screen)
|
|
527 (select-screen (make-screen params)))
|
|
528 ((fboundp 'new-screen)
|
|
529 (select-screen (new-screen params))))
|
98
|
530 (vm-register-frame (vm-selected-frame))
|
0
|
531 (and vm-warp-mouse-to-new-frame
|
|
532 (vm-warp-mouse-to-frame-maybe (vm-selected-frame)))))
|
|
533
|
98
|
534 (defun vm-goto-new-summary-frame-maybe ()
|
|
535 (if (and vm-frame-per-summary (vm-multiple-frames-possible-p))
|
|
536 (let ((w (vm-get-buffer-window vm-summary-buffer)))
|
|
537 (if (null w)
|
|
538 (progn
|
|
539 (vm-goto-new-frame 'summary)
|
|
540 (vm-set-hooks-for-frame-deletion))
|
|
541 (save-excursion
|
|
542 (select-window w)
|
|
543 (and vm-warp-mouse-to-new-frame
|
|
544 (vm-warp-mouse-to-frame-maybe (vm-window-frame w))))))))
|
|
545
|
|
546 (defun vm-goto-new-folder-frame-maybe (&rest types)
|
|
547 (if (and vm-frame-per-folder (vm-multiple-frames-possible-p))
|
|
548 (let ((w (or (vm-get-buffer-window (current-buffer))
|
|
549 ;; summary == folder for the purpose
|
|
550 ;; of frame reuse.
|
|
551 (and vm-summary-buffer
|
|
552 (vm-get-buffer-window vm-summary-buffer))
|
|
553 ;; presentation == folder for the purpose
|
|
554 ;; of frame reuse.
|
|
555 (and vm-presentation-buffer
|
|
556 (vm-get-buffer-window vm-presentation-buffer)))))
|
|
557 (if (null w)
|
|
558 (progn
|
|
559 (apply 'vm-goto-new-frame types)
|
|
560 (vm-set-hooks-for-frame-deletion))
|
|
561 (save-excursion
|
|
562 (select-window w)
|
|
563 (and vm-warp-mouse-to-new-frame
|
|
564 (vm-warp-mouse-to-frame-maybe (vm-window-frame w))))))))
|
|
565
|
0
|
566 (defun vm-warp-mouse-to-frame-maybe (&optional frame)
|
|
567 (or frame (setq frame (vm-selected-frame)))
|
70
|
568 (if (vm-mouse-support-possible-p)
|
0
|
569 (cond ((vm-mouse-xemacs-mouse-p)
|
|
570 (cond ((fboundp 'mouse-position);; XEmacs 19.12
|
|
571 (let ((mp (mouse-position)))
|
|
572 (if (and (car mp)
|
|
573 (eq (window-frame (car mp)) (selected-frame)))
|
|
574 nil
|
|
575 (set-mouse-position (frame-highest-window frame)
|
|
576 (/ (frame-width frame) 2)
|
|
577 (/ (frame-height frame) 2)))))
|
|
578 (t ;; XEmacs 19.11
|
|
579 ;; use (apply 'screen-...) instead of
|
|
580 ;; (screen-...) to avoid stimulating a
|
|
581 ;; byte-compiler bug in Emacs 19.29 that
|
|
582 ;; happens when it encounters 'obsolete'
|
|
583 ;; functions. puke, puke, puke.
|
|
584 (let ((mp (read-mouse-position frame)))
|
|
585 (if (and (>= (car mp) 0)
|
|
586 (<= (car mp) (apply 'screen-width frame))
|
|
587 (>= (cdr mp) 0)
|
|
588 (<= (cdr mp) (apply 'screen-height frame)))
|
|
589 nil
|
|
590 (set-mouse-position frame
|
|
591 (/ (apply 'screen-width frame) 2)
|
|
592 (/ (apply 'screen-height frame) 2)))))))
|
|
593 ((vm-fsfemacs-19-p)
|
|
594 (let ((mp (mouse-position)))
|
|
595 (if (and (eq (car mp) frame)
|
|
596 ;; nil coordinates mean that the mouse
|
|
597 ;; pointer isn't really within the frame
|
|
598 (car (cdr mp)))
|
|
599 nil
|
|
600 (set-mouse-position frame
|
|
601 (/ (frame-width frame) 2)
|
|
602 (/ (frame-height frame) 2))
|
|
603 ;; doc for set-mouse-position says to do this
|
|
604 (unfocus-frame)))))))
|
|
605
|
|
606 (fset 'vm-selected-frame
|
|
607 (symbol-function
|
|
608 (cond ((fboundp 'selected-frame) 'selected-frame)
|
|
609 ((fboundp 'selected-screen) 'selected-screen)
|
|
610 (t 'ignore))))
|
|
611
|
|
612 (fset 'vm-delete-frame
|
|
613 (symbol-function
|
|
614 (cond ((fboundp 'delete-frame) 'delete-frame)
|
|
615 ((fboundp 'delete-screen) 'delete-screen)
|
|
616 (t 'ignore))))
|
|
617
|
|
618 ;; xxx because vm-iconify-frame is a command
|
|
619 (defun vm-iconify-frame-xxx (&optional frame)
|
|
620 (cond ((fboundp 'iconify-frame)
|
|
621 (iconify-frame frame))
|
|
622 ((fboundp 'iconify-screen)
|
|
623 (iconify-screen (or frame (selected-screen))))))
|
|
624
|
|
625 (fset 'vm-raise-frame
|
|
626 (symbol-function
|
|
627 (cond ((fboundp 'raise-frame) 'raise-frame)
|
|
628 ((fboundp 'raise-screen) 'raise-screen)
|
|
629 (t 'ignore))))
|
|
630
|
|
631 (fset 'vm-frame-visible-p
|
|
632 (symbol-function
|
|
633 (cond ((fboundp 'frame-visible-p) 'frame-visible-p)
|
|
634 ((fboundp 'screen-visible-p) 'screen-visible-p)
|
|
635 (t 'ignore))))
|
|
636
|
98
|
637 (if (fboundp 'frame-iconified-p)
|
|
638 (fset 'vm-frame-iconified-p 'frame-iconified-p)
|
|
639 (defun vm-frame-iconified-p (&optional frame)
|
|
640 (eq (vm-frame-visible-p frame) 'icon)))
|
|
641
|
|
642 ;; frame-totally-visible-p is broken under XEmacs 19.14 and is
|
|
643 ;; absent under Emacs 19.34. So vm-frame-per-summary won't work
|
|
644 ;; quite right under these Emacs versions. XEmacs 19.15 should
|
|
645 ;; have a working version of this function.
|
|
646 (if (and (fboundp 'frame-totally-visible-p)
|
|
647 (vm-xemacs-p)
|
|
648 (or (>= emacs-major-version 20)
|
|
649 (>= emacs-minor-version 15)))
|
|
650 (fset 'vm-frame-totally-visible-p 'frame-totally-visible-p)
|
|
651 (fset 'vm-frame-totally-visible-p 'vm-frame-visible-p))
|
|
652
|
0
|
653 (fset 'vm-window-frame
|
|
654 (symbol-function
|
|
655 (cond ((fboundp 'window-frame) 'window-frame)
|
|
656 ((fboundp 'window-screen) 'window-screen)
|
|
657 (t 'ignore))))
|
|
658
|
|
659 (cond ((fboundp 'next-frame)
|
|
660 (fset 'vm-next-frame (symbol-function 'next-frame))
|
|
661 (fset 'vm-select-frame (symbol-function 'select-frame))
|
|
662 (fset 'vm-frame-selected-window
|
|
663 (symbol-function 'frame-selected-window)))
|
|
664 ((fboundp 'next-screen)
|
|
665 (fset 'vm-next-frame (symbol-function 'next-screen))
|
|
666 (fset 'vm-select-frame (symbol-function 'select-screen))
|
|
667 (fset 'vm-frame-selected-window
|
|
668 (if (fboundp 'epoch::selected-window)
|
|
669 (symbol-function 'epoch::selected-window)
|
|
670 (symbol-function 'screen-selected-window))))
|
|
671 (t
|
|
672 ;; it is useful for this to be a no-op, but don't bind the
|
|
673 ;; others.
|
|
674 (fset 'vm-select-frame 'ignore)))
|