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